How do I use FPRINTF to send a special character to an instrument with the Instrument Control Toolbox?
20 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 10 Nov 2022
As indicated in the following documentation on FPRINTF:
fprintf (Instrument Control Toolbox)
The calling syntax:
fprintf(obj,'format','cmd')
writes the string 'cmd' to the instrument connected to obj using the format specified by 'format'.
FPRINTF may also be called as in:
fprintf(obj,'cmd')
In this syntax, FPRINTF writes the string 'cmd' directly to the instrument connected to obj.
However, when I execute the following command
fprintf(g2,'FT1<\r\n');
FPRINTF does not transmit my control sequence '\r\n'. Instead it converts then directly to double values. The '\r' sequence is only evaluated to 13 if it is in the format string, but not if it is in a string passed to the format string.
Accepted Answer
MathWorks Support Team
on 10 Nov 2022
Edited: MathWorks Support Team
on 10 Nov 2022
The command
fprintf(g2,'FT1<\r\n');
is actually shorthand for
fprintf(g2, '%s\n', 'FT1<\r\n');
where '%s\n' is the default format string, because it is not explicitly specified.
For the '\r' to be evaluated, you can use
fprintf(g2, '%s\r\n', 'FT1<');
.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!