How can I take the datas from comport?

1 回表示 (過去 30 日間)
bayram özmen
bayram özmen 2018 年 5 月 2 日
編集済み: Ameer Hamza 2018 年 5 月 3 日
I have a code in ardunuio. Also this is just an example. that code will write the datas to comport. I want to read the integer datas. So ı am trying to read U firstly and then ı am starting to take integer data but ı could not take. How can I take like that?
comport = serial('COM3','BaudRate',9600);
fopen(comport);
for i=1:100
angles=fscanf(comport);
if(angles=='U')
phi=fscanf(comport,'d');
theta=fscanf(comport,'d');
end
end
fclose(comport);
delete(comport);

回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 5 月 2 日
編集済み: Ameer Hamza 2018 年 5 月 3 日
Instead of fscanf(), try using
oneByte = fread(comport, 1);
this will read one value from the serial buffer. Also, you should note that since you are using Serial.println, the Arduino will also send newline character (value 10 in ASCII).

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by