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

4 views (last 30 days)
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 Comments
Jan
Jan on 7 Feb 2013
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 on 7 Feb 2013
@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... :(

Sign in to comment.

Answers (2)

Jan
Jan on 31 Jan 2013
Edited: Jan on 31 Jan 2013
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 Comments
Jan
Jan on 7 Feb 2013
@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 on 7 Feb 2013
Edited: Stan sdsd on 7 Feb 2013
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 :( )

Sign in to comment.


the cyclist
the cyclist on 31 Jan 2013
Edited: the cyclist on 31 Jan 2013
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 Comment
Stan sdsd
Stan sdsd on 31 Jan 2013
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"

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!