如何使用系统时间作为 codesys ladder 中的触发器?
How do I use system time as a trigger in codesys ladder?
用 codesys 编程 raspberry pi,主要使用梯形图,基本上我需要在午夜将几个数组中的所有数据写入 csv 文件,所以我希望能够使用一个 dt 值作为触发器。但是,我不知道如何在阶梯中使用该值。我可以在可视化工具上显示本地时间,但是如果我想要类似 "if localTime=#value" 的东西,那么线圈 'Write' 会打开,系统时间的实际变量在哪里?
据我所知,您需要使用功能块从本地系统读取时钟,例如 GetDateAndTime
来自 CAA DTUtil Extern Library. Then you need to keep it up-to-date by using a function block, for example RTC
from Standard libary
下面读取系统本地时间,然后用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,因此您可能应该使用上升沿检测。
用 codesys 编程 raspberry pi,主要使用梯形图,基本上我需要在午夜将几个数组中的所有数据写入 csv 文件,所以我希望能够使用一个 dt 值作为触发器。但是,我不知道如何在阶梯中使用该值。我可以在可视化工具上显示本地时间,但是如果我想要类似 "if localTime=#value" 的东西,那么线圈 'Write' 会打开,系统时间的实际变量在哪里?
据我所知,您需要使用功能块从本地系统读取时钟,例如 GetDateAndTime
来自 CAA DTUtil Extern Library. Then you need to keep it up-to-date by using a function block, for example RTC
from Standard libary
下面读取系统本地时间,然后用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,因此您可能应该使用上升沿检测。