使用Matlab从线性位移台设备等待命令超时 [英] timeout on waiting for command from linear stage device using matlab

查看:137
本文介绍了使用Matlab从线性位移台设备等待命令超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在步进电机控制器的RS485端口与笔记本电脑的COM端口之间建立全双工串行通信.我使用的电缆连接到控制器上的RS485和笔记本电脑上的USB端口.我正在使用Matlab脚本向控制器发送和接收命令,以在导向线性刻度上移动舞台块.虽然我可以打开与设备的串行连接并发送命令以线性扩展位移台,但我无法从控制器接收任何响应消息. 我在Matlab中有以下代码-

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

如果有人指出如何从控制器获取任何消息(这是简单的OK还是我在上面的代码中尝试的版本),这将很有帮助.

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. 电缆超时导致串行通信超时
  2. 从Arduino到Unity的USB通信:超时错误
  1. Serial communication timeout on long cable time out
  2. USB Communication from Arduino to Unity: Timeout Error

推荐答案

您需要从设备文档中确定一些通讯细节.

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

首先,您似乎正在查询设备的版本.确保"@ 00VER"是正确的命令,并且设备是否需要终止符来识别该命令,例如"\ r"?

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.

这篇关于使用Matlab从线性位移台设备等待命令超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