当前位置:网站首页>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.从新下载运行即可得到本地时间
源码下载
边栏推荐
- 正大国际:真正会在琪貨投资都都应该知道
- 超简单 CameraX 人脸识别效果封装
- JVM (3): classloader classification and parental delegation mechanism
- 如何快速寻找STM32系列单片机官方例程
- Overview of construction knowledge of Fuzhou mask clean workshop
- What is the KDM of digital movies?
- Mathematical basis of information and communication -- the first experiment
- How to check whether domain name resolution is effective?
- [CF571E] Geometric Progressions——数论、质因数分解
- exness:流動性系列-訂單塊、不平衡(二)
猜你喜欢

Given a project, how will you conduct performance testing?

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

Esp32 development -lvgl uses internal and external fonts

Mathematical basis of information and communication -- the first experiment

The third small class discussion on the fundamentals of information and communication

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

Emlog新版导航源码/带用户中心

Feature selection algorithm based on bare bones particleswarm optimization

JVM(2):内存结构、类的加载过程
![[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)
随机推荐
谷歌的代码覆盖率最佳实践
Seven easy-to-use decorators
特征工程 特征降维
正大国际 至秋天的第一个主帐户
国际期货黄金手续费怎么算?
Use tool classes to read Excel files according to certain rules
MySQL index
数据中台和数据仓库有什么异同?
项目架构演进
Introduction to the development and production functions of shop facade transfer and rental applet
Unity 高級背包系統
福州核酸检测实验室建设须知事项探讨
Esp32 gattc configuration UUID
Unity 地图映射
Unity Advanced Backpack System
Matter protocol
SQL optimization
给你一个项目,你将如何开展性能测试工作?
Overview of guanghetong industrial 5g module product line
Guanghetong 5g module fg650-cn and fm650-cn series are produced in full scale, accelerating the efficient implementation of 5g UWB applications