summaryrefslogtreecommitdiff
path: root/serial/serialposix.py
diff options
context:
space:
mode:
authorckielstra <c.kielstra@ultimaker.com>2020-04-13 21:29:02 +0200
committerckielstra <c.kielstra@ultimaker.com>2021-02-25 14:18:59 +0100
commit5ce1773fdce16a0b184363695a7d7d9483c4da0c (patch)
tree133abcfd832bca6822e092e41d1263281aafeb06 /serial/serialposix.py
parent0e7634747568547b8a7f9fd0c48ed74f16af4b23 (diff)
downloadpyserial-git-5ce1773fdce16a0b184363695a7d7d9483c4da0c.tar.gz
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.
Diffstat (limited to 'serial/serialposix.py')
-rw-r--r--serial/serialposix.py13
1 files 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)