LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus Driver Data to Swapped Float Conversion

Solved!
Go to solution

Hello All,

 

I am trying to read some data over Modbus TCP using the LabVIEW Modbus Driver.

The out of the Modbus holding register read which gives out U16 array needs to be converted to floating point.

 

I have been using a typecast to SGL array to do this but the values I am getting are not correct. I think that I need to use a swapped floating point instead. Is there a way to do this?

 

I tried the swap word block but it didn't seem to help. I'm using LabVIEW 2021.

 

0 Kudos
Message 1 of 4
(262 Views)
Solution
Accepted by topic author Silverfang-

Hi Silverfang,

 


@Silverfang- wrote:

I have been using a typecast to SGL array to do this but the values I am getting are not correct. I think that I need to use a swapped floating point instead. Is there a way to do this?

 

I tried the swap word block but it didn't seem to help. I'm using LabVIEW 2021.


You forgot to attach your VI and example data…

 

Giving a generic answer: create an U32 from two U16 words using JoinNumbers (using the right word order), then you typecast to SGL!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(255 Views)

Hello GerdW,

 

Thank you for the solution. This worked. Only issue is that my INT16 is an array so I had to extract my individual array elements and join them and then convert to float to test this.

 

Possible to apply a similar solution to a whole array or do I have to do this for every 2 elements individually?

 

0 Kudos
Message 3 of 4
(227 Views)

Hi Silverfang,

 


@Silverfang- wrote:

Possible to apply a similar solution to a whole array or do I have to do this for every 2 elements individually?


Decimate the U16 array into two arrays, then apply JoinNumbers & TypeCast (to array of SGL)…

 

Or: SplitNumbers the U16 array into two U8 arrays, interleave those into one U8 array, convert into string, UnflattenFromString into array of SGL…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 4
(193 Views)