Mac OS X TERMIOS API only supports baudrates up to 230400 bps.
Higher baudrates are not supported, and any attempt to use them ends up
with an exception.
On Tiger (10.4.x) and above, it is nevertheless possible to use higher
baudrates, using an IOKit-specific ioctl call.
I have not written a patch yet, but here is a code sample I use to
circumvent the current pyserial limitation on Mac OS X. It should be rather
trivial to adapt it to the actual pyserial mainstream code.
serialclass = serial.Serial
if sys.platform.lower() in ('darwin'):
version = os.uname()[2].split('.')
# Tiger or above can support arbitrary serial speeds
if int(version[0]) >= 8:
# first step: remove all speeds not supported with TERMIOS
# so that pyserial never attempts to use them directly
for b in serial.baudrate_constants.keys():
if b > 230400:
del serial.baudrate_constants[b]
# second step: override the default _reconfigurePort
function
class DarwinSerial(serial.Serial):
def _reconfigurePort(port):
try:
serial.Serial._reconfigurePort(port)
except AttributeError:
# third step: use IOKit-specific call to set
up
# high speeds
import array, fcntl
buf = array.array('i', [int(port._baudrate)])
IOSSIOSPEED = 0x80045402 #_IOW('T', 2,
speed_t)
fcntl.ioctl(port.fd, IOSSIOSPEED, buf, 1)
serialclass = DarwinSerial
if os.path.exists(device):
if stat.S_ISSOCK(os.stat(device)[0]):
from neo.serialext import SerialExtender
serialclass = SerialExtender.serialsocketclass()
port = serialclass(port=device,
baudrate=self.DEFAULT_BAUDRATE,
timeout=0)
Chris Liechti
None
None
Public
|
Date: 2009-07-24 15:55 you could check for the set_special_baudrate function with hasattr() |
|
Date: 2009-07-24 12:56 Ok, great, it works with [242], up to 3Mbps on my machine - thanks a lot. |
|
Date: 2009-07-23 23:54 thanks for the feedback. i've updated the posix backend so that is uses a |
|
Date: 2009-07-22 18:20 Sorry, I meant: |
|
Date: 2009-07-22 18:19 > the SVN HEAD already contains code to support non standard baudrate on |
|
Date: 2009-07-21 23:43 the SVN HEAD already contains code to support non standard baudrate on |
|
Date: 2009-05-09 21:21 This is actually a broader issue than just support of high baud rates under |
|
Date: 2009-02-04 00:26 File Added: hsserial.py |
| Filename | Description | Download |
|---|---|---|
| hsserial.py | High speed workaround on Mac OS X | Download |
| Field | Old Value | Date | By |
|---|---|---|---|
| close_date | - | 2009-07-24 15:55 | cliechti |
| allow_comments | 1 | 2009-07-24 15:55 | cliechti |
| resolution_id | None | 2009-07-24 15:55 | cliechti |
| status_id | Open | 2009-07-24 15:55 | cliechti |
| status_id | Pending | 2009-07-24 12:56 | eblot |
| close_date | 2009-07-23 23:54 | 2009-07-24 12:56 | eblot |
| status_id | Open | 2009-07-23 23:54 | cliechti |
| close_date | - | 2009-07-23 23:54 | cliechti |
| status_id | Pending | 2009-07-22 18:19 | eblot |
| close_date | 2009-07-21 23:43 | 2009-07-22 18:19 | eblot |
| close_date | - | 2009-07-21 23:43 | cliechti |
| assigned_to | nobody | 2009-07-21 23:43 | cliechti |
| status_id | Open | 2009-07-21 23:43 | cliechti |
| File Added | 311924: hsserial.py | 2009-02-04 00:26 | eblot |
| summary | High baudrates no supported on Mac OS X | 2009-02-04 00:25 | eblot |
Copyright © 2009 Geeknet, Inc. All rights reserved. Terms of Use