LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ASCII to HEX

I use VISA to read data from serial port,then display them in the chart.
The data I sent are HEX string like"00 01 02 03 04 05",but the data I received are like"..................... !"#$%&'()*+,-./".
So all their value displayed in the chart are 0,but the value what I want are"0 1 0 3 4 5".
A solution is use the "String To Byte Array",But another question is how to combine two serial string into a new value?
 
Thank you!
 
0 Kudos
Message 1 of 14
(4,492 Views)


@feidaodeng wrote:
I use VISA to read data from serial port,then display them in the chart.
The data I sent are HEX string like"00 01 02 03 04 05",but the data I received are like"..................... !"#$%&'()*+,-./".

The thing to remember is that the only difference between an output of
         2E20 2122 2324 2526 2728 292A 2B2C 2D2E 2F
and
         . !"#$%&'()*+,-./
(which by the way are equal) is the display format selected in the indicator.

So all their value displayed in the chart are 0,but the value what I want are"0 1 0 3 4 5".
A solution is use the "String To Byte Array",But another question is how to combine two serial string into a new value?

Unless I misunderstand what you mean, the same way you would any two strings - a string concatenator...
 
Thank you!
 




Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 14
(4,488 Views)

Can you attach a simplified example containing the strings you get and the outputs you want?

You cannot wire a string to a chart so it is not clear what you do to get the "0". String to byte array is a very special case if you know your desired final datatype is U8. In a more general case, you would typecast or unflatten to the desired datatype.


@feidaodeng wrote:
A solution is use the "String To Byte Array",But another question is how to combine two serial string into a new value?

It is not fully clear what you mean, but do you possibly want to extract a multibyte datatype (e.g. 2 bytes for I16) from the string? In this case, the first part of my answer will give you the solution. 🙂

Message 3 of 14
(4,484 Views)
Thanks for your reply.
 
I know what your mean"the only difference is the display format",but I couldn't display it in the chart with format HEX .
 
And what I want is  combine two serial string into a new value, it not means combine two inputs into one output,it means that there is only one serial input.For example: the input is "01 02 03 04..."(1,2,3,4...) and the output I want is "0102 0304..."(18,52...).
0 Kudos
Message 4 of 14
(4,472 Views)
Hi fei,

you want to combine 2 U8 values into a new U16 or U8? Your example is not clear as "0102" is not equal to 18 (it's 258!)

To combine two U8 to one U16 you may use 'join numbers' (data manipulation palette) or 'typecast'. You can also use math: U16=256*MSB+LSB.

To combine two U8 into one U8 you should use math: U8=16*MSB+LSB. Then you have to make sure your single U8 values are no greater than 15 (0x0f)!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 14
(4,467 Views)

Reply to altenbach:

Thanks for your reply.

The date read from serial port is format string,so used the "Hexadecimal String To Number " then wired it to a chart ,the value displayed in the chart is "0".

 

0 Kudos
Message 6 of 14
(4,465 Views)
Thank you for correcting my wrong.
 
What puzzle me the most is how to display the U16 in a chart.
0 Kudos
Message 7 of 14
(4,458 Views)
Hi fei,

'What puzzle me the most is how to display the U16 in a chart.'
Normally you just wire the U16 to the chart...

Can you attach your vi (or a stripped down version) to show the problem?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 14
(4,456 Views)
Attachment is my program,but LV edition is Chinese,so I am not sure if you can open it.
 
0 Kudos
Message 9 of 14
(4,448 Views)
I can open your code. I see that you are sending commands to a serial device of some sort and receiving a response back from it. My sense is that the problem lies in interpreting this response. Typically serial devices return data in ASCII form. For example, the number 1.234 would be returned as the character string "1.234". However some devices will also send the data in 'binary' form in which 4 or 8 consecutive bytes need to be taken together as representing an IEEE-standard floating-point value. In the case above, 1.234 would become four bytes with the hex values: 3F 9D F3 B6.

What is the format of the data that the device is returning? What exactly is for the instrument that you are talking to, and do you have a manual for it?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 10 of 14
(4,441 Views)