我很难从我的望远镜得到返回值。我已经能够向它发送数据,并且我正在使用fscanf来获取返回值--这是我的代码。
close all; clear all; clc;
priorPorts = instrfind; % finds any existing Serial Ports in MATLAB
delete(priorPorts); % and deletes them
COMnum = input('COM Number:');
telescope = serial(['COM',num2str(COMnum)]);
set(telescope,'BaudRate',9600);
set(telescope,'Terminator','#'); %theres a pound symbol at the end of all commands
fopen(telescope);
fprintf(telescope,'h');
out = fscanf(telescope,'%c',512);
当我运行这个输出时,返回的是我无法解释的字符串(如“9”)。预期的反应是:
chr(Q) &
chr(R) &
chr(S) &
chr(T) &
chr(U) &
chr(V) &
chr(W) &
chr(X) &
"#”
其中Q,R,S,T,U,V,W,X都是整数,"#“是终止子。同样,当我输入一个返回char(整数)& "#“的命令时,它返回空格和"#”终止符。注意:当返回值只是一串文本时,这个程序就可以工作了,我尝试过:
下面是我一直在使用http://www.nexstarsite.com/PCControl/ProgrammingNexStar.htm的一些资源,特别是coms协议文档,这是顶部的第一个链接。任何和所有的帮助都是感激的。谢谢!
发布于 2015-02-01 23:37:42
使用fscanf,然后键入强制转换为双面,如
out = fscanf(s);
out = double(out);
https://stackoverflow.com/questions/28269760
复制相似问题