Skip to content

Commit

Permalink
Wait until a serial port has been connected
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszlagan committed Jan 3, 2025
1 parent b6d1727 commit 113cc30
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ def __init__(self):
if len(self.linear_speed_presets.value) != 3 or len(self.angular_speed_presets.value) != 3:
raise ValueError("Speed presets must be a list of 3 values")

self.serial = serial.Serial(port.value, baud.value, timeout=2)
self.serial = None
while self.serial is None:
try:
self.serial = serial.Serial(port.value, baud.value, timeout=2)
except serial.SerialException as e:
self.get_logger().error(f"Failed to open serial port: {e}")
rclpy.spin_once(self, timeout_sec=2)

self.parser = CRSFParser()
self.parser.on_message = lambda msg: self.handle_message(msg)
Expand Down

0 comments on commit 113cc30

Please sign in to comment.