Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial read and write doesn't like second iteration

Hi
 
I am designing a program to control stepper motors. The program uses a modified version of the serial read and write examples.
What the program does is send a signal "I" to the motors which replies with the motors current position. The position is then changed to the next step and written to the motor. The motor is then supposed to reply with "O" meaning the string has been received.
The problem seems to be that the signal "O" from the motor is never returned although the signal is sent to the motor (the motor) does move. On the next iteration of the loop when "I" is sent it recieves the "O" from before which leads to errors.
If I tell the program to not read the second signal (the "O") I still get the same results.
Does anyone know how to fix this problem?
 
Thanks
Nicola
Download All
0 Kudos
Message 1 of 6
(3,933 Views)
Hello Nicola,

I was looking through your code and I have a few suggestions.  The first being adding a small wait between your write command and your read command.  From what you are describing, it sounds like your motor does not have enough time to process the command and reply with it's response, so that the data is waiting to be read the second time you read. 

My second suggestion is to take an NI-Spy capture, to see the low level communication that is going on over the serial port.

Please let me know if you've got further questions,

Meghan R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 6
(3,899 Views)

Hi

I have had another look at the program today (changing it slightly) and have found that it will write and read to the motor twice (with and without a time delay) but the problem seems to be writing the string that was read back to the motors.

What happens is the string is read from the motor, the first integer in the string is then changed to a "O" and this is written to the motor and errors occur. If instead a constant or even a control is attached to the second write the program will work fine.

Is there some "trick" I need to use to feed the string from one to the other?

Thanks

Nicola

0 Kudos
Message 3 of 6
(3,890 Views)

Hi Nicola,

 

Please take an NI-Spy capture, as suggested in the previous post.  It will help us determine what communication is happening and let us be able to troubleshoot more efficiently.

 

Also, as your VI has custom subVIs that I do not have access to, posting your code does not help.  

 

Thank you, 

 

Meghan R

Applications Engineer
National Instruments

0 Kudos
Message 4 of 6
(3,853 Views)

Hi

 

I have attached two NI-spy catures. The first is the program running when the output from the first read is connected to the second write and is when the error occurs. The second is when a constant is input to the second write and no error occurs. It seems that in the first case the number of bytes constantly increases.

 

The second code that I posted contains no custom subVIs and was a simplification of the first.

 

Thanks

 

Nicola

Download All
0 Kudos
Message 5 of 6
(3,842 Views)

Hi Nicola,

 

It looks like your code is working exactly the way you've written it to work.  Either your "replace substing" subVI works differerntly than you expect it to, or your motor is returning information you're not expecting.  Contacting your motor manufacturer should be your next step to verify the operation of the motor.  

 

If you need further help, please contact National Instruments support by going to ni.com/ask and talk to an Applications Engineer.  Make sure you reference this discussion forum thread.

 

Thanks!

 

Meghan R

Applications Engineer

National Instruments

0 Kudos
Message 6 of 6
(3,830 Views)