04-14-2021 12:11 PM - edited 04-14-2021 12:17 PM
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.
I have formatted data set as below at approximately 41 times per second sent from controller, then read it using VISA read.
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.
Attached is the code and test data. could someone to have a look and help out?
Thanks,
Gu
Solved! Go to Solution.
04-14-2021 12:24 PM - edited 04-14-2021 12:25 PM
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.
04-14-2021 02:01 PM
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
04-14-2021 02:02 PM
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.
04-14-2021 02:29 PM
@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.