Library is under development API will change
- LIN frame transmission / reception
- LDF signals encoding / decoding (only signal and frames currently working, schedule table parsing not implemented, max signal size is 1 byte)
- Works on windows, linux, mac. Supported hardware , uCAN LIN USB CONVERTER
pip install ucanlintoolsTo load ldf
from ucanlintools.LDF_parser import parseLDF
ldf = parseLDF("D:\\ldfe.ldf")
message = ldf.get_message_by_name('FRAME_A')
print(message.signals)To decode/ encode frame
aaa = message.encode({'SIGNAL_A': 1})
bbb = b'\x00\x00\x00\x00\x00\x00'
message.decode(bbb)To setup LIN USB Converter
lin = ucanlintools.LUC('COM7')
lin.set_frame_rx_handler(rx_any)
lin.set_new_frame_rx_handler(rx_new_data)
lin.openAsMaster()
lin.addReceptionFrameToTable(52,8)
lin.addReceptionFrameToTable(54,8)
lin.enable()Example data reception handler
def rx_new_data(f):
global message
print (hex(f.id) + ": " +(f.data.hex()))
if (message.id == f.id):
message.decode(f.data)
print(message.diff_str())Example blocking function that can be called in main script to handle KeyboardInterrupt and SystemExit and add code that should be executed after connection is closed. It blocks the script that calls the function but does not interrupt communication threads.
import time
def listen(lin):
try:
while lin.isRunning():
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
lin.disable()
lin.deInitSerial()