08-21-2018 03:52 AM
Hello,
Is it possible to convert a 1D array of unsigned word 16 bit integer into a string? Any help would be much appreciated.
Solved! Go to Solution.
08-21-2018 04:02 AM
08-21-2018 04:18 AM - edited 08-21-2018 04:20 AM
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.
08-21-2018 04:32 AM - edited 08-21-2018 04:32 AM
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?
08-21-2018 04:38 AM
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.
08-21-2018 04:38 AM
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.
08-21-2018 04:44 AM
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.
08-21-2018 04:50 AM
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?
08-21-2018 04:55 AM
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.
08-21-2018 05:05 AM
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.