取消
显示结果 
搜索替代 
您的意思是: 

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 项奖励
1 条消息(共 27 条)
4,957 次查看
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 项奖励
2 条消息(共 27 条)
4,942 次查看
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 项奖励
3 条消息(共 27 条)
4,937 次查看
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 项奖励
4 条消息(共 27 条)
4,936 次查看
Yes, try /n, I think that is that default for Hyperterminal
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 项奖励
5 条消息(共 27 条)
4,936 次查看
One small thing I note that the byte count for the receive is set to Zero, was this intentional?
0 项奖励
6 条消息(共 27 条)
4,925 次查看
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 项奖励
7 条消息(共 27 条)
4,926 次查看
Maybe you could try \r instead of /r.
- tbob

Inventor of the WORM Global
0 项奖励
8 条消息(共 27 条)
4,922 次查看
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 项奖励
9 条消息(共 27 条)
4,904 次查看

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 项奖励
10 条消息(共 27 条)
4,788 次查看