Skip to content

Commit

Permalink
Fix double start socketcan periodic
Browse files Browse the repository at this point in the history
  • Loading branch information
SWolfSchunk committed Sep 18, 2024
1 parent 83280cd commit 310d275
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions can/interfaces/socketcan/socketcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def __init__(
messages: Union[Sequence[Message], Message],
period: float,
duration: Optional[float] = None,
autostart: bool = False,
autostart: bool = True,
) -> None:
"""Construct and :meth:`~start` a task.
Expand All @@ -350,13 +350,13 @@ def __init__(

self.bcm_socket = bcm_socket
self.task_id = task_id
self._tx_setup(self.messages)

if autostart:
self.start()
self._tx_setup(self.messages, send=autostart)

def _tx_setup(
self, messages: Sequence[Message], raise_if_task_exists: bool = True
self,
messages: Sequence[Message],
raise_if_task_exists: bool = True,
send: bool = True,
) -> None:
# Create a low level packed frame to pass to the kernel
body = bytearray()
Expand All @@ -380,7 +380,9 @@ def _tx_setup(
for message in messages:
body += build_can_frame(message)
log.debug("Sending BCM command")
send_bcm(self.bcm_socket, header + body)

if send:
send_bcm(self.bcm_socket, header + body)

def _check_bcm_task(self) -> None:
# Do a TX_READ on a task ID, and check if we get EINVAL. If so,
Expand Down

0 comments on commit 310d275

Please sign in to comment.