Rodney Posted September 15, 2017 Share Posted September 15, 2017 Hi I have read the post on BCD conversion and the formula to use sum((bcd & {0xf000,0xf00,0xf0,0xf}) / {4096,256,16,1} * {1000,100,10,1}) I'm not sure how to use it in conjunction with the Channel data returned The manual says for the piece of equipment I am using that the hour and day are BCD with the hour lower byte I am using I/O read holding U16 (3) which is returning 5409 for 15th day and 2100 hour - is this the correct I/O to use? (for Month and Year (9th mth 2017 year) using the same I/O on a different Channel I am returning 5897) I assume by substituting 5409 for bcd in the above formula I would get an integer and then by using floor and modulus functions I would get the correct values - I'm not... (I have used the floor and Modulus functions on other equipment / data conversions and have got it to work) Your help in the correct method to convert the BCD values most appreciated Regards Rodney Link to comment Share on other sites More sharing options...
AzeoTech Posted September 15, 2017 Share Posted September 15, 2017 Actually, its probably easier to split the word into the two bytes before you feed it into the BCD function. To get the low byte of a word, just do: value & 0xff To get the high byte when you know its a word (and not a long) do: value >> 8 Then feed the result into the bcd function in place of the "bcd" and you'll get what you want (I checked!) Link to comment Share on other sites More sharing options...
Rodney Posted September 16, 2017 Author Share Posted September 16, 2017 Thank you - I got it to work I was even able to do the reverse - update the channel with the BCD value after reading another one of your excellent posts on converting to BCD Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.