找传奇、传世资源到传世资源站!

利用Python发送UDS报文(UDS诊断实例)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

PEAK CAN自动发送CAN报文的python程序from clipboardfrom PCANBasic import *import timefrom sys import *from threading import *temp10ms = 0temp20ms = 0temp100ms = 0;temp250ms = 0;temp1000ms = 0;def send10ms(): global temp10ms temp10ms = 1 if temp10ms > 7: temp10ms = 0 msg = TPCANMsg() msg.ID = 0x001 msg.MSGTYPE = PCAN_MODE_STANDARD msg.LEN = 8 for i in range(8): msg.DATA[i] = 0x10 temp10ms global pd pd.Write(PCAN_USBBUS1, msg) print(10) global thread10ms thread10ms = Timer(0.01, send10ms) thread10ms.start()def send20ms(): global temp20ms temp20ms = 1 if temp20ms > 8: temp20ms = 0 msg = TPCANMsg() msg.ID = 0x002 msg.MSGTYPE = PCAN_MODE_STANDARD msg.LEN = 8 for i in range(8): msg.DATA[i] = 0x00 temp20ms global pd pd.Write(PCAN_USBBUS1, msg) print(20) global thread20ms thread20ms = Timer(0.02, send20ms) thread20ms.start()def send100ms(): global temp100ms temp100ms = 1 if temp100ms > 8: temp100ms = 0 msg = TPCANMsg() msg.ID = 0x003 msg.MSGTYPE = PCAN_MODE_STANDARD msg.LEN = 8 for i in range(8): msg.DATA[i] = 0x40 temp100ms global pd pd.Write(PCAN_USBBUS1, msg) print(100) global thread100ms thread100ms = Timer(0.1, send100ms) thread100ms.start()def send250ms(): global temp250ms temp250ms = 1 if temp250ms > 8: temp250ms = 0 msg = TPCANMsg() msg.ID = 0x004 msg.MSGTYPE = PCAN_MODE_STANDARD msg.LEN = 8 for i in range(8): msg.DATA[i] = 0x50 temp250ms global pd pd.Write(PCAN_USBBUS1, msg) print(250) global thread250ms thread250ms = Timer(0.25, send250ms) thread250ms.start()def send1000ms(): global temp1000ms temp1000ms = 1 if temp1000ms > 8: temp1000ms = 0 msg = TPCANMsg() msg.ID = 0x005 msg.MSGTYPE = PCAN_MODE_STANDARD msg.LEN = 8 for i in range(8): msg.DATA[i] = 0x20 temp1000ms global pd pd.Write(PCAN_USBBUS1, msg) msg.ID = 0x006 for i in range(8): msg.DATA[i] = 0x30 temp1000ms pd.Write(PCAN_USBBUS1, msg) msg.ID = 0x007 for i in range(8): msg.DATA[i] = 0x60 temp1000ms pd.Write(PCAN_USBBUS1, msg) msg.ID = 0x008 for i in range(8): msg.DATA[i] = 0x70 temp1000ms pd.Write(PCAN_USBBUS1, msg) msg.ID = 0x009 msg.DATA[0] = 0x00 msg.DATA[1] = 0x00 msg.DATA[2] = 0x00 msg.DATA[3] = 0x00 msg.DATA[4] = 0x00 msg.DATA[5] = 0x00 msg.DATA[6] = 0x00 msg.DATA[7] = 0x00 pd.Write(PCAN_USBBUS1, msg) print(1000) global thread1000ms thread1000ms = Timer(1, send1000ms) thread1000ms.start()if __name__ == "__main__": global pd pd = PCANBasic() pd.Initialize(PCAN_USBBUS1,PCAN_BAUD_500K) thread10ms = Timer(0.01, send10ms) thread100ms = Timer(0.1, send100ms) thread250ms = Timer(0.25, send250ms) thread1000ms = Timer(1, send1000ms) # thread5000ms = Timer(5, send5000ms) thread20ms = Timer(0.02, send20ms) thread10ms.start() thread20ms.start() thread100ms.start() thread250ms.start() thread1000ms.start() # thread5000ms.start()

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复