LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Port Read

Greetz All,

I'm building a function to read messages on the serial port that vary
from 2 to 10 bits in length, and are separated by a carage return.

What I would like to be able to do is look at the port and scan for the
carrage return, then grab all the data before the CR and dump it into
an array.

What I have now is this. I grab all the data at the port in a 10ms
scan, then run the string through a series of "Match Pattern" vi's that
are daisy chained together. These look for the CR, then pass the bits
before the CR out to the array, and pass the rest of the string on to
the next "Match Pattern", and it looks for the next CR.....

Is there a way to scan the port for the CR then do a read so I can grab
one message at a time so I'm sur
e I don't miss any messages.

Thanks
Ed


Sent via Deja.com
http://www.deja.com/
0 Kudos
Message 1 of 9
(4,419 Views)
Assuming you're using VISA (if you're not, I would recomend doing so), you
can set the termination character to be CR. If the messages consist of multiple
lines, you'll have to keep reading until the buffer is flushed.

Ed Dickens wrote:
>Greetz All,>>I'm building a function to read messages on the serial port
that vary>from 2 to 10 bits in length, and are separated by a carage return.>>What
I would like to be able to do is look at the port and scan for the>carrage
return, then grab all the data before the CR and dump it into>an array.>>What
I have now is this. I grab all the data at the port in a 10ms>scan, then
run the string through a series of "Match Pattern" vi's that>are daisy chained
together. These look for the CR, then pass the bits
>before the CR out to
the array, and pass the rest of the string on to>the next "Match Pattern",
and it looks for the next CR.....>>Is there a way to scan the port for the
CR then do a read so I can grab>one message at a time so I'm sure I don't
miss any messages.>>Thanks>Ed>>>Sent via Deja.com>http://www.deja.com/
0 Kudos
Message 2 of 9
(4,419 Views)
Not really, since the serial port simply receives characters; it doesn't do
anything special if one of the characters is a carriage return.

Your method of stringing many "match pattern"s together is horrible. What I
suggest doing is writing a VI that runs continuously and every so often,
depending on how fast data is coming in and how large your serial port
buffer is, read the data from the port and append it to a "buffer" string
inside your monitor VI. This VI then goes into a while loop where a "Match
Pattern" function scans the buffer string for a carriage return. If it finds
one, it splits out the string before the CR, dumps the CR itself, writes the
string before the CR to a queue and writes the rest of the string back to
the shift register. The loop goes round again and the process continues
until there are no more CRs left in the buffer, and what's left is either
nothing or is the first few characters of a new message. The loop
terminates, you do the serial port read again, the unfinished message is
completed along with grabbing any more messages and the process begins
again.

You'll need some way of signalling the program to quit when your main
application terminates; a simple way would be to have the monitor VI create
the queue, and before writing messages to it see if the queue still exists;
if not, quit. This way your main application can simply close down the queue
on completion and the serial port monitor will die.

Once this program is up and running, your main application simply checks the
queue every so often to see if any messages are waiting- if so, then each
queue entry you retrieve is a single, complete message.

The only way you can lose messages this way is if you have a serial buffer
overflow, in which case you need to decrease the loop delay in the monitor
VI.

Ed Dickens wrote in message
news:934kbn$fsk$1@nnrp1.deja.com...
> Greetz All,
>
> I'm building a function to read messages on the serial port that vary
> from 2 to 10 bits in length, and are separated by a carage return.
>
> What I would like to be able to do is look at the port and scan for the
> carrage return, then grab all the data before the CR and dump it into
> an array.
>
> What I have now is this. I grab all the data at the port in a 10ms
> scan, then run the string through a series of "Match Pattern" vi's that
> are daisy chained together. These look for the CR, then pass the bits
> before the CR out to the array, and pass the rest of the string on to
> the next "Match Pattern", and it looks for the next CR.....
>
> Is there a way to scan the port for the CR then do a read so I can grab
> one message at a time so I'm sure I don't miss any messages.
0 Kudos
Message 3 of 9
(4,419 Views)
The VISA serial read function will allow you to specify CR as the terminator
character of a serial read.

otherwise I typically perform a serial read, catenate string with a shift
register in a while loop and scan for the CR in the string until it arrives
or timeout.

Stu

