How do I write to move the line in sending serial?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
[EDIT: 20110616 09:33 CDT - reformat - WDR]
I want to send serial data using the CR (Cariage Return) I've tried to change the terminator to CR but still belom succeed. I sent this data later to SSC-32 (Servo Motor Driver).
clc; disp('BEGIN')
Serial = serial('COM5');
set(Serial,'Terminator','CR');
set(Serial,'BaudRate',115200);
set(Serial,'DataBits',8);
set(Serial,'Parity','none');
set(Serial,'StopBits',1);
set(Serial,'FlowControl','none');
fopen(Serial);
get(Serial);
%sending data
fprintf(Serial,'%s\n','#1 P1500 T1000');pause(0.2);
fprintf(Serial,'%s\n', '#2 P1500 T1000');pause(0.2);
%close the serial
fclose(serial);
delete(Serial)
clear Serial
disp('STOP')
is not successful,. data I can not send new line breaks. so the servo can not move.
Thanks for help
0 comentarios
Respuestas (3)
Jan
el 16 de Jun. de 2011
This defines CR = CHAR(13) as terminator:
set(Serial,'Terminator','CR');
But:
fprintf(Serial, '%s\n', ...);
Writes \n = LF = CHAR(10) as line break. So either use this:
set(Serial, 'Terminator', 'LF');
or this:
fprintf(Serial, '%s\r', ...);
which is equivalent to
fprintf(Serial, ['%s', char(13)], ...);
2 comentarios
Chirag Gupta
el 16 de Jun. de 2011
Actually the <http://www.mathworks.com/help/techdoc/matlab_external/f62852.html#br8pqg6-1 documentation> does mention that \n will be interpreted as the Terminator property, so it is strange.
Chirag Gupta
el 16 de Jun. de 2011
Can you also try to send the carriage return directly:
fprintf(serial,'%s\r',...);
Also can you check with a serial monitor that the correct data is being sent out. (You are getting a CR (13) for terminator).
0 comentarios
Ankit Desai
el 29 de Jun. de 2011
When using serial object (and any Instrument Control Toolbox object) using fprintf will automatically append the 'Terminator' character.
So you can avoid appending \n to your command string once you setup your terminator property. For the example above, the following should work:
fprintf(Serial,'#1 P1500 T1000');
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!