十六进制/从Modbus到日期和时间的十进制 [英] HEX/Decimal to date and time from modbus

查看:148
本文介绍了十六进制/从Modbus到日期和时间的十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与通风系统建立了Modbus连接,当出现问题时会产生警报.我可以使用modbus接收有关警报的数据.该部分记录有ID,日期和时间的寄存器.所有tre接收包含2个字节的数据.ID 00:13(女巫转换为十进制错误代码19 =过滤器警报)

I have a modbus connection to a ventilation system where it generates alarmas when something is wrong. I can with modbus receive data about the alarm. That part is documentated with a register for ID, date and time. All tre receives contains 2 byte of data. ID 00:13 (witch is converted to decimal error code 19 = Filter alarm)

但是我无法弄清楚日期和时间的格式.但是我可以在通风系统上看到这些日期和时间被转换成什么格式.

But i cannot figure out what format the date and time are in. However i can at the ventilation system see what these dates and times are translated to at the display.

我收到的日期(以字节(十六进制)为单位)= 43:68(十进制为17256),即等于显示屏上显示"13-11-08"(2013年11月8日)和时间以字节(十六进制)为单位= 34:71(十进制13425)等于显示"06:35"

The date i received in bytes(hex) = 43:68 (17256 in decimal) and thats equals on the display with "13-11-08" (08-nov-2013) and the time in bytes(hex) = 34:71 (13425 in decimal) that equals on the display "06:35"

我试图与时代"1970和1980"进行比较,并试图与其他时间转换32位整数进行比较,依此类推.但我不知道翻译是什么.也许这里有人看到了类似的东西,并且可以说出这是什么编码.

I tried to compare with epoch "1970 and 1980" and tried comparing with other time translations 32bit integer and so on. But i cannot figure out what the translate is to. Maybe someone here have seen simular and can tell maybe what encoding this is.

最好的问候托马斯·尼森

Best Regards Thomas Nissen

推荐答案

感谢Nanomurf,我已修复它.我翻译",并提出了多数民众赞成在工作:)它给了我以下08-11-2013 06:35:24那就是我想要的.谢谢您的宝贵时间.

Thank you Nanomurf, i got it fixed. I "translated" and came up with this thats working :) It gives me the following 08-11-2013 06:35:24 and thats what i wanted. Thanks for your time.

    Dim strDate As String = "17256"
    Dim year As String = (strDate >> 9) + 1980
    Dim month As String = (strDate And &H1E0) >> 5
    Dim day As String = strDate And &H1F

    Dim strTime As String = "13425"
    Dim hour As String = strTime >> 11
    Dim minute As String = (strTime And &H7E0) >> 5
    Dim secund As String = (strTime And &H1F) * 2

    Dim AlarmDate As String = New DateTime(CInt(year), CInt(month), CInt(day), CInt(hour), CInt(minute), CInt(secund))

这篇关于十六进制/从Modbus到日期和时间的十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