who i can write more then one value on port?

3 ビュー (過去 30 日間)
husam alrajab
husam alrajab 2019 年 6 月 2 日
編集済み: husam alrajab 2019 年 6 月 2 日
im going to write more than one value on port but it s not working .it s just write tha values as one value.
global a;
a=serial('COM4');
setpoint=str2double(get(handles.s,'string'));
k=str2double(get(handles.k1,'string'));
i=str2double(get(handles.k2,'string'));
d=str2double(get(handles.k3,'string'));
fprintf(a,'%d',setpoint);
fprintf(a,'%d',k);
fprintf(a,'%d',i);
fprintf(a,'%d',d);
  2 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 6 月 2 日
編集済み: Geoff Hayes 2019 年 6 月 2 日
husman - please clarify what you mean by it's not working and it just writes the values as one value. Are you observing an error message? If so, what is it? Else describe where your above code is going wrong. Is it because you convert the strings to doubles? What are the data types for your variables? Do you need to cast these variables to signed integers?
husam alrajab
husam alrajab 2019 年 6 月 2 日
編集済み: husam alrajab 2019 年 6 月 2 日
as you can see it s work but the values is the same for each value it s not write as Parallel
Before run it
after run it

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 6 月 2 日
When you provide your own format to fwrite to serial, then no delimiter is added automatically. CR or LF will not be added between your values when your provide your own format. You need to code in an appropriate delimiter, possibly '%d\n' or '%d ' for the first several and '%d\n' for the last.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 2 日
Where is your fopen(a) ?
husam alrajab
husam alrajab 2019 年 6 月 2 日
編集済み: husam alrajab 2019 年 6 月 2 日
It's in another section . i make it in first press the Contact button in that button there is definition of serial and open the serial .
Before run it
after run it

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by