Beckhoff TwinCAT Basic Tutorial TwinCAT-1 Getting and Setting System Time

 Use the function block NT_GetTime, fill in NETID with two single quotes to indicate the local machine, START is a trigger signal, and most function blocks require a rising edge to trigger execution. The final output type is left to the system to decide, and then these variables are uniformly placed in global variables (I personally think this is a good programming practice) for easy viewing.












The collected time is a relatively special type. We can right-click to view the contents of this structure, or after running it, we can see whether the data of each element in this variable corresponds to the native time after execution is complete











After understanding the read time, the write time is relatively simple. First, we need to get a variable of the same type as the read variable (note that the year, month, day, and so on in the struct are all WORD types, while the controls and interactive variables we place in the HMI are all INT types, so we need to do data conversion).











Finally, no matter which function block is completed, it will return to the 0 state and reset the function block, making it easier to execute when the button is clicked next time