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

Enable echo frames in PCAN driver if receive_own_messages is set #1723

Merged
merged 3 commits into from
Jan 20, 2024

Conversation

tttech-ferdigg
Copy link
Contributor

@tttech-ferdigg tttech-ferdigg commented Jan 12, 2024

This allows the reception of messages sent over the interface. Before, setting the parameter receive_own_messages did not have any effect for the PCAN interface.

Tested with PEAK PCAN-USB FD dongle, Firmware version 3.2.0

@zariiii9003
Copy link
Collaborator

Run ruff check --fix ./can to fix the static code analysis. The failing PyPy tests are unrelated, you can ignore those.

@lumagi
Copy link
Collaborator

lumagi commented Jan 14, 2024

This looks nice. I can test it next week.

Copy link
Collaborator

@lumagi lumagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import can


def main():
    bus1 = can.Bus(
        interface="pcan", channel="PCAN_USBBUS1", bitrate=500000, receive_own_messages=True
    )
    bus2 = can.Bus(
        interface="pcan", channel="PCAN_USBBUS2", bitrate=500000, receive_own_messages=False
    )

    msg1 = can.Message(arbitration_id=0x123, is_fd=False, data=b'hello')
    msg2 = can.Message(arbitration_id=0x123, is_fd=False, data=b'world')
    bus1.send(msg1)
    
    print(bus1.recv(0.1))
    print(bus1.recv(0.1))
    print(bus2.recv(0.1))
    print(bus2.recv(0.1))
    
    bus2.send(msg2)
    
    print(bus1.recv(0.1))
    print(bus1.recv(0.1))
    print(bus2.recv(0.1))
    print(bus2.recv(0.1))


if __name__ == "__main__":
    main()

I did a back-to-back test with two PCAN interfaces, and the output I got was the following:

Timestamp: 1705482812.765127    ID: 00000123    X Rx                DL:  5    68 65 6c 6c 6f              'hello'
None
Timestamp: 1705482812.765166    ID: 00000123    X Rx                DL:  5    68 65 6c 6c 6f              'hello'
None
Timestamp: 1705482812.970332    ID: 00000123    X Rx                DL:  5    77 6f 72 6c 64              'world'
None
None
None

So, it looks like it's working as intended.

@zariiii9003
Copy link
Collaborator

Is it possible to detect the message direction to set the is_rx attribute of Message?

@tttech-ferdigg
Copy link
Contributor Author

Is it possible to detect the message direction to set the is_rx attribute of Message?

I will check.

@tttech-ferdigg
Copy link
Contributor Author

Works :)

@lumagi
Copy link
Collaborator

lumagi commented Jan 17, 2024

Same here:

Timestamp: 1705497322.812748    ID: 00000123    X Tx                DL:  5    68 65 6c 6c 6f              'hello'
None
Timestamp: 1705497322.812736    ID: 00000123    X Rx                DL:  5    68 65 6c 6c 6f              'hello'
None
Timestamp: 1705497323.015279    ID: 00000123    X Rx                DL:  5    77 6f 72 6c 64              'world'
None
None
None

@zariiii9003 zariiii9003 merged commit 4e39768 into hardbyte:main Jan 20, 2024
30 checks passed
@tttech-ferdigg
Copy link
Contributor Author

Thank you for your efforts and keep up the great work :)

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

Successfully merging this pull request may close these issues.

None yet

3 participants