Hey guys,
I'm trying to collect data from an engine dyno via serial port, and am having some issues. I have no problem obtaining one line of data using the code below, but I need a continous stream of data.
s = serial('COM3','BaudRate',19200,'DataBits',8, 'StopBits',1,'Terminator','CR/LF')
fopen(s);
fprintf(s,'OD')
fgets(s)
So far my code will return one 1x15 char in the form 'S 7945T0.795R' (S= rpm, T=torque output, R/L=rotation direction. The problem is, using fgets(s), if I try and use it more than once, i get the following error:
Warning: A timeout occurred before the Terminator was reached.
'serial' unable to read any data. For more information on possible reasons, see Serial Read
Warnings.
This means that in order to continue to get data I have to repeat the 'Output Data' command to the dyno, and I only get 1 line of data before timeout. The dyno should output at 60Hz, any ideas on how to get a continous data stream and store it so I can parse out the variables with a different code?
Cheers!
3 Comments
Walter Roberson (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/474642-how-to-store-continuous-serial-data-from-com-port#comment_731334
Clay Robinson (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/474642-how-to-store-continuous-serial-data-from-com-port#comment_732113
Walter Roberson (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/474642-how-to-store-continuous-serial-data-from-com-port#comment_732145
Sign in to comment.