LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Determine when the visa (serial) write buffer is empty

I am using RS 422 communication to send a string of data repeatedly, and a transmission gap is expected between subsequent writes of this string. When the hardware receives the end of the string, it expects a 1.5 ms gap before the beginning of the next string comes in. Is there any way I can deteremine when the WRITE buffer is empty, or some VISA event I can use to notify me of this? I know there is a way to get bytes at port on a read, but I have found it is always 0 when writing (which doesn't really surprise me). I thought about using the baud rate and using the number of bytes sent to calculate how long it should take for the whole string to be transfered, then start the timing for my 1.5 ms gap after that time expired, but if the system runs for a while, any jitter will be compounded and eventually the transmission gap will be too large, causing errors.

 

Let me know if I need to clear anything up.

0 Kudos
Message 1 of 6
(5,487 Views)

When I think about it, if I reset the timer after each write, the jitter shouldn't effect it much. I am going to try this timing method and see what happens.

0 Kudos
Message 2 of 6
(5,477 Views)

I BELIEVE that if you right-click the VISA write and choose "syncrounous" it will not return until the data is passed to the hardware buffer (or written ) but I am not sure.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 6
(5,444 Views)

Greg Freeman,

 

Ben is correct, the synchronous mode locks the thread until just before the function returns. 

 

you can find more information regarding synchronous vs asynchronous VISA writes in this very in-depth knowledgebase article here:

http://digital.ni.com/public.nsf/allkb/ECCAC3C8B9A2A31186256F0B005EEEF7?OpenDocument

 

That being said, do realize this is still ultimately software timed on a non-deterministic OS (assuming were not on a RT target), so strict adherance to this 1.5 ms gap is not guaranteed.

 

Regards,

Kyle Mozdzyn

Application Engineering

National Instruments

 

Regards,

Kyle M.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 6
(5,412 Views)

@Ben wrote:

I BELIEVE that if you right-click the VISA write and choose "syncrounous" it will not return until the data is passed to the hardware buffer (or written ) but I am not sure.

 

Ben


You cannot rely on this for all forms of communication. I know for a fact it does not work for TCP based communications. Regardless of this setting the VISA write will return as soon as the Os accepts the data in its buffers. If you are sending large amounts of data and run a network trace you can clearly see the call to VISA write returns much ealier than the completion of the data transmission. This may not be the case with serial and GPIB communications. I'm also not sure about how USB communications work under these conditions.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 6
(5,410 Views)

What I have done and seems to work for me is as follows:

 

1. Calculate microseconds per bit based on baud rate and multiply this by the number of bits written. This is the time to transmit the whole string. I'll call it "t". t is in microseconds

2. Get a timestamp when data is first written via the visa write

3. Check the timer at each loop iteration and see if the timer is greater or equal to t + 1500 us

4. If it is, write the next string

5. Repeat steps 1-4.

 

The only issue with this is you need to make sure your loop time is fast enough so you don't go way past t+1500 before doing the next write. For instance, if t is 1000 us and the gap is 1500 us, your total wait time is 2500 us, you don't want your loop wait time to be 1500 us. Otherwise, you will write once, loop and your timer will be at 1500 us. This is not greater than or equal to 2500 us so you loop again. Next time it checks, and you are now at 3,000 us. You are now 500 us late.

 

So, what I have done is pick a small wait time based on the shortest string we will be writing to the visa, and used an in range and coerce function with the limits being the tolerance the hardware has for the gap(I think 1500 us +/- 200 us.

 

Hope that made sense. I haven't marked it as solution in case others have ideas or discussions to bring forward.  

 

I should have added, I am using a PXI so it is an RTOS

0 Kudos
Message 6 of 6
(5,391 Views)