TOSUN-Shanghai / TSMaster

A powerful open environment for automotive bus monitoring, simulation, testing, diagnostics, calibration and so on. It supports all kinds of mainstream hardware such as TOSUN, Vector, IXXAT, PEAK, Kvaser, Intrepidcs, ZLG, CANable, CandleLight, cantact and so on. Free for research and education purpose for some features.
http://www.tosunai.cn/
GNU Lesser General Public License v2.1
262 stars 41 forks source link

[Toolbox Designer] How to define a reception callback for a specific CAN meesage in toolbox program in Python? #109

Closed safak17 closed 8 months ago

safak17 commented 1 year ago

Hi ✋,

First of all, thank you for this great tool. I do appreciate your effort.

I want to build a toolbox application in TOSUN. When a new CAN message is received, the form application user interface will be updated according to the CAN message's data. I've examined the Raw CAN Transmit example, but could not find any CAN message reception callback implementation.

It is OK to send a CAN message by com.transmit_can_async() but how I can define a reception callback for a specific CAN message? I was expecting to find something like this:

def on_rx_CAN_MSG_123(ACAN):
  print("This function will be called whenever TOSUN receives a CAN message with ID 0x123")

CAN_MSG_ID = 0x123
com.register_receive_callback_for(CAN_MSG_ID, on_rx_CAN_MSG_123)

Looking forward to your answer. Thank you.

freshhope commented 12 months ago

this demo do have rx callback implemented: image in this event, you can check ACAN.is_tx to see whether it is tx or rx message image if you want to apply filter, just use image then you can pass parameters to this filter function image