LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA write to serial device

I have an integer 32 value, for example 904 (0x388) that I need to write to a serial port with the actual byte value 0x0388. The VISA write expects a string, and when I convert the value using the vi 'number to hex string', the value written is not the same. Instead the asci value of 33 3838 is passed on.Is there a way to push the actual integer value 0x388 to the serial line so that device on the other end gets the true value?

0 Kudos
Message 1 of 5
(2,560 Views)

Hi bullet,

 

you should think about byte order...

check.png

Best regards,
GerdW


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

The Flatten to String is the guy you want so you can set the endianness.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 5
(2,552 Views)

I'm inferring from the question that you want to send exactly 2 bytes to the serial port, the byte with value 0x03, followed by the byte with value 0x88

 

If that is so, a type cast to string is suitable. This preserves the bit pattern of the input. Bear in mind that if you do the type cast on a U32/I32, the string (being the same bit representation as the 32 bit / 4 byte value) will have 4 characters/bytes in it, in your example 0x00, 0x00, 0x03, 0x88

 

So you should either take a substring of the 3rd and 4th characters, or make sure that you pass a 16 bit quantity into the type cast, either by doing you sums in a U16 or by doing a "to U16" before the cast. Use whichever is most appropriate to the calulation that produces the 0x0388 result.

 

The 'number to hex string' converts the input number into a printable text string representation of the number; here the bit pattern is different. Therefore the 32 bit value of 0x00000388 (or 16 bit value of 0x0388) is converted into three ascii characters '3', '8', '8', having the hex values of 0x33, 0x38, 0x38

 

Rod.

 

0 Kudos
Message 4 of 5
(2,545 Views)

So did you work it out?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 5
(2,522 Views)