当前位置:网站首页>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.从新下载运行即可得到本地时间
源码下载
边栏推荐
- MySql索引
- What is the KDM of digital movies?
- JVM (4): active and passive use of classes, internal structure of runtime data area, JVM thread description, PC register
- golang泛型:generics
- PHP话费充值通道网站完整运营源码/全解密无授权/对接免签约支付接口
- [server data recovery] data recovery case of RAID5 crash of buddy storage
- 智慧工地怎样做到数字化转型?
- Overview of guanghetong industrial 5g module product line
- ACTS:如何让缺陷无处藏身?
- 传说使用Shader的ID来设置Shader属性能提高效率:)
猜你喜欢

芯源cw32f030c8t6用keil5编译时出现的问题

特征工程 特征降维

It's 2022. When will the "module freedom" be realized?

七个好用的装饰器

Unity music playback Manager

Guanghetong 5g module shines brightly and has won the "2021 science and technology award of China Electronics Society"

JVM(6):Slot变量槽、操作数栈、代码追踪、栈顶缓存技术

Product milestones in May 2022

无刷电机调试经验与可靠性设计

Guanghetong LTE CAT6 module fm101-cg, which supports CBRS band, took the lead in obtaining FCC certification
随机推荐
[CF571E] Geometric Progressions——数论、质因数分解
FreeRTOS startup - based on stm32
Feature selection algorithm based on bare bones particleswarm optimization
谷歌的代码覆盖率最佳实践
Unity 编辑器扩展 保存位置
MySQL锁总结
Esp32 gattc configuration UUID
Overview of guanghetong industrial 5g module product line
Cloud broadcast alert, guanghetong helps intelligent camera to build a "river protection" drowning prevention system
ACTS:高效的测试设计(并赠送一个优秀的测试设计工具)
Do you know the difference between mallbook ledger and bank ledger?
JVM(3):类加载器分类、双亲委派机制
ACTS:如何让缺陷无处藏身?
Unity advanced backpack system
Sql优化
Unity 在不平坦的地形上创建河流
梅州植物组培实验室建设资料整理
Unity 传送机制的实现
Unity item model rotating display
MySQL stored procedure