LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial to TCP VI

I am trying to write a VISA serial to TCP VI. I want to be able to read in 12 bit serial data and do the following:

1)Construct a 256 byte array of double and bundle
2)Bundle 12 bytes of a first signal
3)Bundle 12 bytes of a second signal
4)Bundle 12 bytes of a third and final signal

In my experience, a serial port buffers 8 bits. The Configure I/O buffer size.vi looks like it is setting it to a 16 bit buffer which is large enough for our 12 bit data. So then I have a FOR loop with 512 iterations -- two 8 bit reads for one "packet" so that would ultimately be 256. This looks good to me. However, I also need those other three 12 bit data signals. How can I differenentiate these from the array I need to construct? Any help would be greatly appreciated!

I attatched my VI so you can take a look at it!
0 Kudos
Message 1 of 5
(3,266 Views)
You do not need to re-configure the serial port and buffer 512 times for each iteration of the while loop. Once should be sufficient. Move those parts outside both loops.

Unless you are absolutely sure the data will be there when you try to read, it is considered good practice to poll the serial port with a VISA Bytes at Port property node and only attempt to read the number of bytes actually present.

As for parsing the data, it is very helpful to have some kind of framing character in the serial string. Does the sending device use a carriage return or a control character to mark the end of the data set? If it does not, you may never be able to be absolutely certain which characters belong to which parts of the data. A continuous sequence of numeric characters can be quite tricky to parse.

Lynn
0 Kudos
Message 2 of 5
(3,243 Views)
Hi King Cosmos!

I agree with everything that Lynn said, but I'll add my 2 cents worth also. First off, sending a 16 to the 'mask' input of the VISA Set I/O Buffer Size.vi DOES NOT set the buffer size to 16. The mask input is a code that specifies which buffer (16-> I/O receive buffer; 32-> I/O transmit buffer; 48-> both) to set the size of. The 'size' input of the VISA Set I/O Buffer Size.vi is actually what specifies the size of the selected buffer. The way you have it set up is fine, but I just wanted to explain actually how it was set up :-). See the Help for VISA Set I/O Buffer Size.vi:

=======================================================
MASK designates which buffer size to set. Valid values for mask are I/O receive buffer (16) and I/O transmit buffer (32). Add the mask values to set the size of both buffers simultaneously. SIZE designates the size of the I/O buffer. Set size slightly higher than the amount of data you expect to transmit or receive. The default is 4096.
=======================================================

Secondly, I see that you are acquiring 512 bytes (256 words) of data, but I never see where you're reading the other 3 pieces of data. If those 3 pieces of data are also coming in over the serial port, you will need to be able to distinguish that they are actually "different" than the 256 words of data for your array. Some type of indication will be needed for this (some type of token that you search for or something). Then you will also (obviously) need to increase your iterations of the For Loop to account for the extra 3 pieces of data.

Hope this helps!!

Travis H.
National Instruments
Travis H.
LabVIEW R&D
National Instruments
0 Kudos
Message 3 of 5
(3,230 Views)
Thank you for your advice. I have one last question that bothers the hell out of me. I can run my VI I posted, or the sample serial VIs included with LabVIEW 7.1 Professional at my school computer just fine. However, if I run these very same VIs at home (LV 7.1 Pro) I get an undefined error with the VISA configure serial port VI. If I increase the wait before read (in the samples) it sits there until time is up and gives me the undefined error. Does anyone know what could be going on?
0 Kudos
Message 4 of 5
(3,227 Views)
It's possible that you have a problem with VISA on your home computer. Try placing a VISA resource control on your front panel and see which resources you have available. If you have none, or their names are wrong, there are a few things to do. Try searching for VISA and serial on this site.

___________________
Try to take over the world!
0 Kudos
Message 5 of 5
(3,212 Views)