write関数が未定義となることについて
조회 수: 7 (최근 30일)
이전 댓글 표시
ArduinoとMATLAB間でシリアル通信を行うMATLABのプログラムでwrite関数を用いようとしているのですが「関数 'write' (タイプ'serial' の入力引数) が未定義です。」とエラーが出てしまいます。
これの解決方法が分からないので教えてください。
下記がMATLABコードです。
s = serial('COM7', 'BaudRate', 9600, 'Terminator', 'CR', 'StopBit', 1, 'Parity', 'None');
fopen(s);
a=1;
t=1;
N=30;
out = zeros(2,N);
while(1)
if (t<=N)
write(s,1);
fprintf(s,'1');
out(1,:) = str2double(fscanf(s));
s.BytesAvailable;
write(s,2);
fprintf(s,'2');
out(2,:) = str2double(fscanf(s));
s.BytesAvailable;
else
fclose(s);
delete(s);
clear s
break;
end
t = t+1;
end
t=1:1:30;
figure
plot(t,out(1,N),'-.')
hold on
plot(t,out(2,N),'-.')
hold on
댓글 수: 0
답변 (1개)
Takafumi
2020년 6월 22일
手元にArduino が無いので確かめられませんが、
MATLABでは、serial 関数から、serialport 関数への移行をしております。
serial 関数で押す場合は、fwrite を使います。
serial を serialport 関数への変更か
write を fwrite に変更するか、
検討してみてください。
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 シリアル ポート デバイス에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!