aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/serialhdl.py
Commit message (Collapse)AuthorAgeFilesLines
* Run black on all first party python codeTomasz Kramkowski2025-08-061-101/+150
|
* mcu: allow disable send retriesTimofey Titovets2025-07-111-1/+4
| | | | Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
* serialhdl: Catch IOError in connect_canbus()Kevin O'Connor2024-07-051-1/+1
| | | | | | | It seems the can library on Python2 can sometimes raise an IOError exception on a failure. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Replace logging.warn usage with logging.warningJelle van der Waa2024-05-011-4/+5
| | | | | | | logging.warn is an alias to logging.warning since Python 3.3 and will be removed in Python 3.13. Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
* klippy: Replace deprecated logger.warn with logger.warning (#6385)Thijs Triemstra2023-11-161-2/+2
| | | | | | | Replace deprecated logger.warn with logger.warning logger.warn will be removed in Python 3.13 Signed-off-by: Thijs Triemstra <info@collab.nl>
* serialhdl: Catch os.error on can.interface.Bus() callKevin O'Connor2023-06-171-1/+1
| | | | | | | | It seems opening the canbus socket can sometimes throw an os.error (in addition to can.CanError). Catch that error to avoid Klipper reporting an internal error. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Add a get_serialqueue() methodKevin O'Connor2023-01-061-0/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialqueue: Improve canbus timingKevin O'Connor2022-07-291-6/+7
| | | | | | | Adjust timing based on the minimum transmission time of canbus messages. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Use regular str() type for stats on Python2Kevin O'Connor2021-10-311-3/+3
| | | | | | | Avoid using unicode() types on Python2 as it can lead to subtle errors. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Convert to Python3 string encodingKevin O'Connor2021-10-011-6/+6
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* msgblock: Add clock estimation helper functionsKevin O'Connor2021-06-091-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Support prepending a warn_prefix to error and log messagesKevin O'Connor2021-06-091-25/+35
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Only load the CAN module if CAN bus is configuredKevin O'Connor2021-03-131-1/+2
| | | | | | | Temporarily postpone loading the CAN module so that moonraker (and similar) can improve upgrade scripts. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Add support for communicating over a CAN busKevin O'Connor2021-03-131-1/+46
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialqueue: Support sending messages over a CAN busKevin O'Connor2021-03-131-3/+4
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* tmc2130: Verify SPI register writesKevin O'Connor2021-03-101-3/+6
| | | | | | | | The tmc2130 (and tmc5160) will respond back with the value written during the next SPI command. Use this feature to verify that the value written matches the value sent. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Update callers to decide serial fd typeKevin O'Connor2021-03-021-46/+59
| | | | | | | | Don't try to detect a "real serial port" in serialhdl.py. Instead, have the callers invoke either connect_uart(), connect_file(), or connect_pipe(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: prevent creation of controlling ttyLasse Dalegaard2021-03-011-2/+3
| | | | | | | | | | | | | | | | | | | | When `serialhdl` opens a terminal device it must prevent the device from becoming the controlling terminal of `klippy`, as such a terminal will send additional messages to the session leader, e.g. a SIGHUP, which would kill `klippy`. See e.g. #3981. pySerial already does this, but for e.g. `klipper_mcu` we were not doing this ourselves. On Linux a process must set `O_NOCTTY` when opening any file that could potentially be a terminal device, to avoid this. Earlier process daemonization tools prevent this from being an issue by double forking, but under `systemd` a process must take steps to avoid opening a controlling terminal. Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Improve Python3 compatibilityKevin O'Connor2020-12-011-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Add support for setting reqclock in CommandQueryWrapper.send()Kevin O'Connor2020-10-291-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Setup for serialqueue_free to be automatically calledKevin O'Connor2020-09-161-8/+10
| | | | | | Use ffi_main.gc() to automatically free the C serialqueue object. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Don't define a __del__() methodKevin O'Connor2020-09-161-2/+0
| | | | | | | | The existence of a __del__() method prevents deallocation on python2 if there are circular references. Just remove the method as disconnect() should already be called directly. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serial: Add Fysetc Cheetah board specific reset sequenceGrigori Goronzy2020-04-021-2/+32
| | | | | | | | | | | | | | | | | | Fysetc Cheetah v1.2 boards require a special sequence to reset reliably. This sequence works for me in all cases. Simpler sequences without double reset did not work correctly. This is likely because of a weird stateful circuitry for toggling the bootloader state. Cheetah boards use RTS to configure bootloader triggering. By default, pySerial sets RTS on connect, which unfortunately configures the board to start the bootloader on reset. Add a toggle for the RTS state to allow users to workaround. The RTS state is set before the serial connection is opened, so there are no glitches. Addresses #2026. Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
* serialhdl: Reduce connection fail timeout from 2.5 minutes to 1.5 minutesKevin O'Connor2020-03-241-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Introduce new lookup_query_command() command wrapperKevin O'Connor2020-02-201-0/+2
| | | | | | | Use new mcu.lookup_query_command() for all commands that query information from the micro-controller. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Convert queries to use new notify message ack systemKevin O'Connor2020-02-201-28/+27
| | | | | | | | | | | Convert standard queries to use the acknowledgments of the sent command to determine if the response was received or not. This also controls command retransmissions (should the response have been lost). The tmc_uart.py will continue to use the old mechanism as the tmcuart responses are not sent synchronously with the query command. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialqueue: Support notification of when a command is processedKevin O'Connor2020-02-201-4/+27
| | | | | | | | | Add ability for the host code to get a notification when the ack for a command sent to the micro-controller is received. This is in preparation for improved detection of message loss between mcu and host. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Update SendWithRetry to use reactor completionsKevin O'Connor2019-07-101-45/+23
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Use register_response() for both registering and unregisteringKevin O'Connor2019-07-101-5/+5
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Support minclock in send_with_response() requestsKevin O'Connor2019-06-211-6/+13
| | | | | | | Enhance send_with_response() so that it supports queries with a minclock. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Move SerialCommand from serialhdl.py to mcu.pyKevin O'Connor2019-06-211-19/+2
| | | | | | | | Move the serial command wrapper class from serialhdl.py to mcu.py. This will allow that class to better support higher level functionality. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Introduce SerialReader.send_with_response()Kevin O'Connor2019-06-211-3/+6
| | | | | | | Introduce a main send_with_response() helper function and use it during identify and the setup of clocksync. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Eventually timeout connect attemptKevin O'Connor2019-06-211-3/+6
| | | | | | | If the serial connection has not been successful after 2.5 minutes then report an error. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Use send_with_response() to query identify dataKevin O'Connor2019-06-211-48/+25
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Add a get_msgparser() methodKevin O'Connor2019-06-211-0/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Rename register_callback() to register_response()Kevin O'Connor2019-06-211-8/+8
| | | | | | Rename the method and use that name in the mcu class as well. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Use reactor mutex in send_with_response()Kevin O'Connor2019-06-091-12/+20
| | | | | | | Reduce the delay in send_with_response() by introducing a reactor mutex to wake the main thread when the response is obtained. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Enforce exclusive access on POSIX, this is default behavior on ↵Daniel2019-04-141-2/+2
| | | | | windows. (#1216) Signed-off-by: Daniel Joyce <daniel.a.joyce@gmail.com>
* msgproto: Convert static strings to a more generic enumeration systemKevin O'Connor2019-03-171-1/+0
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Revert "serialhdl: Enforce exclusive access on POSIX, this is default ↵Kevin O'Connor2019-02-101-2/+2
| | | | | | | | behavior on windows. (#1216)" This reverts commit fdbbda948419932be2bf93a932ae91ffc7f94e7f. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Enforce exclusive access on POSIX, this is default behavior on ↵Daniel2019-02-101-2/+2
| | | | | windows. (#1216) Signed-off-by: Daniel Joyce <daniel.a.joyce@gmail.com>
* serialqueue: Limit message transmission to available receive buffer sizeKevin O'Connor2018-05-281-0/+4
| | | | | | | | | If the mcu is using a traditional serial port, then only send a new message block if there is space available in the mcu receive buffer. This should make it significantly less likely that high load on the mcu will result in retransmits. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Automatically clear rollover_info on each restartKevin O'Connor2018-04-031-5/+0
| | | | | | | Automatically clear the information printed at the start of each log file rollover on a klippy internal restart. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Add a wrapper around the results of lookup_command()Kevin O'Connor2018-02-271-15/+27
| | | | | | | | Add a lookup_command() method to the SerialReader class that provides a wrapper that stores the serial and commandqueue references. This makes it easier to run the send() method. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* msgproto: Support default values in get_constant() callsKevin O'Connor2018-01-291-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* build: Add gcc and binutils version to mcu data dictionaryKevin O'Connor2017-12-211-2/+3
| | | | | | | | Store the gcc and binutils versions used in the compilation of the firmware in the firmware data dictionary. Forward that information to the log so it is available during debugging. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Don't open port at 1200 baudKevin O'Connor2017-10-121-3/+3
| | | | | | | The 1200 baud trick on the Arduino Due does both a reset and an erase. The erase is not desired. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* klippy: Avoid using '%' syntax when calling logging moduleKevin O'Connor2017-09-271-12/+12
| | | | | | | The logging module can build strings directly from printf syntax - no need to build the string first. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Make dump_debug() output atomicKevin O'Connor2017-09-271-6/+8
| | | | | | | Build a single (very large) logging message with the debug state. This prevents the output from being fragmented. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Move clock synchronization code into new fileKevin O'Connor2017-09-191-96/+6
| | | | | | | Move the low-level clock synchronization code from serialhdl.py to a new file clocksync.py. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>