fprintf, the option '%6.4f'', RS232, and ascii Code ( Explanation and help pleas)
4 ビュー (過去 30 日間)
古いコメントを表示
So, It's been 2 month now that I try to send an ascii order to a motor without any succesfull code. But today, I succed to send a stop message to the motor this way :
fprintf(s, '%6.4f','A2')
And it recognise other order, for example, if I send A1 (start engine) it works, if I send A30020 that is for "go to speed 20 km/h" it change the speed, but not in a good way at all, emergency stop used in that case !!!!
So first, can you explain to me this option '%6.4f', I have found example, but no explanation on it And secondly, do you understand why for sending 'A2' it works. If you want more information of the order in ascii I have to send, follow this link, it's the Trackmaster Protocol for treadmill.
Best regards.
Stanislas A
5 件のコメント
Jan
2013 年 2 月 7 日
ASCII communication is not really usual. I still can imagine, that the device communicates with simple bytes, which are explained in HEX format.
回答 (2 件)
Jan
2013 年 1 月 31 日
編集済み: Jan
2013 年 1 月 31 日
The documentation of your device say, that you need:
"A3" plus 4 octects.
Why do you assume that fprintf(s, '%6.4f', 'A30020') does this job?
[EDITED]
The linked documentation says:
"A3" and 4 octets
Actually "A3" looks like a hexdecimal values, such that e.g. this could be sufficient:
fwrite(s, sscanf('%x', 'A3'), 'uint8');
or
fwrite(s, sscanf('%2x', 'A30020'), 'uint8');
(or do we need '%.2x'? Please try this by your own). But this is a pure guess and most likely this will get more clear, when you explain why you have chosen fprintf and '&6.4f'.
10 件のコメント
Jan
2013 年 2 月 7 日
@Stan: Is this the complete documentation? 1 page only and there is only a French version?!
I still got no answer to my question, if fwrite(s, sscanf('A30020', '%2x'), 'uint8') works.
the cyclist
2013 年 1 月 31 日
編集済み: the cyclist
2013 年 1 月 31 日
If you look at the documentation for the command fprintf()
>> doc fprintf
you should be able to find the complete description of what that format specification is. Have you looked at that already, and still feel you don't have a good description?
Depending on what MATLAB version you have, to may have to expand the "formatSpec" section of that doc file.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!