0

I used pyserial to control a uart, hardware is Odroid and OS is ubuntu 14.04, and there are something wrong happend:

>>> import serial
>>> s = serial.Serial("/dev/ttyUSB1", 115200)
>>> s.readline()
'$GPNTR,054626.40,0,0.000,+0.000,+0.000,+0.000,*41\r\n'
>>> s.close()
>>> s = serial.Serial("/dev/ttyUSB1", 115200)
>>> s.readline()
'\x7f\x84)\x95\x02\x84a\xfd\x021\x95\n'
>>> s.close()

But after using minicom to open the port, this port will return to normal, and if i run the code, mistakes will happen again.

Thank.
Tianyu.

dtysky
  • 1
  • 1
  • You should probably tell us what is wrong, rather than something is wrong. Also check the other serial params minicom is setting when you use it, ie bits, stop bits, etc... and match those with python. Minicom could also be reading more than a line, so draining any buffers (implying possible flow control). – Tim Hoffman Dec 20 '15 at 07:29
  • As shown in the code, at the first time i open a port, then i can read the right data, but if i close it and re-open, wrong data will be returned by "read" function. I have already do lots of tests in Odroid(ubuntu) and PC(windons), only in odroid this mistake will be happended. I only setting the baudrate and port. – dtysky Dec 20 '15 at 07:42
  • ok, but minicom by default often sets quite a few other serial params. Check what is it doing. Also look at how you exit form mincom, is the exit resetting the port for instance ? – Tim Hoffman Dec 20 '15 at 08:07
  • emm...i checked and found the minicom has the same settings as my code...i used ctrl&a + q to exit the minicom... – dtysky Dec 20 '15 at 08:40
  • ............ if i do these, all will be ok: open port with baudrate 115200 -> close -> open with 57600 -> close -> open with 115200, but i don't know why... – dtysky Dec 20 '15 at 08:56
  • 1
    Check the state of the port before and after opening using stty -a -F /dev/ttyUSB1 – Tim Hoffman Dec 20 '15 at 09:00

0 Answers0