LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from serial port a large number of Bytes.

Just like the subject says, Is there any way I can read a large number of bytes(64K) from the serial port. Do I need some sort of loop?
0 Kudos
Message 1 of 13
(3,939 Views)
A loop is needed.  I believe the serial port buffer size is maxed out at around 32k.  Read in chuncks until nothing is left in the buffer.  Use the VISA property node "Bytes at Serial Port" to determine when to stop reading.

Dan Press
PrimeTest Automation
0 Kudos
Message 2 of 13
(3,936 Views)
Where can I find an example of this? I used the example I found on labview labeled "Basic Serial Read and Write" all i did was changed the baud rate and wrote my own command. The only thing is it stops at 1920. I want to make it go further.

Message Edited by Newguy100 on 08-18-2005 04:01 PM

0 Kudos
Message 3 of 13
(3,934 Views)
Here is my vi
0 Kudos
Message 4 of 13
(3,928 Views)
I modified your vi to put a loop around the read part.  On the front panel, there is a timeout control.  If it takes 5 seconds to receive all your data, set the timeout to 6 (just above what is needed).  The port will be read repeatedly until the timeout is reached.  The output will be the concatenated string from all port reads.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 13
(3,925 Views)
Thanks tbob, that really helps. I got another question. How come it can only run it once. Afterwards it doesn't open the serial port anymore.

Message Edited by Newguy100 on 08-18-2005 05:17 PM

0 Kudos
Message 6 of 13
(3,922 Views)

Hi tbob,

I have a promblem with the example you gave, sometime the Bytes at Port splite the data into two .for example I send the data @61RD000100081722011401140112000000005C* to the port, most of the time the byte count is 40,but sometime I get a  byte count less than 40, I get a 11,and soon I get a 29,at the Port read window it shows @61RD000100 first ,and soon it shows 081722011401140112000000005C*. Why, here is the vi. 

0 Kudos
Message 7 of 13
(3,854 Views)
I am creating a button to dump information onto the screen, but I am having a problem opening my serial port a second time. I would leave my serial port open, but since I am using a combination of *.dll and labview to read and write to the same serial port. I need to close and reopen it again. I don't know what is causing it not to read a second time.

Message Edited by Newguy100 on 08-19-2005 08:41 AM

0 Kudos
Message 8 of 13
(3,899 Views)
If you are using a dll to read/write to the serial port, the dll must be holding it open.  The Labview program has the proper Close Visa function so that should not be the problem.  I would have to say that the dll is holding the port.  That is a problem you will have to fix since I don't know anything about your dll.  I would guess your dll is not closing the port when it is done.
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 13
(3,890 Views)
It may have something to do with how quickly your device sends its data over the serial port.  Referring to your vi (which looks like one I wrote), inside the first inner loop, the loop will exit whenever it detects more than 0 bytes at the port.  This loop executes every 900 milliseconds.  Lets say that the loop starts, and 800 millseconds later, the data starts coming in.  But not all of it is recevied in that last 100 mS.  There are some bytes (>0) so the loop exits and the bytes get read.  Now there are some bytes still left at the port unread.  The next major loop will catch these, but the number of bytes will be different.  You will have to adjust the timing to match the timing of your device as it puts data onto the serial port.  Maybe increase the delay time.  Or you could change the exit requirement from bytes > 0 to bytes >= some number of bytes you expect.  If you know you will always receive 100 bytes, change the > 0 to >= 100.  Then the first inner loop won't exit until it sees 100 bytes at the port.  This should fix your problem.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 13
(3,826 Views)