Date: Feb 4, 2013 4:31 PM
Author: Michael
Subject: Re: matlab serial/fgets doesn't work with non ascii chars

"francesc oller" wrote in message <keo1c4$4ph$1@newscl01ah.mathworks.com>...
> executing the script:
>
> in = serial('/dev/ttyS0', 'BaudRate', 9600, 'DataBits', 8, ...
> 'Parity', 'none', 'StopBits', 1, 'Terminator', 'LF');
> fopen(in);
> line = fgets(in);
>
> and input data 'ñ\n' (hexa C3 B1 0A), fgets hangs and timeouts, i,e, doesn't recognize LF. This only happens when inputting extended non-ascii strings. I'm using Matlab 7.12 R2011a, can somebody test with R2012?. Thanks


Characters in the extended ASCII set are not supported by MATLAB fscanf (and I would presume fgets as well). I spoke with MATHWORKS support earlier this year when I encountered the same issue. There is a feature request from last year about this but the more people that ask for it, the more likely it will be implemented.

You may have better luck using fread instead of fgets but I have not tried that.