shh Posted November 8, 2017 Report Share Posted November 8, 2017 Hi, What is the best solution for converting two 16 bits registers from modbus device to floating point in UniStream? 2x16 bit registers = 32 int to float. (IEEE754 single pr). Is there any FB for this kind of conversion? The device information: Quote 0x12345678 , shall be written in two consecutive registers, where the first register is 3499. Therefor the value has to be transmitted in the following way: Reg 3499, high byte 0x34 Reg 3499, low byte 0x12 Reg 3500, high byte 0x78 Reg 3500, low byte 0x56 I don´t believe I have to do this manually with calculation according to standard IEEE 754. If anybody know any method, it will be appreciated. 1 Quote Link to comment Share on other sites More sharing options...
Saragani Posted November 9, 2017 Report Share Posted November 9, 2017 You can copy the 2 16 bits registers (assuming it is an array of 2 Int16) to a Buffer using "Tag to Buffer". (or use 2 Tag to Buffer" elements, but with an offset of 2 on the second copy). Then use a "Buffer to Tag", and copy 4 bytes from offset 0 from the buffer into a Real number. Depending on how the value is sent, you might need to swap bytes on the buffer before copying it to Real. 1 Quote Link to comment Share on other sites More sharing options...
shh Posted November 14, 2017 Author Report Share Posted November 14, 2017 Thanks Saragani, It works perfectly. Quote Link to comment Share on other sites More sharing options...
Rafael Zapata Posted September 8, 2019 Report Share Posted September 8, 2019 Some body have a code example to see of this? Quote Link to comment Share on other sites More sharing options...
MVP 2022 Joe Tauser Posted September 9, 2019 MVP 2022 Report Share Posted September 9, 2019 Did you look at this post? Joe T. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.