| 发表于:2007-09-19 16:18:02 楼主 |
这个是一个接受can总线数据的程序~~主要是对接受的数据做一些处理~~~ 现在的问题是这里的一个while ... wend语句只执行咯一次呢!高手帮忙看下~~~ ============================================================= private sub command1_click() text2.text = 0 if command1.caption = "打开串口 " then command1.caption = "关闭串口 " mscomm1.portopen = true else command1.caption = "打开串口 " mscomm1.portopen = false end if end sub private sub command2_click() if mscomm1.portopen = true then mscomm1.portopen = false end if unload me end sub private sub command3_click() text1.text = " " text2.text = " " end sub private sub form_load() mscomm1.commport = 1 mscomm1.settings = "9600,n,8,1 " mscomm1.inbuffersize = 1024 mscomm1.inputmode = cominputmodebinary mscomm1.inputlen = 0 mscomm1.rthreshold = 1 mscomm1.sthreshold = 0 mscomm1.inbuffercount = 0 mscomm1.outbuffercount = 0 dim mstr as string dim curstr as string dim inbuf() as string dim inputnumber as integer dim id88, id67, ide8, id2a, id50 as string dim idd88, iddc7, idde8, idd1a, idd50 as string dim flag as boolean dim jistatus as string dim soc as string inputnumber = 0 curstring = " " jistatus = " " soc = " " flag = false end sub private sub mscomm1_oncomm() static curstring as string if mscomm1.commevent = comevreceive then n = mscomm1.inbuffercount inbuf = mscomm1.input for i = 0 to ubound(inbuf) if len(hex(inbuf(i))) = 1 then mstr = "0 " & hex(inbuf(i)) curstr = "0 " & hex(inbuf(i)) else mstr = hex(inbuf(i)) curstr = hex(inbuf(i)) end if curstring = curstring & curstr text1.seltext = mstr & " " next '***************************************** 'calulate 电量 电流 电压 '***************************************** inputnumber = len(curstring) / 2 text3.text = inputnumber while (inputnumber > = 8) '判断接受字符的长度 'if inputnumber > = 8 then 'id88 = mid(curstring, 1, 2) 'id67 = mid(curstring, 3, 2) 'ide8 = mid(curstring, 5, 2) 'id2a = mid(curstring, 7, 2) 'id50 = mid(curstring, 9, 2) ' if id88 = "83 " and id67 = "67 " and ide8 = "e8 " and id2a = "2a " and id50 = "50 " then ' jistatus = mid(curstring, 11, 2) ' inputnumber = inputnumber - 8 ' curstring = mid(curstring, 17, inputnumber * 2) ' flag = true ' text5.text = val( "&h " & jistatus) ' end if ' end if if inputnumber > = 13 then '继续对字符做处理 idd88 = mid(curstring, 1, 2) iddc7 = mid(curstring, 3, 2) idde8 = mid(curstring, 5, 2) idd1a = mid(curstring, 7, 2) idd50 = mid(curstring, 9, 2) if idd88 = "88 " and iddc7 = "c7 " and idde8 = "e8 " and idd1a = "1a " and idd50 = "50 " then soc = mid(curstring, 11, 2) msgbox (str(inputnumber)) inputnumber = inputnumber - 13 msgbox (str(inputnumber)) msgbox (curstring) curstring = mid(curstring, 27, inputnumber * 2) falg = true text6.text = val( "&h " & soc) text4.text = curstring msgbox (curstring) end if end if if flag = true then flag = false else inputnumber = 0 end if wend end if text2.text = val(text2.text) + n end sub |
|
|
|
|