LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read multiple holding registers and convert to 32 bir float

Solved!
Go to solution

Hi

 

I want to read multiple holding registers and convert the registers to 32 bit float.

I have managed to do it, but I think there must be a more efficient way to do it.

Skjermbilde1.PNG

 

 

Can i read register 0-10 and then split them to convert the registers?

0 Kudos
Message 1 of 12
(1,711 Views)

You can probably read the entire blue array (start=0, size=12) at once and typecast it into an array of SGL.

Then you could use index array to get the elements if you really need them as scalars.

 

Sorry, can't open your VI (only 2020 here). It is impossible to tell from the picture, but I assume the blue array is 16bit.

0 Kudos
Message 2 of 12
(1,702 Views)

Hello Oyfug,

 

I have used this in one of my old program, you can remove the reverse 1D array function if that is not relevant to you.

Best option is reading all the registers at once and then start formatting.

 

U16toFloat.png

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 3 of 12
(1,663 Views)

@PalanivelThiruvenkadam wrote:

I have used this in one of my old program, you can remove the reverse 1D array function if that is not relevant to you.

Best option is reading all the registers at once and then start formatting.


That is casting, not formatting and can be done in one step by casting to a SGL array. No need for loops and all that other stuff.

A division by two is just a left shift. Ne need to go orange and back.

 

(If there is a byte order change involved, that can also be handled easier)

0 Kudos
Message 4 of 12
(1,650 Views)

@altenbach wrote:

@PalanivelThiruvenkadam wrote:

I have used this in one of my old program, you can remove the reverse 1D array function if that is not relevant to you.

Best option is reading all the registers at once and then start formatting.


That is casting, not formatting and can be done in one step by casting to a SGL array. No need for loops and all that other stuff.

A division by two is just a left shift. Ne need to go orange and back.

 

(If there is a byte order change involved, that can also be handled easier)


Thanks for the your inputs, I need to convert every two array elements with byte order change thats the reason i have used typecast in a loop to handle two at a time.

 

I will give a try as you suggested in my next activities if any, Thanks again for your suggestion.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 5 of 12
(1,621 Views)


That is casting, not formatting and can be done in one step by casting to a SGL array. No need for loops and all that other stuff.

A division by two is just a left shift. Ne need to go orange and back.

 

(If there is a byte order change involved, that can also be handled easier)


I have modified and checked for typecast of SGL it takes 2 bytes by default and i checked it works fine.

 

How to handle if there is a byte order change involved?

 

This was one of my old projects where it required byte order change but now i don't have values to Validate.TypcastRegisterValues.png

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 6 of 12
(1,613 Views)

Thank you for the response

Yes, the blue array is 16 bit

 

I changed the VI, however the wires will not connect.

Skjermbilde1.PNG

"These cannot be wired together because their data types (numeric, string, array, cluster, etc.) do not match. Show the Context Help window to see what data type is required.
The type of the source is single [32-bit real (~6 digit precision)].
The type of the sink is 1D array of
single [32-bit real (~6 digit precision)]."

 

0 Kudos
Message 7 of 12
(1,606 Views)

The cast needs an array of doubles.

0 Kudos
Message 8 of 12
(1,599 Views)

@oyfug wrote:

Thank you for the response

Yes, the blue array is 16 bit

 

I changed the VI, however the wires will not connect.

Skjermbilde1.PNG

"These cannot be wired together because their data types (numeric, string, array, cluster, etc.) do not match. Show the Context Help window to see what data type is required.
The type of the source is single [32-bit real (~6 digit precision)].
The type of the sink is 1D array of
single [32-bit real (~6 digit precision)]."



Right Click change source also to Array you will get the output as expected.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 9 of 12
(1,591 Views)
Solution
Accepted by topic author oyfug

@MaSta wrote:

The cast needs an array of doubles.


NO! An array of SGLs.. I would just right-click the scalar SGL constant wired to the type input and change to array.

 

altenbach_0-1680705962762.png

 

 

Message 10 of 12
(1,584 Views)