Skip to content

Commit

Permalink
Add support for setting a custom baudrate on the MIPS platform
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ckielstra committed Feb 25, 2021
1 parent 0e76347 commit 5ce1773
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions serial/serialposix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import errno
import fcntl
import os
import platform
import select
import struct
import sys
Expand Down Expand Up @@ -80,8 +81,14 @@ def _update_break_state(self):
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
Expand Down Expand Up @@ -154,7 +161,7 @@ def _set_special_baudrate(self, baudrate):
# 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)
Expand Down

0 comments on commit 5ce1773

Please sign in to comment.