# LabVIEW

cancel
Showing results for
Search instead for
Did you mean:

Solved!
Go to solution

## read multiple holding registers and convert to 32 bir float

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.

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

Message 1 of 12
(948 Views)

## Re: read multiple holding registers and convert to 32 bir float

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.

Message 2 of 12
(939 Views)

## Re: read multiple holding registers and convert to 32 bir float

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.

----------------------------------------------------------------------------------------------------------------
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.
-----------------------------------------------------------------------------------------------------------------
Message 3 of 12
(900 Views)

## Re: read multiple holding registers and convert to 32 bir float

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

Message 4 of 12
(887 Views)

## Re: read multiple holding registers and convert to 32 bir float

@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.
-----------------------------------------------------------------------------------------------------------------
Message 5 of 12
(858 Views)

## Re: read multiple holding registers and convert to 32 bir float

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.

----------------------------------------------------------------------------------------------------------------
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.
-----------------------------------------------------------------------------------------------------------------
Message 6 of 12
(850 Views)

## Re: read multiple holding registers and convert to 32 bir float

Thank you for the response

Yes, the blue array is 16 bit

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

"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)]."

Message 7 of 12
(843 Views)

## Re: read multiple holding registers and convert to 32 bir float

The cast needs an array of doubles.

Message 8 of 12
(836 Views)

## Re: read multiple holding registers and convert to 32 bir float

@oyfug wrote:

Thank you for the response

Yes, the blue array is 16 bit

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

"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.
-----------------------------------------------------------------------------------------------------------------
Message 9 of 12
(828 Views)
Solution
Accepted by topic author oyfug

## Re: read multiple holding registers and convert to 32 bir float

@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.

Message 10 of 12
(821 Views)