MATLAB: False serial read (ASCII: 26)

incorrect readingreadserial

Hello together,
I`m currently working with a serial deviceand Matlab R2018b. I can send comands with fwrite and the answer is from the serial device is correct. I read with fscanf and use the unicode2native function, So far so good. The terminator of my sended data is 254, what cannot be used with Matlab. So I set the input buffer to size 1 and save the byte to a variable. When I combine different bytes to one actual frame I do some calculations and writing to a file. Most of the the time everything works.
Unfortunately at some places the CRC that the device sends does not match the CRC calculated from the bytes. It is noticeable that the byte '26' (ASCII: Substitute) occurs in each of these supposedly erroneous frames. I have already checked the actual sended bytes with HTerm and they are all correct (no '26')
Does anyone have any idea why Matlab reads '26' instead of the actual sended bytes?
Thanks for your answer!

Best Answer

unicode2native puts in a 26 if the unicode code point does not exist in the destination character set.
It can get tricky if the source values happen to be in a range devoted to surrogate pairs.