LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa read isn't reading the correct results

I have a Vi that I am using to control a stepper motor. In this Vi I start by writing several initialization commands to the motor. This is followed by either a command to send the motor to a homing position or to step to a certain angle. While the motor is moving I am using a while loop to check if the motor is in motion or not. I do this by writing a Movement command that responds a 0 or 1 accordingly. Now when I use a visa read to read the response of the movement, the visa read reads the initialization commands that I am sending at the beginning of the program. This will sometimes get fixed when I use the show highlight button on the Vi. Is this a timing problem I am having, or is there any type of way I can clear the buffer. I am not too sure how to go about this

In advance thanks for the help, it is greatly appreciated

0 Kudos
Message 1 of 13
(3,388 Views)

You are reading what you sent out?  That doesn't make any sense unless the motor is just performing a loopback.

 

Can you share any code to help give us more context?


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
0 Kudos
Message 2 of 13
(3,373 Views)

So the first visa read comes right after I query "MG_BGA;" and the reads back the text string "LC 1; AG 0;" which is the very first thing I write to the motor.

This error also occurs when I read right after I query "TD;" most of the time I am getting back "DP 0; DE0;" which is what I had previously written.

0 Kudos
Message 3 of 13
(3,368 Views)

Have you tried setting the bytes to read to some high number? It would seem you are doing incomplete reads. What does it look like when you use a terminal emulation program such as hyperterminal or putty? If you are getting multi-line responses, that would also account for your problem.

0 Kudos
Message 4 of 13
(3,326 Views)

Ahh Galil motion control. I know it very well and am generally quite pleased with what I can do with it. My Galil libraries have been in use for years now and are based on the old DMC32.dll that was once their standard offering rather than the new dot-net interface that's available so I don't guarantee I know exactly what you are dealing with but I'll give it a shot.

 

The Galil is for the most part a synchronous system where you send a message and you get a response but there it also has the ability to send unrequested asynchronous messages if something happens that it thinks you need to know about. You do have some control over how these async messages are delivered but I've always been OK with them coming over the same comm channel as the ordinary command/response communications. (FWIW I most often use controllers like the DMC-2143 and an Ethernet comm link).

 

This is what I do when communicating with the Galil:

  1. Before sending any command (as part of the low-level send/receive VI)
    1. I do a check for aysnc messages and handle any that are found
    2. I check the response buffer for any outstanding, unread response and  (usually) dump it.
  2. When a command is sent,
    1. check any error return terminal provided by the sending routine for problems
    2. Always read and check the Galil response to the command for a ":" (command OK) or "?" (command bad)
    3. if the command was asking the Galil for an immediate return of information, wait for that response and then read it.
  3. When communication is first established,
    1. Turn off The Galil's command echo ("EO 0" command)
    2. Disable the trace function ("TR0")
    3. Configure the default port for unsolicted (async) messages ("CF n" command)

 

Based on what you are describing I'd say you still have the command echo on and you are not reading the Galil's response after  every  command  you  send. You need to do that.

0 Kudos
Message 5 of 13
(3,310 Views)

Thank you so much, it does show how much you have worked with the Galil MC. The "EO 0;" and "TR 0;" worked great.

I am having a bit of an issue now with the for loop that checks the motion. So the first time the for loop gets executed I am using a search/split string with an offset of 9, (9 corresponds to the commands I have previously sent. Which is back ":::::::::" so once I offset by 9 the response the motion comes back as a 0 or 1. Now the problem I am having is that the second time through the for loop only one command is being sent which in case should respond ":" followed by the boolean for motion. Is there any way to search a string only for a integer. I am not sure how I can implement two different offsets in the same loop.

 

Is there any way I can clear the ":" response of a command?

 

you also mentioned to check for the ":" "?" response, I tried doing this using a visa read and it gives me back an error.

0 Kudos
Message 6 of 13
(3,262 Views)

If every time you send a command, you then wait for a ":" or "?" response then you will not be accumulating long collections of responses that you then need to wade through to find the data you want and then the response parser get simpler. And, as I said before, you should also consider implementing a "dump buffer" subVI before any VI that makes a request for data to be returned.

 

I only very rarely use the "split string at offset" function as that assumes the offset is either always well defined or else there is code implemented before the function to dynamically identify the correct offset. I prefer to instead use the "Match Pattern" function as it is extremely powerful if you invest the time to figure out how to use it.

0 Kudos
Message 7 of 13
(3,254 Views)

I am trying to wait for the : or ?, but how do I read it? I am trying to use a visa read and it gives me back error "-1073807339" for some commands.

Some other commands have no problem being read.

It seems like if I am seeting up parameters it doesnt like to be read. If I am querying something like position of motor or encoder, it doesnt mind being read.

0 Kudos
Message 8 of 13
(3,251 Views)

I'm guessing you are trying to use RS232 communications?  That is a bit different than the Galil DLL-based Ethernet communications that I use but it can be made to work. I believe that most Galil responses are terminated with a CRLF pair so you would want to configure the serial communications to terminate reads on a LF character.  Looking at the Galil documentation, the ":" and "?" character responses may not be followed by a CRLF but you can still use the VISA Serial Settings property "Bytes at Port" to watch (poll with timeout) for when the byte arrives and then you do a VISA read terminated on byte count (equal to the number of bytes in the buffer) to grab what's there. I've attached an image of a dump-buffer routine that I had handy and it is similar to what you would need for a read-response routine. But rather than stopping if no bytes are found, you would need to wait until a timeout time occurred or an expected response ( ":" or "?" or LF ) was received.

Dump Buffer.png

0 Kudos
Message 9 of 13
(3,235 Views)

Yes I am using serial connection to communicate, Thanks so much for the help, it is greatly appreciated.


I have a small question since you know so much about the galil and labview, how can I implement Stepper Position Maintenance Moe SPM using labview?

0 Kudos
Message 10 of 13
(3,188 Views)