πCAN Interface Sample App
Here is an example of a Qt application that uses the CAN interface from TorizonOS to receive CAN messages and display them on the screen.
Prerequisites
Ensure you have a CAN interface set up and connected to your ATDM.
Ensure that the necessary CAN utilities and libraries are installed on your ATDM.
Example Code
This example uses the Python python-can library to interact with the CAN interface. You'll need to install this library in your Docker container.
Dockerfile
First, update your Dockerfile to include the python-can library:
Dockerfile FROM torizon/qt5-wayland:latest
# Install necessary packages
RUN apt-get update && apt-get install -y \
python3-pip \
can-utils \
&& apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*
# Install python-can library
RUN pip3 install python-can
# Copy application files
COPY . /app
WORKDIR /app
CMD ["python3", "main.py"]main.py
Here's an example of the Qt application that receives CAN messages and displays them on the screen:
Running the Application
Build the Docker Container
Build your Docker container with the following command:
Deploy the Application to ATDM
Deploy the Docker container to your ATDM:
Summary
This example demonstrates how to create a simple Qt application that uses the CAN interface on TorizonOS to receive and display CAN messages. The application initializes the CAN interface, starts a separate thread to read CAN messages, and updates the UI to display the received messages. This provides a foundation for developing more complex CAN-based applications on your ATDM.
For more information on working with CAN in Python, you can refer to the python-can documentation.
Last updated