import win.ui; /*DSG{{*/ mainForm = win.form(text="CAN_Bootloader";right=699;bottom=465;border="dialog frame";max=false) mainForm.add( btnConnect={cls="button";text="连接";left=204;top=64;right=289;bottom=90;z=4}; btnDiag1001={cls="button";text="默认会话";left=98;top=229;right=190;bottom=260;z=23}; btnDiag1002={cls="button";text="boot会话";left=192;top=229;right=284;bottom=260;z=22}; btnDiag1003={cls="button";text="扩展会话";left=286;top=229;right=378;bottom=260;z=21}; btnFlash={cls="button";text="开始刷写";left=276;top=368;right=375;bottom=396;z=9}; btnFresh={cls="button";text="刷新";left=204;top=28;right=288;bottom=54;z=2}; btnOpen={cls="button";text="打开文件";left=272;top=101;right=371;bottom=129;z=8}; btnReadF186={cls="button";text="读取当前会话";left=4;top=229;right=96;bottom=260;z=13}; btnReadF198={cls="button";text="读取F198";left=286;top=261;right=378;bottom=289;z=19}; btnReadF199={cls="button";text="读取F199";left=192;top=261;right=284;bottom=289;z=20}; btnReadHw={cls="button";text="硬件版本号";left=98;top=261;right=190;bottom=289;z=12}; btnReadSw={cls="button";text="软件版本号";left=4;top=261;right=96;bottom=289;z=10}; btnTest={cls="button";text="停止";left=277;top=400;right=376;bottom=428;z=11}; button={cls="button";text="点亮";left=6;top=304;right=94;bottom=332;z=26}; 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="richedit";left=8;top=131;right=371;bottom=209;border=1;disabled=1;edge=1;multiline=1;wrap=1;z=14}; edit={cls="edit";left=390;top=19;right=692;bottom=401;autovscroll=false;edge=1;multiline=1;vscroll=1;z=5}; progress={cls="progress";left=389;top=435;right=689;bottom=463;edge=1;max=100;min=0;z=15}; radiobutton={cls="radiobutton";text="左板";left=277;top=310;right=365;bottom=329;checked=1;z=24}; radiobutton2={cls="radiobutton";text="右板";left=277;top=336;right=365;bottom=355;z=25}; 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}; static3={cls="static";text="刷写进度";left=389;top=408;right=442;bottom=428;transparent=1;z=16}; static4={cls="static";text="烧录APP";left=13;top=108;right=85;bottom=132;center=1;transparent=1;z=17}; static5={cls="static";text="V0.5_20230401";left=545;top=1;right=689;bottom=17;align="right";center=1;notify=1;transparent=1;z=18} ) /*}}*/ import win; import usb2canfd; import win.timer; var bootstate = false;//boot状态标志 Display = function(str){//显示日志 var nowtime = time(); nowtime.format="%H:%M:%S"; mainForm.edit.print(tostring(nowtime) + " " + str); } //遍历目录 //import console; /* import fsys.fileInfo; info = fsys.fileInfo("C:\Users\fcb19\Desktop\dll\libusb-1.0.dll"); console.log(info.writeTime); execute("pause") raw.loadDll("C:\Users\fcb19\Desktop\dll\libusb-1.0.dll"); */ CANHw = usb2canfd.USB2CANHW();//尝试加载CAN dll var ret = CANHw.LoadDll(); if(ret == 0){ Display("DLL加载成功"); } else { 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){ var canfd_check = 0x80;//mainForm.checkbox.checked?0x80:0x00; var devstr = mainForm.cbbDev.selText; var devhw = string.slice(devstr,9,9); if(devhw == 4) { //Display(devhw); canfd_check = 0x00; } ::PostThreadMessage(thrdId,101,mainForm.cbbDev.selIndex,(mainForm.cbbChannel.selIndex - 1)|canfd_check)//自定义消息 /* 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(); var flag_connected=0; listener.$Display = function(str){ Display(str); } listener.$ShowPath = function(str){ mainForm.edFile.text = str; } listener.$ShowFlashDrvPath = function(str){ mainForm.edFile2.text = str; } listener.$SetProgress = function(pos){ if(pos >= 0 && pos <= 100){ mainForm.progress.pos = pos; } } listener.$Connected = function(){ thrdTable.设备连接状态 = 1; mainForm.btnConnect.disabled = true; mainForm.btnFresh.disabled = true; mainForm.cbbDev.disabled = true; mainForm.cbbChannel.disabled = true; flag_connected = 1; } listener.$SendEnd = function(isSuccess){ //timer_bootcount.disable(); var usetime = time.now().diffsecond(starttime); bootstate = false; if(isSuccess == true){ Display("刷写成功,用时 " + usetime + " S") } } import thread.table; thrdTable = thread.table("多线程共享数据"); thrdTable.设备连接状态 = 0; thrdTable.设备 = {}; thrdTable.test = "123" thrdTable["文件加载状态"] = false; thrdTable["电源电压"] = 0; //线程函数 var CanThread = function(){ //线程函数内部要添加自已的import语句 import win; import console; import thread.table; thrdTable = thread.table("多线程共享数据"); //console.log("线程开始运行") loadcodex("\user\CanThread.aardio");//加载线程程序 //在子线程启动消息循环 win.loopMessage(FuncLoopMsg) } 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(0xF193); } mainForm.btnReadF186.oncommand = function(id,event){ DiagReadDID(0xF186); } mainForm.btnTest.oncommand = function(id,event){ DiagStopReq(); } mainForm.btnFlash.oncommand = function(id,event){ if(io.exist(mainForm.edFile.text) == null){ Display("请打开文件"); return; } if(flag_connected == 0){ Display("请连接设备"); return; } if(bootstate == true){ return ; } import fsys; var filename = fsys.getFileName(mainForm.edFile.text); if(mainForm.radiobutton.checked){ if(string.find(filename,"SWTL") == null){ Display("请打开正确的文件"); return; } } else { if(string.find(filename,"SWTR") == null){ Display("请打开正确的文件"); return; } } bootstate = true; mainForm.edit.text = ""; Display("开始刷写流程"); starttime = time.now(); //timer_bootcount.enable(); DiagBootReq(); } mainForm.btnOpen.oncommand = function(id,event){ ::PostThreadMessage(thrdId,104,1,0)//自定义消息-打开文件 } //程序关闭 mainForm.onClose = function(hwnd,message,wParam,lParam){ if(thrdId != null){ ::PostThreadMessage(thrdId,105,0,0)//自定义消息 thread.waitClose(thrdHandle); } //PLinHw.isConnected()///待完善 //console.print("线程已关闭") //console.pause() } mainForm.btnReadF198.oncommand = function(id,event){ DiagReadDID(0xF198); } mainForm.btnReadF199.oncommand = function(id,event){ DiagReadDID(0xF199); } //var frmChild = win.loadForm("\dlg\诊断子窗口.aardio"); //frmChild.show(false); mainForm.btnDiag1003.oncommand = function(id,event){ Diag10Req(0x03); } mainForm.btnDiag1002.oncommand = function(id,event){ Diag10Req(0x02); } mainForm.btnDiag1001.oncommand = function(id,event){ Diag10Req(0x01); } mainForm.text += " " mainForm.radiobutton.oncommand = function(id,event){ if(mainForm.radiobutton.checked){ ::PostThreadMessage(thrdId,106,0x720,0x620);//自定义消息 } } mainForm.radiobutton2.oncommand = function(id,event){ if(mainForm.radiobutton2.checked){ ::PostThreadMessage(thrdId,106,0x710,0x610);//自定义消息 } } mainForm.button.oncommand = function(id,event){ ::PostThreadMessage(thrdId,107,1,0);//自定义消息 } aboutcounter = 0; mainForm.static5.oncommand = function(id,event){ aboutcounter++; if(aboutcounter >= 5){ aboutcounter = 0; var frmChild = mainForm.loadForm("\dlg\about.aardio"); frmChild.doModal(mainForm); } } mainForm.text += mainForm.static5.text; mainForm.onClose = function(hwnd,message,wParam,lParam){ //::PostThreadMessage(thrdId,109,0,0);//自定义消息 //sleep(20); raw.closehandle(thrdHandle) } thrdHandle,thrdId = thread.create( CanThread ); mainForm.show(); return win.loopMessage();