Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError in slcan.py when formatting standard (non-extended) CAN frames #75

Open
felixavy opened this issue Dec 4, 2024 · 0 comments

Comments

@felixavy
Copy link

felixavy commented Dec 4, 2024

A TypeError occurs in the _send_frame function of the TxWorker class inside the slcan.py driver when attempting to format standard (non-extended) CAN frames (frame.extended == False). The issue arises because the format string %03X incorrectly attempts to process both the marker (string) and frame.id (integer), but %X expects only an integer.

Code Snippet

def _send_frame(self, frame):
        marker = 'D' if frame.canfd else 'T'
        dlc_len = CANFrame.datalength_to_dlc(len(frame.data))
        line = '%s%X%s\r' % (('%c%08X' if frame.extended else 't%03X') % (marker, frame.id),
                             dlc_len,
                             binascii.b2a_hex(frame.data).decode('ascii'))

        self._conn.write(line.encode('ascii'))
        self._conn.flush()

Error Traceback
TypeError: %X format: an integer is required, not str

Proposed Fix
Adjust the formatting logic to separate the marker and frame.id when frame.extended == False, ensuring that only frame.id is passed to %03X.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant