HEX/Decimal to date and time from modbus

本秂侑毒 提交于 2019-12-24 03:07:29

问题


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.

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"

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


回答1:


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))


来源:https://stackoverflow.com/questions/20018623/hex-decimal-to-date-and-time-from-modbus

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!