LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send HEX command to NI-Visa write

Solved!
Go to solution

Hello experts,

I want to send a HEX command to serial port device through NI visa and i use Simple serial program. How can i send HEX command to device. 

 

Sina6611_0-1712840932673.png

 

0 Kudos
Message 1 of 13
(354 Views)
Solution
Accepted by topic author Sina6611

Just switch your string control to Hex display mode:

Screenshot 2024-04-11 15.14.20.png

 

Then you will get hex representation inside:

Screenshot 2024-04-11 15.15.33.png

0 Kudos
Message 2 of 13
(349 Views)

Hi experts,

How can send HEX command 0X0211EE0X03 to NI-VISA write? I know that I can write click on the string box and convert it to HEX. But I want to know should I input  HEX command as an array or as a write buffer?

0 Kudos
Message 3 of 13
(316 Views)

@Sina6611 wrote:

I want to send a HEX command to serial port device through NI visa and i use Simple serial program. How can i send HEX command to device. 


I've seen way too much confusion of "hex commands", so I have to ask what you mean by this?  There are two main ways I've seen this defined (along with a couple of really weird ways):

1. Raw/binary/hex data - You are sending raw values, with no connection to ASCII what so ever.

2. ASCII Hex - You are sending ASCII characters that, in normal display, look like hexadecimal values.

 

If the raw, changing your string controls and constants to Hex display (and make the Display Style visible) will make your life 1 billion times easier.

 

If you are just getting into serial communications, I very highly recommend watching this video: VIWeek 2020/Proper way to communicate over serial.  The second half gets into the raw/binary/hex formats, and you need to be a lot more careful than with ASCII protocols.


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 4 of 13
(328 Views)

Actually, I want to send the following HEX command:

0X0211EE0X03

 

 

Sina6611_0-1712842889239.png

 

but I want to know, should it be as an array or as a write buffer?

 

 

 

 

 

0 Kudos
Message 5 of 13
(319 Views)

@Sina6611 wrote:

Actually, I want to send the following HEX command:

0X0211EE0X03

 

but I want to know, should it be as an array or as a write buffer?


If you know the full command, just use a string with the Hex Display.  If you need to build up the message with calculated values, etc., I will most often use Flatten To String on the values and then Concatenate String to put everything in the right order.

 

With that said, I very highly encourage you to watch the video I linked above.  Raw/Binary/Hex protocols need a lot more care than is shown in the Simple Serial Port example in order to make sure you are reading exactly one message.


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 6 of 13
(292 Views)

Hello everyone, 

I want to send a command to a serial device. The connection works, but it sends false commands. Can anyone say what is the problem? Command is 0X0211EE0X03

 

Sina6611_0-1712921025955.png

 

 

Sina6611_1-1712921146813.png

 

0 Kudos
Message 7 of 13
(227 Views)

Hi Sina,

 


@Sina6611 wrote:

Hello everyone, 

I want to send a command to a serial device. The connection works, but it sends false commands. Can anyone say what is the problem? Command is 0X0211EE0X03


Well, we don't have your VI, we don't have your hardware/device, we don't have a manual for your device…

 

What I can say from your image:

  • When the message contains just one byte ("11") then you don't need an array control: a scalar control would be ok.
  • When this "11" value should be hexadecimal then you need to input 17 (as 0x11 = 0d17) into your array control - or switch the numeric formatting of the control to hexadecimal (and show the radix!)!
  • When using such "hex" messages you most often should turn off the TermChar option for your serial communication! Or use the correct TermChar, which should be 0x03 in your case.

Did you already watch this video?

 

And PLEASE don't create multiple threads for the same question/problem!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 13
(222 Views)

thank you for your answer.

My message is 0X0211EE0x03

How can is send it to device?

0 Kudos
Message 9 of 13
(211 Views)

Hi Sina,

 


@Sina6611 wrote:

thank you for your answer.

My message is 0X0211EE0x03

How can is send it to device?


No need to ask the same again and again:

I repeat from my previous message: show the radix/display style for each numeric/string control/constant used for building your message string! (After showing the radix it's much easier to set/use the correct radix…)

 

Btw. you should write "0x02 0x11 0xEE 0x03" to make clear EACH byte is written in hexadecimal encoding! You present a string without any spaces in between, one "0X" and one "0x" (uppercase/lowercase X), the "11"/"EE" without any radix at all - all this makes it harder to understand your issue!

Best regards,
GerdW


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