LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion from 1D array of unsigned 16 Bit Integer to String

Solved!
Go to solution

Hello,

 

Is it possible to convert a 1D array of unsigned word 16 bit integer into a string? Any help would be much appreciated.

 

 

0 Kudos
Message 1 of 10
(4,890 Views)

Hi Franz,

 

check.png

Yes: typecast!

 

(When you need a specific kind of conversion you need to explain that with more details!)

Best regards,
GerdW


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

Thank you for your response! I attempted this but the string results in presumably flattened data. I posted my code below in hopes that it might give some context.

0 Kudos
Message 3 of 10
(4,878 Views)

Hi Franz,

 

but the string results in presumably flattened data.

Not just "presumably"…

 

I posted my code below in hopes that it might give some context.

Well, no: You still don't say which kind of string you expect as result!

What is your expected result?

(When working with Modbus data I usually want to get numeric values and not strings…)

 

Have you tried any of those conversion functions in the string functions -> "number/string conversion" palette?

Best regards,
GerdW


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

I have looked through them and I would prefer a fractional string. I just want the same numbers that are in the 16 bit integer indicators to be in a string indicator. I need it to be in string form for another application unfortunately. Thank you in advance.

0 Kudos
Message 5 of 10
(4,864 Views)

If you need to format array values to a readable text, the quickest way is to use the Array to Spreadsheet String vi. Or other formatting vi's with or without a loop.

Otherwise, please describe what do you need to achieve.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 10
(4,863 Views)

I have posted my code above (modbust test) and so I basically just need to convert the unsigned word 16 bit integer values (like the ones in the indicators) into a similar string indicator in fractional format. As of now Im getting flattened data with the code I have.

0 Kudos
Message 7 of 10
(4,859 Views)

Hi Franz,

 

I basically just need to convert the unsigned word 16 bit integer values … into a similar string indicator in fractional format.

It doesn't make sense to display an U16 value as a fractional number - unless you apply some scaling factors!

 

What about reading the manual of your Modbus device? Do you need to apply scaling on the values read by those Modbus requests?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 10
(4,853 Views)
Solution
Accepted by topic author Franz357

I don't have the Modbus library installed, so I can only make a guess. You are reading a couple of registers to get a floating point SGL value (a float, in C terminology); otherwise why would you need to show fractional values?

So you need to convert the U16 array to a SGL. You may try with a simple cast, but you may need to rearrange the byte order before.

Then, you can format the floating point value as you prefer.

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 9 of 10
(4,852 Views)

I more or less did this, I need it in string format because I am sending it to a database system and it only accepts certain formats. I realize it was a slightly strange request. Thank you very much for taking time to help me, I appreciate it.

0 Kudos
Message 10 of 10
(4,848 Views)