Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80091

Re: pySerial works in miniterm but not in my app

Newsgroups comp.lang.python
Date 2014-11-01 08:30 -0700
References <5cb7e219-cc34-4a4f-ae93-3a2bbfa9121a@googlegroups.com> <mailman.15335.1414709835.18130.python-list@python.org> <9f933554-ae04-4a3f-8317-0ed4f1e6d5b4@googlegroups.com> <mailman.15366.1414778411.18130.python-list@python.org> <da2c7489-e3c2-4fa5-b6bd-3ed2d9dbd425@googlegroups.com>
Message-ID <79aa71d6-853c-4171-9928-bb0dd5d311d3@googlegroups.com> (permalink)
Subject Re: pySerial works in miniterm but not in my app
From Dario <d.corti@gmail.com>

Show all headers | View raw


Il giorno sabato 1 novembre 2014 16:04:06 UTC+1, Dario ha scritto:

> BUT.. plot twist: in Windows XP, the very same python code and usb adapter are working just right (python 2.7 and pySerial 2.7). Also with c#, no issues.

I compared the behaviour of mono and python (2.7 and 3.3) on the same hw and os, I guess something is wrong with pySerial implementation...

Mono code on Mint:

----
SerialPort s = new SerialPort("/dev/ttyUSB0", 19200, Parity.None, 8, StopBits.One);
s.Open();

s.Write("sw o01 +\r");

while (true)
    Console.Write(Convert.ToChar(s.ReadByte()));
----

Device reacts correctly and I get back what I expect (the first line is because I sent the command via com port, the second is because I pushed a button on the device):

dario@ivymint ~ $ sudo ./Test1.exe 
sw o01 + Command OK
Button 1 pushed


Now equivalent Python 3.3 code on Mint:

---
import serial

s = serial.serial_for_url('/dev/ttyUSB0', 19200, bytesize = 8, parity = 'N', stopbits = 1)

s.close()
s.open()
s.write(bytearray('sw o01 +\r','ascii'))

while True:
	print(s.read())
---

In this case, I don't receive anything for my command, and when I press I receive garbage instead of "Button 1 pushed"

dario@ivymint ~ $ sudo python3 ./test2.py 
b'\xfc'
b'\x8f'
b'\r'
b'\x85'
b'1'
b'+'
b'\xfe'

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

pySerial works in miniterm but not in my app Dario <d.corti@gmail.com> - 2014-10-30 12:42 -0700
  Re: pySerial works in miniterm but not in my app Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-30 18:57 -0400
    Re: pySerial works in miniterm but not in my app Dario <d.corti@gmail.com> - 2014-10-31 01:21 -0700
      Re: pySerial works in miniterm but not in my app Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-31 14:00 -0400
        Re: pySerial works in miniterm but not in my app Dario <d.corti@gmail.com> - 2014-11-01 08:03 -0700
          Re: pySerial works in miniterm but not in my app Dario <d.corti@gmail.com> - 2014-11-01 08:30 -0700
            Re: pySerial works in miniterm but not in my app Dario <d.corti@gmail.com> - 2014-11-01 08:57 -0700

csiph-web