LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial port reading timing issue.

Hello,

My application contains VISA serial port read with termination char of
. The VISA read reused the Labview example "Labview <-> Serial".
If I add delay in the "waits for bytes to arrive" loop, it can read
more chars but still not stop at .

But if I copy this part and test outside the application, it works
very well.

Can you please help me out with this? Thanks.

Isabella
0 Kudos
Message 1 of 5
(3,165 Views)
isabella.li@mot.com (Isabella) writes:

> Hello,
>
> My application contains VISA serial port read with termination char of
> . The VISA read reused the Labview example "Labview <-> Serial".
> If I add delay in the "waits for bytes to arrive" loop, it can read
> more chars but still not stop at .
>
> But if I copy this part and test outside the application, it works
> very well.
>
> Can you please help me out with this? Thanks.
>
> Isabella

Isabella,

You can use the VISA featue I like most:

Just try to read a lot more bytes from "VISA read" than your device
will ever send. The function will stop after reading the and
deliver the message read so far.

You'll have to ensure that the VISA properties for term char etc. are
set. But AFAIR they
are default.

HTHm

Johannes Niess
0 Kudos
Message 2 of 5
(3,165 Views)
What if I want the real time reading?
0 Kudos
Message 3 of 5
(3,165 Views)
isabella.li@mot.com (Isabella) writes:

> What if I want the real time reading?

It depends on your definition of "real time".

Do you mean decoding the start of the message before the final LF has
arrived?

Given a typical message length of 12 bytes and a dead slow baud rate
of 1200 you can send/receive 100 messages/second (without accounting
for delays in the serial device). I would not trust standard LV to
show real time behavior at that rate (10 ms/message). That's even less
than a typical interrupt needs to get processed on Intel hardware and
a standard operating system. And that estimation is just the lower
bottom.

If you mean to read parts of the message to get at e.g. a byte
decribing the length of the remaining message you have to s
witch off
the "term char" VISA property to read that part. But it would be
unusual to have both message length bytes (which are often used in binary
protocolls using all 256 byte combinations) and message end chars
(which are most often used in "ASCII" protocolls using only printable
characters).


Johannes Niess
0 Kudos
Message 4 of 5
(3,165 Views)
What I mean real time is that when all the pieces which separated by
LF come, it will output to the other VI.

The message I want to read could have any length from 40 bytes to 300
bytes. The format is like this:

+CMT:xxxxxxxxyyyyyyyyy
I use a while loop to read the serial port and concatenate 3 times
untill all the pieces arrive, then output outside the loop.

The strange things happened yesterday:
The output was not stopped at LF instead of anywhere.
The strange things today:
The output stop at LF but sometimes at the second LF and sometimes the
third LF.

The baud rate may explain this strange things: given the longest msg
with 300 bytes and the baud rate set to 9600, so about 30ms/msg. But
on the other hand
, shouldn't the VISA read have the capability to
handle such situations? what is the best way to solve my reading
problem?
0 Kudos
Message 5 of 5
(3,165 Views)