LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from Serial Port

Hi just having some issues with reading from serial port.

I'm controlling a computerized linear stage by Labview via serial port. I'm moving the stage and would like to know if the stage is in its destination before taking measurements.

The stage has a command that can do this... ie 1R(IP)  - basically read axis 1 and see if the axis is in position.

If you type this command in Hyperterminal you get either 1 (in position) or 0.

So I'm trying to write 1R(IP)/r into the serial port and then read the serial port. For some reason the string I'm getting back is exactly 1R(IP)/r. What am I doing wrong?

Thanx for the help.


0 Kudos
Message 1 of 27
(4,491 Views)
Are you sure the terminator character is correct, it could be that its returning the command as the terminator is different / implied, than that used when in Hyperterminal.
0 Kudos
Message 2 of 27
(4,476 Views)
In addition to verifying correct termination char, you may to to add a delay of a few 10's of msecs between write and read functions.
Were you able to command it to move successfully?
Is this an Animatics motor?
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 3 of 27
(4,471 Views)
To move the stage I would input command like:

1D12000/r
1G/r

1D -> specifies the distance I want to move
1G -> Go command

Maybe I should try /n?


0 Kudos
Message 4 of 27
(4,470 Views)
Yes, try /n, I think that is that default for Hyperterminal
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 5 of 27
(4,470 Views)
One small thing I note that the byte count for the receive is set to Zero, was this intentional?
0 Kudos
Message 6 of 27
(4,459 Views)
Just try having a short delay and using /n.

With a short delay only (using /r) the serial read still gives me what I write in. 😞

Using /n the program just gets stuck on 'run.'

What's going on? :S

On byte count -> Right now I'm just manually changing that when the program is running.

Message Edited by Honeywell on 08-17-2005 02:16 PM

0 Kudos
Message 7 of 27
(4,460 Views)
Maybe you could try \r instead of /r.
- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 27
(4,456 Views)
Oops my mistake. I've been using \r the whole time, not /r.


Tried both \r and \n as well as waited for putting a delay. No good.

I still read 1R(IP) from the serial port.
0 Kudos
Message 9 of 27
(4,438 Views)

Hi Honeywell!
One source of your problem may be an echo setting on your instrument.  If this is enabled, getting back what you sent is expected.  This is exactly what a loopback test does as well.  Is there any way that a loopback pin setup could be in place?  You can see information about the loopback test at this link.  Try sending an obviously incorrect command like random characters to see if you get that exact line back.  If you do, an echo or loopback configuration is probably the case.  I was able to run your program with my NI Instrument Simulator.  All I changed was the command that is being sent and it worked fine for both X and Y positions on your boolean switch.  Check to make sure that the command you are sending is formatted correctly and try other commands with your instrument and see if you get similar behavior.  Are you getting any errors?  Has this program/instrument combination worked before?  I hope this helps, but let me know if you have any additional questions!

Chris R.
Applications Engineer
National Instruments

 
Chris R.
Applications Engineer
National Instruments
0 Kudos
Message 10 of 27
(4,322 Views)