From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I call VISA Read multiple times without a timeout?

I have an instrument that returns data in 3 parts. First 2 bytes indicates the number of bytes to read for the actual number of bytes that is being sent. (ie. <#4><2000><2000 bytes of data> ) The vi must call the 'VISA Read.vi' 3 times. One to pick-up the <#4>. One to pick-up the <2000>. and one more to get the actual data. My problem is that the first call to 'VISA Read' returns the <#4> OK but then appears to delete the remaining bytes that are returned. If I re-write so that I read say 10,000 bytes on the first read, then the data is OK. I don't know exactly how many bytes that the instrument is going to send back. It may include multiple reads to get all of the data. Is there a flag or parameter that I have to set in the VISA drivers?

Thanks
0 Kudos
Message 1 of 12
(2,812 Views)
You can set VISA serial settings using the VISA Configure Serial Port VI. The default timeout is 10 secs. However, I don't see why this should be a problem. If you ask for X bytes and recieve them, the VI finishes and returns the data. If you build a piece of code similar to this one inside a while loop it should work. The one thing I don't understand is this: You're saying the first byte should be #4. Does this work in serial? Isn't that 2 bytes?
Hope this helped. If it didn't, try posting your code.

___________________
Try to take over the world!
0 Kudos
Message 2 of 12
(2,807 Views)
You Are correct. It is 2 bytes. Your drawing does not seem to work for me.

Here is the drawing that I'm working with. It is part of the VISA driver I downloaded from NI.
0 Kudos
Message 3 of 12
(2,802 Views)
The code looks alright, I think. Place a probe or an indicator on both the string coming out of the first read and the number going into the second one and see what comes out. A timeout happens when you ask for a certain number of characters and you don't get them within the given time. Since you say 10,000 did get the entire string, the only thing I can think about is that you wire 0 bytes to read and this (for some reason) causes a timeout, but I can't check this at the moment.

___________________
Try to take over the world!
0 Kudos
Message 4 of 12
(2,794 Views)
I have probed everywhere and data only comes out of the first read.

Here is a vi that works but I don't want to use it because I can not predict how much data is going to be there.
I have set the record to 2010 bytes but after probing I only have 2007 total.

Thanks for your reply.
0 Kudos
Message 5 of 12
(2,789 Views)

@Trendor wrote:
I have probed everywhere and data only comes out of the first read.

Yes, but what data? How many bytes to read are sent to the second read?
I'm not big on serial but the only option I can think of is that the instrument only responds to the first read and after one read stops sending the data.

___________________
Try to take over the world!
0 Kudos
Message 6 of 12
(2,784 Views)
Oh, I'm sorry. Two bytes are read by the first call (controlled by the constant). They are ASCII pound sign and ASCII 4. These get parsed as an integer 4 which is wired to the bytes in of the second call. So the second call is to read a total of 4 bytes. It waits 10 seconds and then returns a timeout error and no bytes in its output and zero in its count.

BTW, this is not serial, it is GPIB. But wait, it is a USB GPIB. I've not used that before. Maybe this is a National problem.
0 Kudos
Message 7 of 12
(2,779 Views)
In that case, I can't help you. I don't work with GPIB. I don't even know what GPIB stands for (and I don't need anyone to tell me, either, so don't all jump at this opportunity).

___________________
Try to take over the world!
0 Kudos
Message 8 of 12
(2,775 Views)
Thanks for your help, tst.

Good Luck.
0 Kudos
Message 9 of 12
(2,773 Views)
Are there any termination characters between the different pieces of data? If there were, then you could enable termination on your GPIB session. This would allow you to read a specified number of bytes OR any number of bytes less than the specified amount up to the termination character.

For instance:
Number of bytes to recieve: 10
Termination character: ASCII "5"
Data in buffer waiting to be read by VISA Read: I work 5 days a week.
1st VISA Read returns: "I work ", or 7 bytes of data
2nd VISA Read returns: " days a we", or 10 bytes of data
3rd VISA Read would time out, because there's not 13 bytes of data to read, and there are no other termination characters to read to.

Typically you would use an ASCII newline character as the termination character, but I used 5 for example purposes only. Anyhow, is this even a possibility with your system? Can you configure your target instrument to append termination characters to the data sent?

Logan S.
0 Kudos
Message 10 of 12
(2,756 Views)