| 发表于:2007-08-24 09:57:5616楼 得分:0 |
我自己做过的一个串口数据接收 private sub mscomm1_oncomm() on error resume next dim bytdata as variant dim errornum as integer doevents if startscan = true then with mscomm1 if .inbuffercount > = 21 then bytdata = .input .inbuffercount = 0 datastr = bytdata errornum = instr(1, datastr, "ffffff ") if errornum = 0 then scanfinish = false scanning = true tempstr = trim(processstr(datastr)) comcount = comcount + 1 if comcount > = 6000 then startscan = false scanfinish = true comcount = 0 end if m_data = mid(tempstr, 4, 8) n_data = mid(tempstr, 13, 8) if comcount > = 2 then '收集数据 end if else if scanning = true then scanedcount = scanedcount + 1 if scanedcount > 20 then scanfinish = true end if end if end if end with else with mscomm1 if .inbuffercount > = 21 then bytdata = .input .inbuffercount = 0 datastr = bytdata 'replace(trim(bytdata), chr(13), "s ", 1) errornum = instr(1, datastr, "ffffff ") if errornum = 0 then comcount = comcount + 1 if comcount > 6000 then comcount = 0 tempstr = trim(processstr(datastr)) m_data = mid(tempstr, 4, 8) n_data = mid(tempstr, 13, 8) end if end if end with end if end sub | | |
|