Software Setup

6. Build libicsneo project and link libicsneoleagacy.so file to your Python project.

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_ics

To 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 Messages

Use this function to Receive CAN messagespy

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 Messages

Use 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/.

Last updated