To help Linux developers speed up development, Intrepid Control Systems announced an open source API called libicsneo earlier this year. It can be used with python_ics to integrate Intrepid vehicle networking hardware to any Python application running Linux, Mac or Windows. In this tutorial, you will learn how to transmit and receive high speed CAN or CAN FD messages using Raspberry Pi with any Intrepid tools such as ValueCAN 4 series. Please reference the API for list of supported hardware. We will be using ValueCAN 4–2 two channel of CAN or CAN FD.
Hardware SetupConnect ValueCAN 4–2 using DB-9F to OBD-II cable to neoOBD2 Simulator(optional) to receive or transmit CAN messages instead of a car.
Before you get started, make sure you have the following dependencies:
- CMake 3.2 or above
- GCC 4.7 or above, 4.8+ recommended
- libusb-1.0–0-dev
- build-essential is recommended
Open Terminal
Clone libicsneo git repository:
git clone “https://github.com/intrepidcs/libicsneo.git”
Check to see if you have install all dependencies:
cd libicsneo/
git submodule update — recursive — init
sudo apt install build-essential ninja cmake libusb
Create a build folder and make the project:
mkdir -p build && cd build && cmake ..make
Installing python_icsTo install python_ics you can use either of this command:
sudo python3 -m pip install python_ics
or:
sudo pip3 install python_ics
Create a new Python project and copy paste the example code from the python_ics or you can download the open_device_example.py from GitHub page: https://github.com/intrepidcs/python_ics/blob/master/examples/open_device_example.py
Open Python IDE and link libicsneolegacy.so by adding this line at the top of your script
ics.override_library_name(“/home/pi/libicsneo/build/libicsneolegacy.so”)
Run your Python file
Note if you don’t see your device, try turning off the raspberry Pi and turn back on with device plugged in.
Receive messagesUse this function to receive CAN messages:
def receive_can(device):
msgs, error_count = ics.get_messages(device)
print("Received {} messages with {} errors.".format(len(msgs), error_count))
for i, m in enumerate(msgs):
print('Message #{}\t'.format(i+1), end='')
print('\tArbID: {}\tData: {}'.format(hex(m.ArbIDOrHeader), [hex(x) for x in m.Data]))
Transmit messagesUse this function to transmit CAN messages:
def transmit_can(device):
msg = ics.SpyMessage()
msg.ArbIDOrHeader = 0x01 # CAN Arbitration ID
msg.Data = (1,2,3,4,5,6,7,8) # Data Bytes go here
msg.NetworkID = ics.NETID_HSCAN # First channel of CAN
# msg parameter here can also be a tuple of messages
ics.transmit_messages(device, msg)
So to recap:
- Build libicsneo project
- install python_ics
- link libicsneolegacy.so file on your python project
You can read the full documentation for libicsneo at https://libicsneo.readthedocs.io/en/latest/ and Python documentation at https://python-ics.readthedocs.io/en/2.15/.
Comments
Please log in or sign up to comment.