【发布时间】:2019-05-28 15:45:13
【问题描述】:
我正在尝试使用以下 Arduino 代码从我的 Simblee Rfduino 与 Matlab 进行通信:
char testing[] = {1,2,3,4,5,6,7,8,'\0'};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(6,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(6,LOW);
Serial.flush();
testing(EMG);
Serial.flush();
digitalWrite(6,HIGH);
}
在 Python 中,我能够以正确的顺序一致地正确读取 1-8。
但是在 Matlab 中,它不断地改变顺序,没有一致性,代码如下:
function serial()
global ser
ser = serial('COM5', 'BaudRate', 9600, 'FlowControl', 'hardware');
fopen(ser);
end
function serial_callback(~, ~)
global ser
time = tic;
fread(ser,1) % pull in data from serial port
toc(time);
end
我认为串行缓冲区中可能存在一些问题。 您能否就如何始终如一地让 Matlab 按顺序读取数据提供一些指导?其他人是否能够让 Matlab 可靠地从串行端口读取? 谢谢!
【问题讨论】:
标签: matlab serial-port