Isra
Isra

Reputation: 155

Reading the remaining content of the serial buffer Matlab

I have a program that involves continuous reading of the serial port and then doing some processing. Due to the processing, I have some delay in reading the values (I read line by line). Once the user presses stop, the reading stops and I wan't to make sure that the buffer is fully read. I know that there will be some data in the buffer and I don't want to loose it once the comport is closed. is there a way to read the content of the whole buffer at once?

I tried fscanf(comport) but it only read one element.

I know fread reads the whole buffer, but I don't know how to convert the binary to string and get my useful data.

Thanks

Upvotes: 1

Views: 324

Answers (1)

Xiangrui Li
Xiangrui Li

Reputation: 2426

If you can read all by fread, then it is just a matter of formatting. You could fread all as number, and convert to char:

u8 = fread(comport, comport.BytesAvailable); % uchar, but in double 
ch = char(u8);

This should give you all in buffer as string.

Upvotes: 0

Related Questions