ฉันกำลังพยายามสื่อสารจาก Simblee Rfduino ไปยัง Matlab ด้วยรหัส Arduino ต่อไปนี้:
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 อ่านจากพอร์ตอนุกรมได้อย่างน่าเชื่อถือหรือไม่? ขอบคุณ!