04-04-2023 01:48 PM
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?
Solved! Go to Solution.
04-04-2023 02:14 PM - edited 04-04-2023 02:15 PM
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.
04-04-2023 05:35 PM - edited 04-04-2023 05:36 PM
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.
04-04-2023 07:17 PM
@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)
04-05-2023 03:59 AM
@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.
04-05-2023 06:12 AM
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. 
04-05-2023 06:46 AM - edited 04-05-2023 06:47 AM
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)]."
04-05-2023 07:05 AM
The cast needs an array of doubles.
04-05-2023 08:35 AM - edited 04-05-2023 08:36 AM
@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.
04-05-2023 09:46 AM
@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.