"Ed Dickens" wrote in message
news:934kbn$fsk$1@nnrp1.deja.com...
> Greetz All,
>
> I'm building a function to read messages on the serial port that vary
> from 2 to 10 bits in length, and are separated by a carage return.
>
> What I would like to be able to do is look at the port and scan for the
> carrage return, then grab all the data before the CR and dump it into
> an array.
>
> What I have now is this. I grab all the data at the port in a 10ms
> scan, then run the str
ing through a series of "Match Pattern" vi's that
> are daisy chained together. These look for the CR, then pass the bits
> before the CR out to the array, and pass the rest of the string on to
> the next "Match Pattern", and it looks for the next CR.....
>
> Is there a way to scan the port for the CR then do a read so I can grab
> one message at a time so I'm sure I don't miss any messages.
>
> Thanks
> Ed
>
>
> Sent via Deja.com
> http://www.deja.com/
Stu
0 Kudos
Message 4 of 9
(4,419 Views)
Thanks,

I actually found the terminate char on the VISA Init vi over the
weekend and it works just like I need.

Wish I would have seen that sooner.
Ed


In article <5SQ56.3311$_G5.288288@typhoon.nyroc.rr.com>,
"Stu McFarlane" wrote:
> The VISA serial read function will allow you to specify CR as the
terminator
> character of a serial read.
>
> otherwise I typically perform a serial read, catenate string with a
shift
> register in a while loop and scan for the CR in the string until it
arrives
> or timeout.
>
> Stu
>
> "Ed Dickens" wrote in message
> news:934kbn$fsk$1@nnrp1.deja.com...
> > Greetz All,
> >
> > I'm building a function to read messages on the serial port that
vary
> > from 2 to 10 bits in length, a
nd are separated by a carage return.
> >
> > What I would like to be able to do is look at the port and scan for
the
> > carrage return, then grab all the data before the CR and dump it
into
> > an array.
> >
> > What I have now is this. I grab all the data at the port in a 10ms
> > scan, then run the string through a series of "Match Pattern" vi's
that
> > are daisy chained together. These look for the CR, then pass the
bits
> > before the CR out to the array, and pass the rest of the string on
to
> > the next "Match Pattern", and it looks for the next CR.....
> >
> > Is there a way to scan the port for the CR then do a read so I can
grab
> > one message at a time so I'm sure I don't miss any messages.
> >
> > Thanks
> > Ed
> >
> >
> > Sent via Deja.com
> > http://www.deja.com/
>
>


Sent via Deja.com
http://www.deja.com/
0 Kudos
Message 5 of 9
(4,420 Views)
Hi, I'm new to this thread! But I too facing similar kind of problem...
Actually when I do the visa read...I need to scan the data text string in this format:
x23y676x56y776x90y77... which means that my x coordinate is 23 y coordinate is 676  and these two values are processed further in my vi. But my constraint is I need to scan this packet at one shot. i.e x23y676 like that...some times what happens is I receive only x23 and y676  data comes after some time. So it disturbes my timing in vi and things get screwed  up.
So what I want is even if y676 comes a bit late my visa read should keep scanning and store all x23y676 string into buffer and only than send some hgh signal out so that I can use this signal later.
Because if I receive x23 and y676 as two data my signal goes high twice and timing gets disturbed.
I hope Im clear enough...
can you please help around../

0 Kudos
Message 6 of 9
(3,982 Views)
Hi, I'm new to this thread! But I too facing similar kind of problem...
Actually when I do the visa read...I need to scan the data text string in this format:
x23y676x56y776x90y77... which means that my x coordinate is 23 y coordinate is 676  and these two values are processed further in my vi. But my constraint is I need to scan this packet at one shot. i.e x23y676 like that...some times what happens is I receive only x23 and y676  data comes after some time. So it disturbes my timing in vi and things get screwed  up.
So what I want is even if y676 comes a bit late my visa read should keep scanning and store all x23y676 string into buffer and only than send some hgh signal out so that I can use this signal later.
Because if I receive x23 and y676 as two data my signal goes high twice and timing gets disturbed.
I hope Im clear enough...
can you please help around../

0 Kudos
Message 7 of 9
(3,982 Views)
Let's stick to your original post on this question instead of hijacking a 6 year old thread.
0 Kudos
Message 8 of 9
(3,965 Views)

What is it that you aren't getting answered in the other thread?!? This is getting to be habitual. You post the same question multiple times when there are people who are actively working to help you on your original threads. This sort of repeated posting or hijacking very old threads does nothing but increase the noise level on the forum and alienate the people who are working you.

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 9 of 9
(3,959 Views)