LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can one write text commands to a usb device through VISA?

The Serial Write contains an "Open Serial Driver" and a "Visa WRITE":
the first opens the connection and sends directly the "refnum" to the
Visa WRITE. Could be also this a difference among your tentatives?
Maybe you always have to force an Open before a Write ....

Bye

0 Kudos
Message 11 of 25
(3,275 Views)
Hi Warren; With regard to the "Get" and Set Stuff" reference; When I send a cmmd to the device, the port monitor shows
the following typical statements:
 
IOCTL_SERIAL_GET BAUD RATE
IOCTL_SERIAL_GET LINE CONTROL
IOCTL_SERIAL-GET CHARS
IOCTL_SERIAL_GET HANDFLOW
IOCTL_SERIAL_SET BAUD RATE
IOCTL_SERIAL_SET RTS
And so forth till a "IRP_MJ_WRITE Request is made.
 
Since Hyperterminal did not send these request and the device was responding, I was thinking that the request could possibly be left off for simplification. I haven't had time to make the changes you recommended but I will. I appreciate your help and patience.
0 Kudos
Message 12 of 25
(3,269 Views)
The stepper motor controller is an ALLMotion EZ17.
0 Kudos
Message 13 of 25
(3,264 Views)


@GeeWhiz wrote:
Hi Warren; With regard to the "Get" and Set Stuff" reference; When I send a cmmd to the device, the port monitor shows
the following typical statements:
 
IOCTL_SERIAL_GET BAUD RATE
IOCTL_SERIAL_GET LINE CONTROL
IOCTL_SERIAL-GET CHARS
IOCTL_SERIAL_GET HANDFLOW
IOCTL_SERIAL_SET BAUD RATE
IOCTL_SERIAL_SET RTS
And so forth till a "IRP_MJ_WRITE Request is made.
 
Since Hyperterminal did not send these request and the device was responding, I was thinking that the request could possibly be left off for simplification. I haven't had time to make the changes you recommended but I will. I appreciate your help and patience.


You are busy on device driver level with your portmon program. That is something rather low level. As you can get from the names of the device driver IOCTLs they are all abut parameters for the serial port. The serial port has to be initialized properly in order to communicate with your device.

Hyperterminal usually does this at the moment it is started up and you select your connection after which the connection is open and Hyperterminal only does read and write commands anymore. Maybe Hyperterminal has some optimization too, that leaves out serial port initilialization if the parameters are the same as the default one. Would seem to me a rather useless optimization but who knows.

Rolf Kalbermatter


Rolf Kalbermatter
My Blog
0 Kudos
Message 14 of 25
(3,263 Views)


@GeeWhiz wrote:
Hi Warren; With regard to the "Get" and Set Stuff" reference; When I send a cmmd to the device, the port monitor shows
the following typical statements:
 
IOCTL_SERIAL_GET BAUD RATE
IOCTL_SERIAL_GET LINE CONTROL
IOCTL_SERIAL-GET CHARS
IOCTL_SERIAL_GET HANDFLOW
IOCTL_SERIAL_SET BAUD RATE
IOCTL_SERIAL_SET RTS
And so forth till a "IRP_MJ_WRITE Request is made.
 
Since Hyperterminal did not send these request and the device was responding, I was thinking that the request could possibly be left off for simplification. I haven't had time to make the changes you recommended but I will. I appreciate your help and patience.


Most of us never use Portmon to see this level of detail and we don't care about it and it doesn't hurt us either. But since we are here anyway this may be an indication of a flaw in your VI or it may be just a side effect of how you are running your VI. I have not seen the VI that you are using so I can only speculate here.
 
  • If your VI consists of only a "VISA Configure Serial Port" function followed by a "VISA Write" that gets the string to write from a front-panel control
    and
  • if the way you use it is to load a string into the control and then click the run button,
    then
  • I think this portmon exchange is reasonable.

