LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Port Carriage return line feed

Does anyone have a solution to monitor the serial port for a carriage return line feed? My instrument under test puts data onto the port when It is available.This is done asynchronously.I am using the serial read VI in a while loop and would like to jump out of the loop upon detection of a carriage return line feed which is on the end of the data string.
0 Kudos
Message 1 of 5
(6,318 Views)
Hi JBH,
You can use the carriage return or line feed constants from the string subpalette to compare them with the serial read vi output and connect the boolean out of the compare function to the while loop conditional terminal. This way you can jump out of the while loop whenever the string value matches that constant.

Regards,
Pravin
0 Kudos
Message 2 of 5
(6,317 Views)
I would also suggest using VISA to read and write to the serial port. VISA reads will terminate at a 0xA, which is a new line character if you turn on the termination character using a VISA property node.

Randy Hoskin
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 3 of 5
(6,317 Views)
JBH wrote in message news:<506500000008000000DC560000-1027480788000@exchange.ni.com>...
> Does anyone have a solution to monitor the serial port for a carriage
> return line feed? My instrument under test puts data onto the port
> when It is available.This is done asynchronously.I am using the serial
> read VI in a while loop and would like to jump out of the loop upon
> detection of a carriage return line feed which is on the end of the
> data string.

The best solution is to use the VISA functions for your serial
communications. Once you've created the VISA session with the serial
port, you can configure it to terminate reads when a specific
character is read.

To configure the VISA session to terminate a read on a line feed
character, create a VISA p
roperty node and wire your VISA session
reference to it. Then size it to two inputs (elements). Popup on the
first element and select Properties->Message Based
Settings->Termination Character Enable. Wire a boolean to this
element and set it to true. For the second element, select
Properties->Message Based Settings->Termination Character. The input
to this function should be decimal 10, which is the ASCII numerical
value for a line feed character.

Once you do this, reading your instrument will be a snap. There won't
be any need for "loop & snoop" code. All you need to do is use the
VISA read function. It will read the input buffer until the line feed
character is read & then stop and return you the string. Use caution.
If the specified character doesn't arrive within the timeout period,
you'll get a timeout error. You can use the VISA property node to
increase the timeout period. Also make sure that your # characters to
read is equal to or greater than the number you expec
t, including the
carriage return-line feed. Additionally, you can use the VISA
property node to see how many bytes are at the port.

Email me if you have any questions about using VISA with serial

gm
0 Kudos
Message 4 of 5
(6,317 Views)
This Ni Development solutions link may help. The example vi reads the
serial port and "listens" for the carriage return/line feed characters
(\r\n).

http://zone.ni.com/devzone/explprog.nsf/webmain/EBB56F611665B8BC862568E9006A
767E?opendocument&node=DZ52363_US


Good Luck
Leno
"JBH" wrote in message
news:506500000008000000DC560000-1027480788000@exchange.ni.com...
> Does anyone have a solution to monitor the serial port for a carriage
> return line feed? My instrument under test puts data onto the port
> when It is available.This is done asynchronously.I am using the serial
> read VI in a while loop and would like to jump out of the loop upon
> detection of a carriage return line feed which is on the end of the
> data string.
0 Kudos
Message 5 of 5
(6,317 Views)