From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Visa buffer read in event case

Hello everybody.

I'm realizing a VI to control 3 motorized stages by RS232 Standa driver. I'm able to control the 3 stepper motors and i can correctly send the commands to the driver. I've problems when i attempt reading Visa buffer answers from my driver.

I attach two image from my work. In 1.jpg there's the case structure, opened on one of SUBVi; in 2.jpg there is a SUBVi example codex.  

I'd like help to read VISA and show the red string on front panel.

Thank you very much for the answers

Download All
0 Kudos
Message 1 of 16
(3,860 Views)

I'd guess that the 50ms delay you have isn't quite right in some respect when you are monitoring for the stepper motor's reply. 

 

Instead of have a fixed delay between the write and the read, I'd recommend implementing some sort of polling scheme. What this means is you should put the Bytes at Port Property node and VISA Read inside a while loop with a 5-10ms wait in that loop. Poll the VISA port until you either get the proper response from the stepper motor or a timeout occurs. If either of those events occur then stop the while loop. In the event of the timeout you might want to keep track of that, or display it on the UI, so you know you didn't get the proper response.

 

Let me know if this helps! 

0 Kudos
Message 2 of 16
(3,849 Views)

I agree with zenthoef,

 

the trick is to have a shift register that contains the entire strings that are read with each iteration of the loop.  That means placing a Concatenate String after the VISA read.  The output goes to the shift register.  You can wire at the same output a Match Pattern (or equivalent) and check that the Offset Past Match is greater or equal to zero.

 

Minor comment:  your command constant...  you don't need to concatenate the carriage return.  You can simply add it to the top string.  You can view string as '\' code display.

Message 3 of 16
(3,844 Views)

"the trick is to have a shift register that contains the entire strings that are read with each iteration of the loop.  That means placing a Concatenate String after the VISA read."

 

Good point! I forgot that a shift register with a concatenate string will help ensure that the entire message is received properly.

0 Kudos
Message 4 of 16
(3,840 Views)

(Thanks zenthoef)

 

I forgot the following:  To learn more about LabVIEW, I suggest you try looking at some of these tutorials.

0 Kudos
Message 5 of 16
(3,837 Views)

Do you suggest a code like that in attachment?

Thank you very very much for your fast answer. I'm at home now; tomorrow i'll try it at my lab

 

0 Kudos
Message 6 of 16
(3,829 Views)

That looks pretty good. Don't forget to OR the loop stop condition with some code that will time the loop out. Otherwise, you may get stuck in this loop, infinitely300! Take the iteration terminal and compare it to about 300, which will be about 3 seconds for you (make this higher if you need more time). If the iteration goes above 300, then stop the loop. 

0 Kudos
Message 7 of 16
(3,826 Views)

almost...

 

The way it is wired now, it will stop at the first iteration..  So it won't work..

What you need to do is have a control which has the expected value.  The value you are expecting back.. wired to [b*]. (It can be a subset at the end of a long string)

 

Or better yet, simply read until you read 0 bytes from "Bytes at Port".

 

 

0 Kudos
Message 8 of 16
(3,822 Views)

thanks a lot...last question...the New code regarding read visa, in while loop, must be placed out yhr event structure, isn't it?

francesco

0 Kudos
Message 9 of 16
(3,821 Views)

you have an event structure?

 

oh.. euh.. if you are talking about the code that you showed...  yes, it does not need an event structure.

0 Kudos
Message 10 of 16
(3,815 Views)