当前位置:网站首页>codesys 获取系统时间
codesys 获取系统时间
2022-06-11 04:30:00 【qq_25126053】
codesys 获取系统时间
- 添加获取时间库 添加库输入caa dtutil搜索库,选中双击添加

2.定义功能块,读取时间
PROGRAM PLC_PRG
VAR
//定义读取当前时间功能块
ReadCurrentTime:dtu.GetDateAndTime;
//系统当前时间,注意此时的时间为世界时间并非本地时间
dtTime:DT;
//更新时间变化
RTC_BLOCK:RTC;
dtTime2:DT;
END_VAR
ReadCurrentTime(
xExecute:= TRUE,
xDone=> ,
xBusy=> ,
xError=> ,
eError=> ,
dtDateAndTime=>dtTime ,
ePeriode=> );
RTC_BLOCK(EN:= ReadCurrentTime.xDone, PDT:= dtTime, Q=> , CDT=> dtTime2);
3.运行 Codesys SoftMotion Win 下载运行,效果如下:
4.注意此时读到的时间为世界时间需要转换为北京时间
PROGRAM PLC_PRG
VAR
//定义读取当前时间功能块
ReadCurrentTime:dtu.GetDateAndTime;
//系统当前时间,注意此时的时间为世界时间并非本地时间
dtTime:DT;
//更新时间变化
RTC_BLOCK:RTC;
dtTime2:DT;
//时间总秒数
w_TotalSeconds :LINT;
//本地时间总秒数
l_TotalSeconds:LINT;
sysCurrentTime:DT;
END_VAR
ReadCurrentTime(
xExecute:= TRUE,
xDone=> ,
xBusy=> ,
xError=> ,
eError=> ,
dtDateAndTime=>dtTime ,
ePeriode=> );
RTC_BLOCK(EN:= ReadCurrentTime.xDone, PDT:= dtTime, Q=> , CDT=> dtTime2);
//获取时间时间总秒数
w_TotalSeconds:=DT_TO_LINT(dtTime2);
//应为北京时间和世界时间相差8小时
l_TotalSeconds:=w_TotalSeconds + 8 * 60 * 60;
//转换成时间格式
sysCurrentTime:=LINT_TO_DT(l_TotalSeconds);5.从新下载运行即可得到本地时间
源码下载
边栏推荐
- From the first generation of sowing to the first generation of flowers, 5g commercial "gave birth to all things" for the third anniversary
- 记一次ES 事故
- Cloud broadcast alert, guanghetong helps intelligent camera to build a "river protection" drowning prevention system
- Project architecture evolution
- Unity map mapping
- 2021 5g aiot annual innovation achievements! release!
- 传说使用Shader的ID来设置Shader属性能提高效率:)
- 国际期货黄金手续费怎么算?
- Feature selection algorithm based on bare bones particleswarm optimization
- Golang generics: generics
猜你喜欢

Unity 可缩放地图的制作

Unity music playback Manager

meedu知识付费解决方案 v4.5.4源码

Safe and borderless, Guanghe tongdai 5g module +ai intelligent security solution shines at CPSE Expo

Production of unity scalable map

JVM(3):类加载器分类、双亲委派机制

Unity Editor Extension save location
![[customview] glide+bitmaptransformation picture upper and lower border wave processing (wavetransformation)](/img/20/6ded07851466d6ef5e5d5a296e3aed.png)
[customview] glide+bitmaptransformation picture upper and lower border wave processing (wavetransformation)

2021 5g aiot annual innovation achievements! release!

JVM (2): loading process of memory structure and classes
随机推荐
Ultra simple cameraX face recognition effect package
Guanghetong officially released the sc126 series of intelligent modules to promote more intelligent connection
It's 2022. When will the "module freedom" be realized?
七个好用的装饰器
2022年新高考1卷17题解析
Unity creates rivers on uneven terrain
Mathematical basis of information and communication -- the first experiment
Statistical knowledge required by data analysts
Unity 消息框架 NotificationCenter
Grandpa simayan told you what is called inside roll!
Safe and borderless, Guanghe tongdai 5g module +ai intelligent security solution shines at CPSE Expo
PCB地线设计_单点接地_底线加粗
[CF571E] Geometric Progressions——数论、质因数分解
Unity message framework notificationcenter
exness:流動性系列-訂單塊、不平衡(二)
Esp32 development -lvgl uses internal and external fonts
USB转232 转TTL概述
SQL optimization
FreeRTOS startup - based on stm32
JVM(5):虚拟机栈、栈异常、栈的存储结果和运行原理、栈内部结构、局部变量表