From 1bb15d7e21be958a32027fdd034f1a602a44816d Mon Sep 17 00:00:00 2001 From: cliechti Date: Fri, 11 Oct 2013 14:38:13 +0000 Subject: =?UTF-8?q?[Patch=20pyserial:30]=20[PATCH=201/1]=C2=A0serial.Seria?= =?UTF-8?q?l()=20should=20not=20raise=20IOError.=20also=20catch=20errors?= =?UTF-8?q?=20when=20getting=20struct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@471 f19166aa-fa4f-0410-85c2-fa1106f25c8a --- CHANGES.txt | 1 + serial/serialposix.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 35d3f65..756fa00 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -462,6 +462,7 @@ Bugfixes (posix): - [Bug pyserial:137] Patch to add non-standard baudrates to Cygwin - [Bug pyserial:141] open: Pass errno from IOError to SerialException - [Bug pyserial:125] Undefined 'base' on list_ports_posix.py, function usb_lsusb +- [Patch pyserial:30] [PATCH 1/1] serial.Serial() should not raise IOError. Bugfixes (win32): diff --git a/serial/serialposix.py b/serial/serialposix.py index e1abce3..131e31b 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -45,18 +45,18 @@ if plat[:5] == 'linux': # Linux (confirmed) import array buf = array.array('i', [0] * 64) - # get serial_struct - FCNTL.ioctl(port.fd, TCGETS2, buf) - # set custom speed - buf[2] &= ~TERMIOS.CBAUD - buf[2] |= BOTHER - buf[9] = buf[10] = baudrate - - # set serial_struct try: + # get serial_struct + FCNTL.ioctl(port.fd, TCGETS2, buf) + # set custom speed + buf[2] &= ~TERMIOS.CBAUD + buf[2] |= BOTHER + buf[9] = buf[10] = baudrate + + # set serial_struct res = FCNTL.ioctl(port.fd, TCSETS2, buf) - except IOError: - raise ValueError('Failed to set custom baud rate: %r' % baudrate) + except IOError, e: + raise ValueError('Failed to set custom baud rate (%s): %s' % (baudrate, e)) baudrate_constants = { 0: 0000000, # hang up -- cgit v1.2.1