From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert byte to integer, have troube in type cluster

Hi,

 

I'm trying to translate the bytes string I got from VISA read to an integer. The string I read directly from the indicator is random unreadable characters. But from the python program I run successful, I know it should be like.

 

b'\r\x06\x00\x1c\' \x03\xff\x7f\xd0\x02\xce\x02\x00\x00\x00\x00\x85t \x00\x00\x00\xfa\x02A\xff\xff\x00\xff\xff\x00\x00 \x00\xffK\xff\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x1c\'!\x03\xd1\x02\xd1\x02\xcf\x02\x00\x00\x00\x00\x84t \x00\x00\x00\xfa\x02AL\xff\x00\xff\xff\x00\x00 \x00\x00K\xff\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x1c\'"\x03\xd0\x02\xd1\x02\xd0\x02\x00\x00\x00\x00\x82t!\x00\x00\x00\xfa\x02AL\xff\x00\xff\xff\x00\x00!\x00\x00K\xff\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x1c\'#\x03\xd1\x02\xd1\x02\xd1\x02\x00\x00\x00\x00\x83t!\x00\x00\x00\xfa\x02AK\xff\x00\xff\xff\x00\x00!\x00\x00K\xff\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x1c\'$\x03\xd2\x02\xd2\x02\xd1\x02\x00\x00\x00\x00\x86t!\x00\x00\x00\xfa\x02AL\xff\x00\xff\xff\x00\x00!\x00\x00K\xff\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x0b\x8e\n'

 

The data I need is at offset 12 and its size is 2. It can be decoded as decimal integer. I tried Typecasting and Unflatten From String from this topic.

https://forums.ni.com/t5/LabVIEW/Convert-3-Bytes-to-16-Bit-Decimal-Number/m-p/3666285#M1030530

My problem is I'm confused by the type cluster. There is no description of how I could define them. When I tried to put a constant into it, it automatically shows it is a long 32-bit integer. But on the topic, it is U8 and U16. And for me, I need U16. Besides, why they are all zero?

0 Kudos
Message 1 of 57
(3,274 Views)

Attach your actual VI where you attempted this.  Be sure your string is saved in their as default data.

0 Kudos
Message 2 of 57
(3,264 Views)

Hi feelsomoon,

 

cleaning up your string might help too:

check.png

(I guess those '\x' encode byte values in the string…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 57
(3,256 Views)

Hi GerdW,

 

Thanks so much for your reply! I met the timeout error when I'm using Serial read and write example VI as below. I can communicate with the sensor well in NI MAX so I'm guessing nothing wrong with the hardware. Do you know anything I could change?

 

Download All
0 Kudos
Message 4 of 57
(3,217 Views)

Sorry, I forgot to change the capture picture's names. I'm wondering if this is because I didn't set the termination characters.

Capture.PNGserial.PNGtimeout.PNG

0 Kudos
Message 5 of 57
(3,209 Views)

@feelsomoon wrote:

Hi GerdW,

 

Thanks so much for your reply! I met the timeout error when I'm using Serial read and write example VI as below. I can communicate with the sensor well in NI MAX so I'm guessing nothing wrong with the hardware. Do you know anything I could change?

 


No idea because you didn't attach your actual VI, just a couple of pictures of a test panel and a block diagram.  The block diagram one doesn't show us what  you have typed into that Command control.

 

Did your Command include the line feed termination character like your test panel shows?

0 Kudos
Message 6 of 57
(3,207 Views)

Yes, I did. I tired the original example and it worked. But the return data in the indicator is like. Can I add your code after the read Serial VI?

 

random.PNG

0 Kudos
Message 7 of 57
(3,199 Views)

Sorry to bother you again. Just to clarify, I'm confused is because the return data in the indicator is not like the data from NI test panel. I'm not sure if I could use match pattern like that.

0 Kudos
Message 8 of 57
(3,196 Views)

Right click on your Response string control and select "Hex Display". Then it will look almost like the display in the VISA Control panel. The difference will be that the VISA Control panel shows each 8 bit value as an independent 2 character hex value, while the LabVIEW string display will group 2 such 8-bit values into a 4 character hex value but that is just cosmetics.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 57
(3,193 Views)

Thank you rolfk! I never realized this is the display problem. May I ask another silly question? I'm wondering how the 8 bit data could represent 1 integer. Like I want the Outside Temperature with offset at 12, size of 2, corresponding to 3193. Should it be 31=49, 93=147, 3193=147+49=196? This seems wrong because the temperature is much higher than this.

 

Besides, when I code, should I split the raw data first them format them separately? I still don't know which VI I should use and how to set the type parameter of Type Cast and Unflatten From String.

 

Sorry if these problems are too basic, I'm really new with these. Thank you for your patience.

number.PNG

 

reference.PNG

0 Kudos
Message 10 of 57
(3,180 Views)