Discussion:
Serial read and write doesn't like second iteration
(too old to reply)
Nic04
2008-08-12 03:40:06 UTC
Permalink
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


test5.jpg:
Loading Image...


test45.vi:
http://forums.ni.com/attachments/ni/140/31518/2/test45.vi
Meghan R
2008-08-12 19:40:11 UTC
Permalink
Hello Nicola, I was looking through your code and I have a few suggestions.&nbsp; The first being adding a small wait between your write command and your read command.&nbsp; 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.&nbsp; My second suggestion is to take an<a href="http://digital.ni.com/public.nsf/allkb/8D890EC09B15C05A86256E6F007E3E86?OpenDocument" target="_blank"> NI-Spy capture</a>, 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 EngineerNational Instruments
Nic04
2008-08-13 05:10:09 UTC
Permalink
Hi
I have had another look at the program today (changing it slightly)&nbsp;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,&nbsp;the first integer in the string is then&nbsp;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


test45.vi:
http://forums.ni.com/attachments/ni/140/31536/1/test45.vi
Meghan R
2008-08-14 18:40:12 UTC
Permalink
Hi Nicola, &nbsp;Please take an NI-Spy capture, as suggested in the previous post.&nbsp; It will help us determine what communication is happening and let us be able to troubleshoot more efficiently.&nbsp;Also, as your VI has custom subVIs that I do not have access to, posting your code does not help. &nbsp; &nbsp;Thank you,&nbsp;&nbsp;Meghan RApplications Engineer
National Instruments
Nic04
2008-08-15 03:40:09 UTC
Permalink
Hi&nbsp;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.&nbsp;The second code that I posted contains no custom subVIs and was a simplification of the first.&nbsp;Thanks&nbsp;Nicola


Capture1.spy:
http://forums.ni.com/ni/attachments/ni/140/31574/1/Capture1.spy


Capture2.spy:
http://forums.ni.com/ni/attachments/ni/140/31574/2/Capture2.spy
Meghan R
2008-08-15 21:10:11 UTC
Permalink
Hi Nicola, &nbsp;It looks like your code is working exactly the way you've written it to work.&nbsp; Either your &quot;replace substing&quot; subVI works differerntly than you expect it to, or your motor is returning information you're not expecting.&nbsp; Contacting your motor manufacturer should be your next step to verify the operation of the motor. &nbsp; &nbsp;If you need further help, please contact National Instruments support by going to <a href="http://sine.ni.com/apps/utf8/niae_asc.main" target="_blank">ni.com/ask</a> and talk to an Applications Engineer.&nbsp; Make sure you reference this discussion forum thread. &nbsp;Thanks!&nbsp;Meghan RApplications EngineerNational Instruments
Continue reading on narkive:
Loading...