12-06-2013 02:15 PM
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
12-06-2013 02:47 PM
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?
12-06-2013 03:01 PM - edited 12-06-2013 03:02 PM
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.
12-07-2013 10:25 AM
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.
12-07-2013 01:41 PM
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:
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.
12-11-2013 09:56 AM - edited 12-11-2013 10:16 AM
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.
12-11-2013 10:14 AM - edited 12-11-2013 10:18 AM
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.
12-11-2013 10:19 AM - edited 12-11-2013 10:26 AM
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.
12-11-2013 10:49 AM
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.
12-17-2013 02:30 PM
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?