Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial VISA 'Write' -why is it slow to return even with large buffer?

Hi,

 

I'm writing a serial data transfer code 'module' that will run 'in the background' on a cRIO-9014.  I'm a bit perplexed about how VISA write in particular seems to work.

 

What I'm seeing is that the VISA Write takes about 177ms to 'return' from a 4096 byte write, even though my write buffer has been set to >> 4096.

 

My expectation would be that the write completes near instantly as long as the VISA driver available buffer space is greater than the bytes waiting to be written, and that the write function would only 'slow down' up to the defined VISA timeout value if there was no room in the buffer.

 

As such, I thought it would be possible to 'pre-load' the transmit buffer at a high rate, then, by careful selection of the time-out value relative to the baud rate, it would self-throttle once the buffer fills up?

 

Based on my testing this is not the case, which leaves me wondering:

 

a) If you try to set the transmit buffer to an unsupported value, will you get an error?

b) Assuming 'yes' to a, what the heck is the purpose of the serial write buffer? I see no difference running with serial buffer size == data chunk size and serial buffer size >> data chunk size??

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 1 of 9
(5,955 Views)

Hi QFang,

 

I am curious if you have NI-Spy running in the background? If so, then it will have the same performance effect on your VISA commands that Highlight execution does in your VI.

0 Kudos
Message 2 of 9
(5,915 Views)

Hi ChasePotato,

I googled and figured out that NI-Spy is now called IO-Trace, and no, I'm not running an IO Trace session.

 

I'm unfamiliar with NI-Spy, I have a 'Data Finder' icon in my taskbar, but I'm not intentionally running NI-Spy and not aware of how to check if it is running.

 

Thanks!

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 3 of 9
(5,894 Views)

QFang,

 

Would it be possible for you to attach your code or a screenshot so that we can get a better idea of your architecture?

0 Kudos
Message 4 of 9
(5,874 Views)

Hi, I can quickly show the low-level part as a png. It's a sub-vi for transferring file segments.  Some things like the thin 'in-line' VI with (s) as the icon were added to help me look at were the hold-up is.  I cropped the image to make it more readable, the cut-off left and right side is just the input and output clusters.

 

In a nut-shell, the VISA Write takes as much time to 'return' as it would take to transfer x bytes over y baud rate.  In other words, even though there is suppused to be a (software or hardware) write and read buffer on the com port, the VISA write function seems to block until the message has physically left the port (OR it writes TO the buffer at the same speed the buffer writes out of the port).  This is very unexpected to me, and what prompted me to ask about what the point is of the write buffer in the first place?  -The observations are on a 9014 RT target built in serial port.  Not sure if the same is observed on other targets or other OS's.  [edit: and the observation holds even if transmitting block-sizes of say 4096 with a buffer size of 4096 or 2*4096 or 10 * 4096 etc. I also tried smaller block sizes and larger block sizes with larger still buffers.  I was able to verify that the buffer re-size function does error out if I give it an insane input buffer size request, so I'm taking that to mean that when I assign e.g. a 4MiB buffer space with no error, the write buffer actually IS 4MiB, but I have not found a property to read back what the HW buffer is, so all I have to base that on is the lack of an error during buffer size setting.) [\edit\]

 

The rest of the code is somewhat irrelelvant to this discussion, however, to better understand it, the idea is that the remote side of the connection will request various things, including a file.  The remote side can request a file as a stream of messages each of size 'Block Size (bytes)', or it can request a particular block (for handling e.g. re-transmission if file MD5 checksum does not match).   The other main reason for doing block transfers is that VISA Write hogs a substantial ammount of CPU, so if you were to attempt to write e.g. a 4MiB file out the serial port, assuming your VISA time-out is sufficiently long for that size transfer, the write would succeed, but you would see ~50% CPU from this one thread alone and (depending on baud rates) it could remain at that level for a verrry long time.   So, by transferring smaller segments at a time, I can arbitrarily insert delays between segments to let the CPU sleep (at the expense of longer transfer times).  The first inner case shown that opens the file only runs for new transfers, the open file ref is kept on a shift register in the calling VI.  The 'get file offset' function after the read was just something I was looking at during (continued) development, and not required for the functionality that I'm describing.

 

serial transfer.png

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 5 of 9
(5,852 Views)

QFang,

 

The USB-RS-232 device I have does not support changing the buffer size so I am limited in what I can try. 

 

I get the same times as you do. Synchronous or ansynchronous makes no difference, but again that may be a driver or OS issue.

 

It gets interesting when I change the size of the datablock.  Assuming that the buffer is 4096 since that is the default and I cannot change it, I changed the size of the datablock. For 3841 <= size <= 4096 the time is 177 ms. From 3840 down to about 1000 bytes the time is about 260 us (0.0015 * 177 ??). Below that it is more proportional to the size. At 4097 the time jumps to 354 ms (time for two blocks)  to 4481 bytes where it jumps to 621 ms (3.5 * 177 ??).

 

My guess is that VISA perfoms its own "magic" on the buffers regardless of what we tell it to do.

 

The fact that it takes much longer in some cases than the amount of data (4097 bytes for example) would justify leads me to consider this a bug. 

 

Lynn

0 Kudos
Message 6 of 9
(5,840 Views)

Lynn,

 

Are you 'with  NI' and/or have/will file this as a bug and post back here with the CAR#?

 

If not, would you be willing to share your test VI with me and I'll take the best of both and distill it into a nice bug-test project that I can send to NI's support team.  I've found that being able to send them a stand-alone project that very simply reproduce and/or show the issue saves a ton of time for everyone and I tend to get better help faster in those cases. 🙂

 

Thanks for trying and for looking at this yourself!!  -I appreciate the feedback so I know I'm not the only one that sees this behavior and find it odd!

 

-QFang

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 7 of 9
(5,832 Views)

QFang,

 

No, I am not 'with NI' nor am I 'against' them.  I have been using LV since version 1.2 so I have been around for a while.

 

Here are the two VIs I put together. Test VISA Serial Buffer.vi creates a random string of lengthe "size" and  writes it. As I pointed out earlier the driver for the device I have does not support resizing the buffer. The second VI uses the random string and VISA Write code from the first inside a loop which allows programatic changes of the string size. The write times get verrrry long (~4 seconds per string at size = 4096).  

 

I suspect that this is the effect of whatever is happening with the buffer.

 

Please keep this thread updated with what you learn from NI.

 

Lynn

Download All
0 Kudos
Message 8 of 9
(5,807 Views)

Thanks Lynn, and yeah, I noticed after posting that it says "Knight of NI" which at the time I was hurridely bashing my keyboard got translated as 'NI employee' for some reason. 😛

 

I'll keep the thread up to date with what I learn for sure.

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 9 of 9
(5,799 Views)