Programming a raspberry pi with codesys, using mostly ladder, basically I need to write all data that is currently in a couple arrays to a csv file at midnight, so i'd like to be able to use a dt value as a trigger. I can't figure out how to use that value in ladder, however. I can display the local time on visualizer, but if i wanted something like "if localTime=#value" then coil 'Write' turns on, where is the actual variable for system time?
问问题
1191 次
1 回答
0
据我所知,您需要使用功能块从本地系统读取时钟,例如GetDateAndTime
来自CAA DTUtil Extern Library。然后,您需要使用功能块(例如标准库RTC
中的功能块)使其保持最新状态
下面读取系统本地时间,然后用RTC
功能块对其进行更新。至少在 Windows 上工作,无法用 Raspberry 进行测试。请注意,如果本地时间因某种原因发生更改,则不会再次更新。因此,例如,您需要时不时地运行GetDateAndTime
呼叫。
首先,一个更新并提供本地时间的程序:
PROGRAM PRG_UpdateSystemTime
VAR_OUTPUT
SystemDateTime : DT;
END_VAR
VAR
ReadLocalTime : DTU.GetDateAndTime; //Reads local time from system
RtcBlock : RTC; //Real-time clock - updates the previously received local time
END_VAR
//NOTE: Output is UTC time
//The block that reads local time. NOTE: Error handling is missing
ReadLocalTime(xExecute:= TRUE);
//Running real-time clock
RtcBlock(
EN := ReadLocalTime.xDone AND NOT ReadLocalTime.xError,
PDT := ReadLocalTime.dtDateAndTime,
CDT => SystemDateTime
);
然后是梯子的一个例子。我认为有数百万种方法。请注意,“DoSomething”将在整个秒内为 TRUE,因此您可能应该使用上升沿检测。
于 2020-04-08T05:58:25.517 回答