fprintf, the option '%6.4f'', RS232, and ascii Code ( Explanation and help pleas)

4 ビュー (過去 30 日間)
Stan sdsd
Stan sdsd 2013 年 1 月 31 日
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
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.
Stan sdsd
Stan sdsd 2013 年 2 月 7 日
@Cedrid Wannaz : I can't try it today, you will have an answer tomorrow, I will try your code, and give you the fscanf answers. For the terminator, they said to me that it doesn't matter... :(

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

回答 (2 件)

Jan
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
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.
Stan sdsd
Stan sdsd 2013 年 2 月 7 日
編集済み: Stan sdsd 2013 年 2 月 7 日
So sorry, I tried it yesterday, with no succes. And no, just french documentation saddly (and as you can imagine, explanations in it are so BAD :( )

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


the cyclist
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.
  1 件のコメント
Stan sdsd
Stan sdsd 2013 年 1 月 31 日
I Have see this source, but I don't understand, why does it work in my situation ? I mean, I want to send ascii, and I thought fprintf with %s was enough, but it has never work ! and today I try this, and it works for some of my order (like A2 etc...) That's my question : why is it working for sending my ascii order. Anyway, thank you for your answer, I will go check the formatspec. My matlab version is the 7.8.0 R2009a Best regard "the cyclist"

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by