The VI is doing exactly what you have programmed, every time you click the run button it is configuring the serial port and then sending the string. Turn on execution highlighting and watch it. The VI won't skip over the Configure step the second time you run it if you have not built the VI such that it keeps track of how many times you run it and knows to skip the Configure step for later runs.

 
If your VI consists of an event-driven while loop containing a "VISA Configure Serial Port" function followed by a "VISA Write"  and every time you update the front-panel string to write, the event fires which then executes the Configure followed by the Write and a loop back to wait for the next event  then the VI is again doing exactly what you have programmed. The flaw here is that the Configuration really does belong outside the while loop so that you get the configure once followed by multiple writes.
 
It would really help if you would show us what you are doing (post your VI or a picture of it) and tell us what you are ultimately trying to accomplish. Do you just want to be able to enter commands from a front panel of the VI and have them executed? Why not stick with Hyperterm then?
Or is this going to be part of some much bigger system that will automatically generate and send out all sorts of commands?
 

@GeeWhiz wrote:
The stepper motor controller is an ALLMotion EZ17.

So it looks like the manual is available from here in general and here specifically.
 
Just to summarize what I see at a quick glance:
  • all commands start with a "/" character followed by an address number
  • all commands end with a carriage return character <CR> (hex 0A)
  • responses will begin with "/0" where "0" is the master controller address (your PC)
  • responses will end with <ETX> <CR> <LF> in that order.
    (so when you get around to trying to read from this thing you will want to terminate the read on the <LF> character)
 

 
Message 15 of 25
(3,249 Views)

I am now successfully using the "Basic Serial Write and Read VI" from NI to command the motor to position. This was accomplished by just terminating the String to Write properly with a "\r" which is consistent with your recommendations.The vi has the "VISA Configure Serial Port" function followed by the "VISA Write" and "String to Write" (both inside Case Structure). There are no "While Loops" in the VI. I still get the error message -1073807298, Hex 0xBFFF003E, when I run the VI but the device responds properly to positioning commands. However, commands that asks for responses are not read. An example is /1?8\r is a request to return the stepper motor position. While I get a response from Hyperterminal with this command, I dont see a response with LabView.

I turned on the execution highlighting and stepped the through the vi. The error message -1073807298 shows up on the output ot the VISA Write function and is carried all the way through.

Driving the stepper motor is part of a bigger project in which I will be driving LED's, taking analog voltages, and performing analyses of data. If I can figure out how to post an image, I will. 

0 Kudos
Message 16 of 25
(3,238 Views)

GeeWhiz wrote:
I am now successfully using the "Basic Serial Write and Read VI" from NI to command the motor to position. This was accomplished by just terminating the String to Write properly with a "\r" which is consistent with your recommendations.

Good.


I still get the error message -1073807298, Hex 0xBFFF003E, when I run the VI but the device responds properly to positioning commands.

The message associated with that error number is "-1073807298 VISA: (Hex 0xBFFF003E) Could not perform operation because of I/O error." 
At this point I don't know why you are getting it.


However, commands that asks for responses are not read. An example is /1?8\r is a request to return the stepper motor position. While I get a response from Hyperterminal with this command, I dont see a response with LabView.

Usually to successfully read responses you need to customize the reading routine to the message format which you are expecting. That is why I pointed out in my previous message that the last character of every message that the EZ17 will send to the PC is terminated by a linefeed character. That makes reading easy. You just tell VISA to hold all characters until it gets a linefeed and then, when it finally does get one, return all characters it has collected up to and including the linefeed. See if the attached VI set (LV v7.1.1) will allow you to send commands and read responses.


 If I can figure out how to post an image, I will. 

