Borrar filtros
Borrar filtros

RS232 with MATLAB: Doesn't send what I want

1 visualización (últimos 30 días)
Julia
Julia el 30 de Oct. de 2014
Comentada: Julia el 30 de Oct. de 2014
Hello everyone! I am using Matlab to communicate with a device on a RS232 connexion. My code is quite simple: I first open the correct COM port: obj=serial('COM3','BaudRate',9600); fopen(obj);
And send I send various ASCII commands. For example: fprintf(obj,'%s\n',[char(hex2dec('A1'))])
I have a sniffer on the RS232 port, so I can make sure I am sending the right command. in this case 'A1'.
However, sometimes when I try to send '8B' it sends '3F' instead (shown by the sniffer): fprintf(obj,'%s\n',[char(hex2dec('8B'))])
This is bizarre, because sometimes it works perfectly fine and for some ASCII characters, it doesn't work!
Do you know why this happens? And what can I do to avoid this? Are there other alternatives to communicate on RS232 serial port with MATLAB?
Thank you in advance for your response and your time!
  1 comentario
Julia
Julia el 30 de Oct. de 2014
ok so I understood something. When the characters I send are larger than 127 (so when the 8th bit is a 1: ex. 10000000 and larger), Matlab doesn't send the right number. This is why everything worked well for most of the characters, but as soon as I send a value larger than 127 (80 in hex) it didn't work properly.
Does someone know how I can avoid this? I guess Matlab considers the 8th bit as a sign or something...
Thank you!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by