timeout on waiting for command from linear stage d

2019-08-23 11:27发布

I am trying to establish a full duplex serial communication between the RS485 port of a stepper motor controller and the COM port of my laptop. The cable I use connects to RS485 on the controller and to a USB port on my laptop. I am using a Matlab script to send and receive commands to the controller to move a stage block on a guided linear scale. While I can open the serial connection to the device and send commands to advance the stage block on the linear scale, I am unable to receive any response message from the controller. I have the following code in Matlab -

stage = serial('COM4', 'baudrate', 9600, 'terminator', 'CR');
fopen(stage)

%part below does not work and timeout happens
fprintf(stage,'@00VER')
pause(10)
out = fscanf(stage)

%part below works and I am able to move the block for 5 secs.
fprintf(stage, '@00HSPD=5000');
fprintf(stage, '@00J+');
pause(5);
fprintf(stage, '@00STOP');
pause(5);
fclose(stage)
delete(stage)
clear stage

A timeout happens while script waits for message as shown below -

Warning: Unsuccessful read: A timeout occurred before the Terminator was
reached.. 

out =

  0×0 empty char array

It would help if someone can point out how to get any message from the controller, either a simple OK or the version as I am trying to do in the above code.

I must point out that I referred to following questions but either they did not help or I was unable to connect my problem with the solution given -

  1. Serial communication timeout on long cable time out
  2. USB Communication from Arduino to Unity: Timeout Error

1条回答
迷人小祖宗
2楼-- · 2019-08-23 11:36

There are some details for the communication you need to make sure from the device documentation.

First, it seems you are querying the version of the device. Make sure '@00VER' is the correct command, and does the device need a terminator to recognize the command, like '\r'?

Second, make sure the terminator is needed, and, if so, correct. To debug, you can set up the port using no 'Terminator', and read the port to check what you get.

查看更多
登录 后发表回答