LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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

I have a stepper motor controller that I can command through Hyperterminal and the USB with commands like /1A1000R<enter>. This command causes the stepper motor to move to position 1000. Everything works well with Hyperterminal. When I try to get LV to do a similar operation with MAX or Basic Write and Read.vi, there is no response from the controller or stepper motor. I have port monitor software looking at the USB port. When HyperTerminal is used, Portmon displays the proper cmmds in Hex. Looking at the port when using LV, it appears that LV is asking the controller for things like no. of bits, stop bits, flow control, etc. with no response from the controller. Can anyone help? I'm fairly new to LabView but I'm taking LV Basic Courses 1 and 2 next week. All responses appreciated.
0 Kudos
Message 1 of 25
(6,453 Views)

Easiest way is to buy a GPIB-USB converter $500.00 from NI.

Unless you don't have a GPIB control card.

0 Kudos
Message 2 of 25
(6,442 Views)
It would be silly to buy a GPIB controller for a serial instrument.Smiley Wink
 
GeeWhiz,
 
Are you sure that you are sending the correct termination character for the instrument? When you hit the enter key in Hyperterminal, it sends a CR/LF. In the Basic Serial Write and Read, when you first opened it up, the default string is "*IDN?\r\n". The \r\n are the control codes for CR/LF. Include those with your commands and see if anything works.
Message 3 of 25
(6,440 Views)
Thanks for your responses. Dennis When I key an "enter" at the end of a command string (in HyperTerminal),
a Hex 0D is sent to the device. I then get a read statement from the device that ends in 0A.
0 Kudos
Message 4 of 25
(6,412 Views)
Dennis; I just noticed I didn't respond fully to your reply; O haven't done the \r\n thing but I will. Thanks again.
0 Kudos
Message 5 of 25
(6,404 Views)
So far, writting \r\n at the end of the string hasn't worked for me. However, I am learning some things. I copied the Serial Write.vi from the NI website and opened it. Using this vi, If I type the commands in Hex and run the vi, the stepper motor responds properly. However, before I did this, I had changed the "display style" to "Hexadecimal". Is it the "Normal Style" that allows one to type the commands in with characters like /1A1000R<enter>? I have tried running the Basic Write and Read VI by typing in Hex characters and it didn't work for me.
0 Kudos
Message 6 of 25
(6,400 Views)


@GeeWhiz wrote:
So far, writting \r\n at the end of the string hasn't worked for me. However, I am learning some things. I copied the Serial Write.vi from the NI website and opened it. Using this vi, If I type the commands in Hex and run the vi, the stepper motor responds properly. However, before I did this, I had changed the "display style" to "Hexadecimal". Is it the "Normal Style" that allows one to type the commands in with characters like /1A1000R? I have tried running the Basic Write and Read VI by typing in Hex characters and it didn't work for me.

Not sure about Hyperterminal but in most other environments I know character escaping is done with \ and not /. And LabVIEW has a special display style for this " '\' Codes Display ". Basically it shows all normal ASCI characters as is but displays non printable characters with their ASCI code or an abbreviation of it and a preceding \ character. Also it allows to enter a two digit hex code after the \ code for the ASCI code. Normal code only shows the printable characters and empty space for anything else. Hex Display converts every character into a two digit hex code.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
Message 7 of 25
(6,385 Views)
It is not very hard, once you determine what correct termination character is required for your commands to automatically add it to every command you send out over the serial link.
 
That way you don't have to worry about whether or not LabVIEW is interpreting the press of the "enter" key as just another character to include in the string (it usually does not do this) or else if it is a signal to LabVIEW that you are done entering the string and it is now free to process it (this is the usual interpretation).
 
It also removes the worry about what character LabVIEW actually adds to the string if you manage to get it into the  mode where it treats the enter key as an ordinary key. LabVIEW normally adds a "newline" character which is LabVIEW-speak for a linefeed character. If your command actually needs a carriage return, then treating the enter key as an ordinary key won't get you what you need anyway.
 
The concatenation is easy to do and it will allow you to enter your command strings as normal ASCII text (no more hex codes) since the invisible termination characters are automatically added and appear as constants on the block diagram.

Message Edited by Warren Massey on 03-05-2006 01:01 PM

Message 8 of 25
(6,377 Views)
I now believe I understand what is needed. But I'll pass along a little more info so you will see exactly what I am trying to accomplish, my stepper motor controller/driver provided a "Command Set and Communication protoco". An example command is: /1A1000R<CR>. The "/" is the start character; the "1" is the device address; "A" tells the controller to send the stepper motor to the absolute position 10000; "R" tells it to run the command that is received; and" <CR> is a carriage return that tells  the stepper that the command string is complete and should be parsed." One more question that i wish you will answer for me is; Does LabView have to send out all the lines of open, set and get stuff before it sends the commands the device needs? The stepper controller apparently ignores all of tis until it gets to the commands it wants. Thank you so much for providing such helpful information.
0 Kudos
Message 9 of 25
(6,369 Views)


@GeeWhiz wrote:
One more question that i wish you will answer for me is; Does LabView have to send out all the lines of open, set and get stuff before it sends the commands the device needs? The stepper controller apparently ignores all of tis until it gets to the commands it wants.


I don't follow what you mean by "open, set and get stuff". Might you be talking about VISA Open, VISA Write & VISA Read?

If so, then the VISA Open does come first to configure the serial communications parameters like baud rate and so forth.

After the serial channel is properly configured, you should be able to make a call to the VISA Write function and have a command sent to the device immediately. If the command was properly formatted for the device, then the device should act on it immediately.

In situations like this it's not unusual to follow a VISA Write of a command with a VISA Read of a response to see what the motion controller thought of the command. The format of the response depends on whose controller you are using but typically you get one message if it liked the command and another if it didn't.

Assuming the motion controller liked the command, there's no reason you couldn't immediately loop back to the VISA Write function and send out another command. Usually the controller recognizes some commands as ones it should act on immediately (like STOP!!!) and others it may just buffer until it finishes whatever it is currently doing.

Tell us the make and model number of the controller you are using and we may be able to provide more specific help. A pointer to a PDF manual would be nice.

If you mean something else by the "open, set and get stuff" reference, try again with the explanation. It would also be useful if you could post a VI (or a picture of your block diagram) along with a description of what you intended it to be doing.

0 Kudos
Message 10 of 25
(6,361 Views)