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: 

Newbe: Serial Port Programming

Hi, I new to labview and I can't understand how to program the serial
port? Can the serial port through LabView read binary data ?
Everything I read talks about strings which for me are only ASCII
data. Thanks for any help you can give.

Regards

Steve Drake
0 Kudos
Message 1 of 4
(2,845 Views)
Steve Drake wrote:

> Hi, I new to labview and I can't understand how to program the serial
> port? Can the serial port through LabView read binary data ?
> Everything I read talks about strings which for me are only ASCII
> data. Thanks for any help you can give.

The short answer is Yes, LV and serial port read binary data.

The long answer is a bit more complex.

The serial port only understands binary data (that is, some sequence of 0's
and 1's).
Interpretation of that sequence is another matter.
ASCII assigns specific characters to specific sequences of binary data.
Since ASCII covers the range of an 8 bit sequence it is normally used
to transfer serial data. This can be seen by the serial port VIs.
If I wanted to send binary data of 41 (hex) I would send the A
SCII
character "A" using serial port write VI.
If I received the binary data of 41 (hex) the serial read VI will give me an
ASCII "A"
this may mean the character "A" or hex 41 or decimal 65 or it could mean
"feed the cat".
It is all a matter of interpretation.

Use the string functions to generate and decode the values to something
appropriate.

Hope this is less confusing than Quantum Physics.
Kevin Kent
0 Kudos
Message 2 of 4
(2,845 Views)
Yeah, this can get confusing for newbies. If you're sending anything
other than text messages, your strings are going to look garbled and
messy. Make use of the "String to Byte Array" and "Byte Array to
String" functions. You can always use "String to Byte Array" and then
hook up an indicator to the output, and an array of the data you're
sending will pop up. Then you can view it in decimal for the ASCII
codes. Hex is also good for viewing bytes.

Rick
0 Kudos
Message 3 of 4
(2,845 Views)
Hi, Unfortunately I can't attach you my VI to labview for serial port with
this post. Email me and I attach VI to my mail.
I use sequence structure for work with serial port:
1 frame - I use Serial port init VI for setup port number, baud rate and
...
2 frame - Writ command to serial port.
3 frame - Read number of characters and convert them into binary or hex or
else format.
With Best Regards.
Vadim
Ukraine
0 Kudos
Message 4 of 4
(2,845 Views)