import console; //console.log("CANTHREAD开始") import thread.table; var thrdTable_CANHW = thread.table("CAN设备",true/*清空*/) var thrdTable_RxTable = thread.table("接收数据",true/*清空*/) var thrdTable_TxTable = thread.table("发送数据",true/*清空*/) CT_Display = function(str){//显示日志 if(Display!=null){ Display(str); } } CT_Fresh = function(){ ::PostThreadMessage(thrdId,100,0,0)//自定义消息 } CT_Connect = function(dev,chn,iscanfd){ var canfd_check = 0x80;//iscanfd?0x80:0x00;//兼容UTA401 ::PostThreadMessage(thrdId,101,dev,(chn - 1)|canfd_check);//自定义消息 } CT_GetCANHw = function(){ var canhw = {}; for( k,v in thrdTable_CANHW.each() ){ table.push(canhw,v); } return canhw; } CT_GetRxMsg = function(id){ var ret = thrdTable_RxTable.get(id); return ret; } CT_UpdateCANTxMsg = function(id,period,data){ var msg = {}; msg.id = id; msg.period = period; msg.data = data; thrdTable_TxTable.set(id,msg); } CT_Diag10 = function(sid){ ::PostThreadMessage(thrdId,111,sid,0);//自定义消息,111为10服务,参考CanThread文件FuncLoopMsg函数 } CT_Diag22 = function(did){ ::PostThreadMessage(thrdId,110,did,0);//参考CanThread文件FuncLoopMsg函数 } CT_Diag2EVal2B = function(did,data){ ::PostThreadMessage(thrdId,116,did,data);//参考CanThread文件FuncLoopMsg函数 } CT_Diag2EVal1B = function(did,data){ ::PostThreadMessage(thrdId,117,did,data);//参考CanThread文件FuncLoopMsg函数 } CT_Diag3E = function(){ ::PostThreadMessage(thrdId,115,0,0);//参考CanThread文件FuncLoopMsg函数 } CT_SetDiagID = function(req,rsp){ ::PostThreadMessage(thrdId,102,req,rsp);//参考CanThread文件FuncLoopMsg函数 } LastDiagRespData = {}; CT_GetLastDiagResp = function(){ return LastDiagRespData; } CT_UpdateCANTxMsg(0x30,200,{0,0,0x00,0, 0,0x08,0,0}); //CAN通讯线程 import thread.command; var listener = thread.command(); var flag_connected=0; listener.$Display = function(str){ CT_Display(str); } listener.$Connected = function(devs){ flag_connected = 1; CAN_Connected_callback(); } listener.$LastDiagResp = function(resp){ //console.log("接收数据"); LastDiagRespData = resp; //console.dumpJson(LastDiagRespData); } //线程函数 var CanThreadFunc = function(){ //线程函数内部要添加自已的import语句 import win; import console; //console.log("线程开始运行") loadcodex("\CANThread\CanThread.aardio");//加载线程程序 //在子线程启动消息循环 win.loopMessage(FuncLoopMsg) } thrdHandle,thrdId = thread.create( CanThreadFunc );