Skip to content

Issues opening serial connection on linux #8

Description

@jku

I've been playing with tkey for a bit now and I've never managed to get this python module to work: serial connection seems to fail on my linux laptop (distro is close to debian unstable) whatever I do.

Example:

tkeyclient-py$ python3 ./client.py test --auto
2026-06-14 22:20:44,809 - [INFO] cmds: Attempting to open serial port: /dev/ttyACM0
Traceback (most recent call last):
  File "/home/jkukkonen/src/tillitis/tkeyclient-py/./client.py", line 76, in <module>
    result = args.func(args)
  File "/home/jkukkonen/src/tillitis/tkeyclient-py/cmds.py", line 23, in wrapper
    return func(*args, **kwargs)
  File "/home/jkukkonen/src/tillitis/tkeyclient-py/cmds.py", line 38, in test_connection
    with TKey(port, connect=True) as tk:
         ~~~~^^^^^^^^^^^^^^^^^^^^
  File "/home/jkukkonen/src/tillitis/tkeyclient-py/tkeyclient/tkey.py", line 93, in __init__
    self.connect()
    ~~~~~~~~~~~~^^
  File "/home/jkukkonen/src/tillitis/tkeyclient-py/tkeyclient/tkey.py", line 124, in connect
    self.conn.open()
    ~~~~~~~~~~~~~~^^
  File "/home/jkukkonen/src/tillitis/securesystemslib/.venv/lib/python3.14/site-packages/serial/serialposix.py", line 332, in open
    self._reconfigure_port(force_update=True)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/home/jkukkonen/src/tillitis/securesystemslib/.venv/lib/python3.14/site-packages/serial/serialposix.py", line 517, in _reconfigure_port
    termios.tcsetattr(
    ~~~~~~~~~~~~~~~~~^
        self.fd,
        ^^^^^^^^
        termios.TCSANOW,
        ^^^^^^^^^^^^^^^^
        [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (22, 'Invalid argument')

My intuition was that this is a pyserial issue specific to linux (possibly to do with the unusual baud rate), and I did manage to work around this by using raw serial access in my own work -- but that no longer uses tkeyclient-py . See _serial_hack.py in this code if you are interested.

Did I do something wrong here or is this a known issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions