LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

need some answer for serial communication in Labview

Hello,
I am trying to acquire a package of data from a RF board through the serial port into the computer. The package of data coming from the RF board is serial data and has a set length and start and stop with the same character. The package can come in at anytime at an unknown frequency (we know the baud rate, just not how often the packages of data come in).
I have been going through the tutorial in Labview and found some examples about read and write through serial port. However, I don't understand if Labview will keep an open communication with the device all the time so that it will detect and read in the data when the package becomes available.
I have an idea that I need to check the serial buffer for the specific character at the beginning of the package and start reading in if that character is present. But I don't really know how to do this. I found this 1 example in the folder that I think is closed to what I need. It looks like it checks for the number of bytes present against the number of bytes need to read. But I don't quite understand how it knows how many bytes are there at the serial port. Can you please explain that and also let me know if this vi is closed to what I need. Thanks,
0 Kudos
Message 1 of 5
(3,028 Views)
The vi you referenced is pretty close to what you need for the application
you described.

The general approach with serial ports is:
1) open the port
2) send and receive, repeating as appropriate
3) close the port (this step is not shown in your example; not an issue
with an example like this but the port should be closed in a real application)

In applications, the port is typically opened just as in your example. The
Visa Resource Name output from the port open is then passed to read and write cases as
necessary.

I added a while loop to your example to show how the reference can be passed between
the read and write cases. Note that this is not a complete application yet; you
have to add the logic to process your message, respond as appropriate, do error correction,
etc.

Once the serial port is opened it will buffer incoming bytes. The 'Bytes at port' function
tells you how many bytes have arrived but not yet been read. You have to have the port already
open and configured to receive bytes.

Some additional references:
http://digital.ni.com/public.nsf/websearch/e22da85e97818de78625678c0069bfc9?OpenDocument
http://zone.ni.com/devzone/devzoneweb.nsf/Opendoc?openagent&14A5CB349BD18D20862568210005EB0A

Hope this is useful.

Matt
Message 2 of 5
(3,014 Views)
Mr. Williams,
Thanks for your explanation. I could not open the vi you sent because it is a newer version than mine. I have student edition 6i. Can you save it as the older version and resend. I appreciate it. Thank you.
Also, for the Visa Resource Name, in my case it would be the name of the serial port(COM1), isn't it?
In my application, I am only concerned with reading data from the board, not writing anything to it. When the packages of data arrive, the serial port will see that. However, when there are not any data present, the signal line of the RF board may be a constant ground or 1 logic or maybe off, I am not sure. I am concern that the serial port would mistake the strings of 1 or 0 as data also. Will that be the case at all?
Thanks for helping.
0 Kudos
Message 3 of 5
(3,002 Views)
Sorry about that; I wasn't paying attention and didn't realize I had changed the version.
6.0 vi and block diagram .jpg should be attached.

Matt
0 Kudos
Message 4 of 5
(2,973 Views)
and .jpg.

Matt
0 Kudos
Message 5 of 5
(2,971 Views)