Not the easiest process but here how you can post an image.

  1. Capture an image - If you are using a PC, pressing the "PrtScn" (Print Screen) key (usually near F12 along the top of the keyboard) will capture a bitmap to the clipboard of the entire Windows desktop. If you hold down the "Alt" key when pressing PrtScn, then you will capture a bitmap of the current active window.
  2. Open an image editing program and past the clipboard image into it. Crop it as desired.
  3. Save the image to a JPG, GIF or (my favorite) PNG file.
  4. When posting to this forum, browse to the image file and add it as an attachment.
    You can stop here if you do not want to have a thumbnail version of the image appear in the posting.
  5. If you want to include a thumbnail of the image in the posting, then finish editing the text of the posting and get the posting spell-checked and looking like you want it to look without the thumbnail image (note that due to a bug in the forum system software, if you choose to preview the message then you will need to re-add your image attachment that was added in the previous step) 
  6. Submit the Post
  7. View the submitted post and select the now-visible hyperlink to the now-attached image and copy the hyperlink to the clipboard.
  8. Within 5(?) minutes of submitting the posting, choose to re-edit the post (if you wait too long, you will lose the option to re-edit).
  9. Click in the message edit window where you want the image to appear.
  10. Click on the "Insert an Image" button above the edit window and paste the hyperlink to the image into the box that appears.
  11. Resubmit the post. The image should be visible as a thumbnail.

Feel free to post the VI(s) instead of images if that is easier for you; it can be easier for those of us trying to do the debugging from afar...

Message Edited by Warren Massey on 03-08-2006 08:20 AM

Message 17 of 25
(3,222 Views)
Hi Warren; Thanks for sending me the vi's to try. I have been trying to run the "VISA Serial Send Message" and the "VISA Send Commands and Check Responses" vi's. I have not got any response from the stepper motor. I am still getting the same error responses that I have previously posted. (the -1073807298) Should the "Send Message" sub-vi run by itself? When I run it, I see on the port monitor the first command character intermingled with "Get Com Status" and "Flush Buffer". Hold on! I just discovered that is the case when the "Intercharacter Delay" is set to 1 ms. and the retry count is set to 1. When I set the "Intercharacter Delay" back to zero with the retry at "1", Portmon does see the entire command set, as entered, but the stepper motor does not respond. Is that because with this sub-vi there is no way to set Baud Rate, Stop Bits etc. It does allow setting the comm port.  
0 Kudos
Message 18 of 25
(3,187 Views)


@GeeWhiz wrote:
Hi Warren; Thanks for sending me the vi's to try. I have been trying to run the "VISA Serial Send Message" and the "VISA Send Commands and Check Responses" vi's. I have not got any response from the stepper motor. I am still getting the same error responses that I have previously posted. (the -1073807298) Should the "Send Message" sub-vi run by itself? When I run it, I see on the port monitor the first command character intermingled with "Get Com Status" and "Flush Buffer". Hold on! I just discovered that is the case when the "Intercharacter Delay" is set to 1 ms. and the retry count is set to 1. When I set the "Intercharacter Delay" back to zero with the retry at "1", Portmon does see the entire command set, as entered, but the stepper motor does not respond. Is that because with this sub-vi there is no way to set Baud Rate, Stop Bits etc. It does allow setting the comm port.  


The 138kb zip file I posted a couple of messages back has "VISA Send Commands & Check Responses.vi" as a top-level VI. That is the file you should be running. It is a complete demonstration communication program. On its block diagram it does have a way for you to specify the comm port as well as the baud rate and so forth off to the left side.

The "Send Message" vi should not normally be run by itself. But, with that said, if you don't do anything to close the serial port then you can configure a port with one VI and then subsequently run another VI like Send Message to transmit information out the port, but the usual way is to build it all into a program that handles it all in an ordered sequence like the program I provided.

0 Kudos
Message 19 of 25
(3,179 Views)
Thanks for everyone's help. Everything is working great now. I am writing commands to the stepper motor (through the USB) that are acted upon and I am able to read the devices' responses. Using the proper termination character (\r) allowed the Write string to be read and the stepper motor to respond. The Read problem was caused by the error message that was generated at the VISA Write vi. With the VISA Read vi downstream, the error kept the Read vi from functioning. A Clear Errors vi was installed in the next sequence after the VISA Write  and that enabled the downstream Read vi to function properly. This is a great forum.
0 Kudos
Message 20 of 25
(3,156 Views)