LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What are the Bytes left at port while data are read correctly

Solved!
Go to solution

Hello application engineers,

 

I found an interesting things on the VISA read from serial port. there is always some bytes left at port while data are read correctly.

edmonton_1-1618417986067.png

 

I have formatted data set as below at approximately 41 times per second sent from controller, then read it using VISA read.

edmonton_0-1618417724616.png

Total of 10 data each set with a "," separation between numbers,  the last one is a data set count. and the second last one is a time stamp in milliseconds. I saved data to excel sheet, and checked if there is a missing count. no missing count was found.

 

I played it around,

1. changed termination char from T to F and from F to T with read all bytes available at port

2. changed termination char from T to F and from F to T with bytes to read at  91.

3. changed termination char from T to F and from F to T with bytes to read  at  91 or 93, showing actual byte received was 91.

4. changed VISA read from synchronous I/O Mode from asynchronous to synchronous.

5. changed delay time from 10 to 30 ms for the 4 situations above.

 

The bytes left at port start from zero, it start to show increase after running for a short time, say 30 seconds to 2 minutes, then it keeps increase quickly, 

 

The test data shows, 38402 bytes left at port when data set count was 3245.

edmonton_0-1618420631152.png

 

Attached is the code and test data. could someone to have a look and help out?

 

Thanks,

Gu

Download All
0 Kudos
Message 1 of 5
(1,303 Views)
Solution
Accepted by topic author edmonton

It looks like your device is spitting out data every 24-25ms. I would remove the "write delimited spreadsheet" (place it outside of loop) and remove the "wait until next ms multiple" and see if you can keep up with your device.
Your data comes with a termination character "\r\n" so you should be using that.

Also, you can set bytes to read larger than the data you expect (ex. 1000), and it will stop at the termination character.

Message 2 of 5
(1,296 Views)

Hi Gregory,

 

It works fine after moving  "write delimited spreadsheet" outside of the loop.

 

Do you happened to know if there is a number of bytes limit for VISA read at a time?

 

Regards,

Gu

0 Kudos
Message 3 of 5
(1,265 Views)
Solution
Accepted by topic author edmonton

Problems:

You have an ever-growing array.

You are constantly rewriting that file with the ever-growing array.

You are using Bytes at Port.

 

Solution:

Don't do those things.

 

Follow Gregory's advice.  Read Crossrulz' VI Week presentation

Read an entire line of data, write it to the file appending it.

Message 4 of 5
(1,261 Views)
Solution
Accepted by topic author edmonton

@edmonton wrote:

It works fine after moving  "write delimited spreadsheet" outside of the loop.


You really should open/create/replace the file before your loop, close it after your loop, and write the data inside of the loop.  From what I see, you can just write the data straight from the VISA Read to the file using Write Text File.  Do this instead of constantly growing your array just to log it at the end.  It is best to just log the data as you get it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 5
(1,250 Views)