LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending 8-bit binary values to Serial COM port usnig NI-VISA

Solved!
Go to solution

Hi guys,

I am struck with my project. I hope you guys can help me resolving it.

I am reading a excel file which has numerical data in it and i am making some calculation with it. I want to convert the numerical data into 8-bit binary format and i want that binary number to be sent to one of my serial port in my laptop so that i can read it with a microcontroller.

So i am using NI-VISA WRITE function to write the data to one of my Serial COM port. NI-VISA  WRITE function can send only string format to the COM port. All i need is 8-bit binary numer on the output(Serial COM port).my VImy VI

0 Kudos
Message 1 of 3
(2,788 Views)
Solution
Accepted by BOND002

You can either build a U8 array, then Type Cast or Flatten it to a string.

example.png

With Type Cast, only binary data are converted to the string; with Flatten to String, an I32 header may be added (and it is by default) meaning the number of array elements. Also, with Flatten to string you can select the byte order.

In the picture below, the string content in hex format is shown (two characters per byte).

pincpanter_0-1581927184916.png

If you send data continuously, you may need to add some control character (a start byte sequence, for example), to help the receiver to separate subsequent packets.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 3
(2,763 Views)

@pincpanter wrote:

If you send data continuously, you may need to add some control character (a start byte sequence, for example), to help the receiver to separate subsequent packets.


If we are actually sending raw/binary/hex values over the serial port, then a typical method is to have a start byte (0x02 is common) followed by a message ID and/or a message length, the the data and finally a checksum of some type.  This allows the receiver to find where the message actually starts and validate the message was properly received.


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 3
(2,742 Views)