LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with reading from VISA

Solved!
Go to solution

Hi,

So I'm very new to LabView, But I've been searching this forum for a few days now and I couldn't find anything helpful, apologies if this is already answered somewhere else. 

I'm trying to control a Velmex stepper motor with Labview. The VI generates a string based on user inputs (1D or 2D movement, dimensions, speed, etc.) and sends the string to the device, then sends the run command and waits for the movement to finish. What I'm trying to do is to read the motor position from the controller, preferably in real time. The first attached image (labview_block_diagram.png) shows what I'm using right now. It sends an "X" command to the controller, and then reads the response. Note that this runs before anything else is sent to the device. When I run this VI, this is what I see. Basically, the correct value is read somehow, but not the correct number of digits are being shown (I guess?). When I send the same command through Velmex's software (COSMOS), I get the right value (see the second attached image, blue text is sent to the device and yellow text is read from the device). I think I'm somehow messing up the read timing and the number of bytes to be read, can anyone advice on how to solve this issue?

Any help is much appreaciated. 

Download All
0 Kudos
Message 1 of 4
(2,447 Views)

Hi,

You hsould try to determine if the data sent by your Velmex is having a termination character.

If so, set the same character as the termination character of your session (Using VISA Configure port fiunction) and Enable Termination Character. Then write and read (as you do today), read will wait for the termination character, and you'll get your value.

Otherwise, be sure to read the correct number of bytes (which is returned by the read function) after your write.

 

However, what you should do first, is force to wait between W and R. In your VI you don't know when the loop waits. so after your write, add a falt sequence, insert your wait into it, and then do your read (VISA reference you enter and leave the flat sequence).

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
Message 2 of 4
(2,407 Views)
Solution
Accepted by topic author Siavash87

zyl7 wrote:

However, what you should do first, is force to wait between W and R. In your VI you don't know when the loop waits. so after your write, add a falt sequence, insert your wait into it, and then do your read (VISA reference you enter and leave the flat sequence).


That is not needed.  The VISA Read will take care of the wait for you.  By default, there is a 10 second timeout.  So the VISA Read will sleep until the number of bytes is read, the termination character is read (if enabled), or the timeout.  In this case, the OP tells the VISA Read to read 7 bytes.  But the data shown in the command line example shows at least 8 bytes being read.  So the first half of your reply was correct in that the termination character should be used if the instrument does sent one.  And if the termination character is used, then the bytes to read should be set to something larger than any message should be; I like to use 50.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 4
(2,390 Views)

Thank you very much for the recommendations. It's working as intended now. Thanks.

0 Kudos
Message 4 of 4
(2,356 Views)