From 5ce1773fdce16a0b184363695a7d7d9483c4da0c Mon Sep 17 00:00:00 2001 From: ckielstra Date: Mon, 13 Apr 2020 21:29:02 +0200 Subject: Add support for setting a custom baudrate on the MIPS platform Fixed the issue where a custom baudrate could not be set for the MIPS platform. The hard coded values in the IOCTL call do differ in MIPS when compared to most other platforms. --- serial/serialposix.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/serial/serialposix.py b/serial/serialposix.py index 7aceb76..0464075 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -32,6 +32,7 @@ from __future__ import absolute_import import errno import fcntl import os +import platform import select import struct import sys @@ -80,8 +81,14 @@ if plat[:5] == 'linux': # Linux (confirmed) # noqa CMSPAR = 0o10000000000 # Use "stick" (mark/space) parity # baudrate ioctls - TCGETS2 = 0x802C542A - TCSETS2 = 0x402C542B + if platform.machine().lower() == "mips": + TCGETS2 = 0x4030542A + TCSETS2 = 0x8030542B + BAUDRATE_OFFSET = 10 + else: + TCGETS2 = 0x802C542A + TCSETS2 = 0x402C542B + BAUDRATE_OFFSET = 9 BOTHER = 0o010000 # RS485 ioctls @@ -154,7 +161,7 @@ if plat[:5] == 'linux': # Linux (confirmed) # noqa # set custom speed buf[2] &= ~termios.CBAUD buf[2] |= BOTHER - buf[9] = buf[10] = baudrate + buf[BAUDRATE_OFFSET] = buf[BAUDRATE_OFFSET + 1] = baudrate # set serial_struct fcntl.ioctl(self.fd, TCSETS2, buf) -- cgit v1.2.1