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

Tx messages can not be received with AsyncBufferedReader() #1769

Open
EllaJia opened this issue Apr 22, 2024 · 0 comments
Open

Tx messages can not be received with AsyncBufferedReader() #1769

EllaJia opened this issue Apr 22, 2024 · 0 comments
Labels

Comments

@EllaJia
Copy link

EllaJia commented Apr 22, 2024

Python 3.11.3
python-can 4.3.1

The program is to talk to an amplifier and log both the Tx and Rx messages asynchronously. In a word to explain how things work on the hardware side, the Amplifier sends Rx messages periodically, and receives Tx messages I send.

The documentation said can.AsyncBufferedReader() is able to catch both Tx and Rx messages, so I adapted the example as the following.

async def main() -> None:
    logger = can.Logger("logfile.asc")

    with can.Bus(auto_reset=True) as bus:
        reader = can.AsyncBufferedReader()

        listeners: List[MessageRecipient] = [
            print_and_log_message, 
            reader,
            logger
        ]

        loop = asyncio.get_running_loop()
        notifier = can.Notifier(bus, listeners, loop=loop)

        msg = can.Message(arbitration_id=0x106, data=[0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], dlc=8, is_extended_id=False, is_rx=False, is_error_frame=False)
        
        send_task = bus.send_periodic(msg, 0.1, 5)

        await asyncio.sleep(5)

        if isinstance(send_task, can.CyclicSendTaskABC):
            send_task.stop()

        notifier.stop()
        bus.shutdown()

With this code snippet, the log file gets Rx messages only, even the Tx messages I sent out actually works (based on the Rx messages I see, some parameters are updated as what I want). Is it something with my code or the function? Any thoughts and advice will be deeply appreciated!

@EllaJia EllaJia added the bug label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant