import win.ui; /*DSG{{*/ mainForm = win.form(text="CAN_Bootloader";right=599;bottom=399;border="dialog frame";max=false) mainForm.add( btnConnect={cls="button";text="连接";left=204;top=64;right=289;bottom=90;z=4}; btnFlash={cls="button";text="开始刷写";left=152;top=180;right=272;bottom=205;z=10}; btnFresh={cls="button";text="刷新";left=204;top=28;right=288;bottom=54;z=2}; btnOpen={cls="button";text="打开文件";left=31;top=180;right=131;bottom=206;z=9}; btnReadF186={cls="button";text="读取当前会话";left=19;top=293;right=118;bottom=321;z=14}; btnReadHw={cls="button";text="读取硬件版本号";left=17;top=263;right=116;bottom=291;z=13}; btnReadSw={cls="button";text="读取软件版本号";left=17;top=233;right=116;bottom=261;z=11}; btnTest={cls="button";text="测试";left=173;top=355;right=272;bottom=383;z=12}; cbbChannel={cls="combobox";left=58;top=64;right=191;bottom=90;edge=1;items={};mode="dropdown";z=3}; cbbDev={cls="combobox";left=58;top=27;right=191;bottom=53;edge=1;items={};mode="dropdown";z=1}; edFile={cls="edit";left=27;top=141;right=281;bottom=165;edge=1;readonly=1;z=8}; edit={cls="edit";left=296;top=8;right=582;bottom=383;edge=1;multiline=1;z=5}; static={cls="static";text="设备";left=1;top=28;right=61;bottom=52;align="center";center=1;transparent=1;z=6}; static2={cls="static";text="通道";left=1;top=66;right=61;bottom=90;align="center";center=1;transparent=1;z=7} ) /*}}*/ import win; import usb2canfd; Display = function(str){ mainForm.edit.print(tostring(time()) + " " + str); } CANHw = usb2canfd.USB2CANHW(); var ret = CANHw.LoadDll(); if(ret == 0){ Display("DLL加载成功"); } mainForm.cbbChannel.add("通道1"); mainForm.cbbChannel.add("通道2"); mainForm.cbbChannel.selIndex = 1 mainForm.btnFresh.oncommand = function(id,event){ mainForm.cbbDev.clear(); var hwnum = CANHw.FlashHw(); if(hwnum == 0){ mainForm.cbbDev.text = "未找到硬件" } else { var allhw = CANHw.GetAvailableHW(); for(i=1;#allhw;1){ mainForm.cbbDev.add(allhw[i].name); } } mainForm.cbbDev.selIndex = 1 ::PostThreadMessage(thrdId,100,0,0)//自定义消息 } mainForm.btnConnect.oncommand = function(id,event){ ::PostThreadMessage(thrdId,101,mainForm.cbbDev.selIndex,mainForm.cbbChannel.selIndex - 1)//自定义消息 /* var ret = CANHw.OpenDevice(mainForm.cbbDev.selIndex,mainForm.cbbChannel.selIndex - 1);//通道为0和1 if(ret == 0){ Display("连接成功"); } else { Display("连接失败"); } */ } //CAN通讯线程 import thread.command; var listener = thread.command(); listener.$Display = function(str){ Display(str); } //线程函数 var CanThread = function(){ //线程函数内部要添加自已的import语句 import win; import console; console.log("线程开始运行") loadcodex("\user\CanThread.aardio");//加载线程程序 //在子线程启动消息循环 win.loopMessage(FuncLoopMsg) } var DiagReadDID = function(did){ ::PostThreadMessage(thrdId,110,did,0)//自定义消息 } var Diag10Req = function(num){ ::PostThreadMessage(thrdId,111,num,0)//自定义消息 } var DiagBootReq = function(){ ::PostThreadMessage(thrdId,102,0,0)//自定义消息 } var DiagStopReq = function(){ ::PostThreadMessage(thrdId,103,0,0)//自定义消息 } mainForm.btnReadSw.oncommand = function(id,event){ DiagReadDID(0xF195); } mainForm.btnReadHw.oncommand = function(id,event){ DiagReadDID(0xF192); } mainForm.btnReadF186.oncommand = function(id,event){ DiagReadDID(0xF186); } mainForm.btnTest.oncommand = function(id,event){ DiagStopReq(); } mainForm.btnFlash.oncommand = function(id,event){ DiagBootReq(); } thrdHandle,thrdId = thread.create( CanThread ) mainForm.show(); return win.loopMessage();