How ElectronicControlUnit (ECU) and ControllerApplication (CA) work together
masterIn this library, an ElectronicControlUnit (ECU) acts as a container that can hold one or more ControllerApplications (CA).
- An ECU manages the connection to the CAN bus and can subscribe to all passing messages globally.
- A CA represents a specific logical entity on the bus with its own unique address. It handles its own address claiming, message sending (via
send_pgn), and specific timers.
To use them, you typically create an ElectronicControlUnit, create one or more ControllerApplication objects, and then add the CAs to the ECU using ecu.add_ca(controller_application=ca).
import j1939
# Create the ECU
ecu = j1939.ElectronicControlUnit()
# Create a CA with a specific name and address
name = j1939.Name(manufacturer_code=666, identity_number=1234567, ...)
ca = j1939.ControllerApplication(name, 128)
# Link them
ecu.add_ca(controller_application=ca)
# Connect and start
ecu.connect(bustype='pcan', channel='PCAN_USBBUS1', bitrate=250000)
ca.start()