A set of python scripts to work with SAE J1708 protocol over serial port communication.
SAE J1708 protocol is used in various heavy-duty equipment (e.g., lorries, loaders, diggers, etc.) and is a simple communication protocol supporting CRC shechsum. Detailed description of the protocol is provided here.
A J1708 message example:
MID | Data 1 | Data 2 | Data 3 | Data 4 | Checksum |
---|---|---|---|---|---|
44 | 23 | 61 | 114 | 62 | 208 |
The first byte in every message must always be a MID. Valid values of the MID is 0-255.
- MIDs 0-68 belong to predefined devices to ensure consistency.
- MIDs 69-86 are set aside for J1922 protocol.
- MIDs 87-110 are reserved for future applications. Manufactures may apply to SAE Truck and Bus Electrical Committee to define a MID. MID 111 is designated for factory tests of electronic control units and shall not be used by any on-board unit.
- MIDs 112-127 are not reserved and can be used as wanted. MIDs 128-255 are reserved for the SAE J1587 protocol, where they are defined.
The checksum is calculated as following:
As an example (using the sample message in the figure above),
- 44+23+61+114+62+208 = 512
- (512 AND 0xFF) = 0, so the message is correct.
The scripts have a number of dependencies that can be installed using
To use the scripts the following packages are required:
- pyserial
- time
- csv
- sys
- signal
- os
To install the above-mentioned packages use the following commands:
python -m pip install --upgrade pip
python -m pip install serial, time, csv, sys, signal, os
To read the serial bus COM-port number has to be updated in line 46 in j1708_com_receive.py. It is also advisible to check com.baudrate and com.timeout
Running of the script from CLI by:
python j1708_com_receive.py
will result in a log file to be created in logs/ folder.