| 发表于:2007-01-09 10:45:292楼 得分:0 |
public function sendhexdatastring() as boolean dim senddata as string dim buf() as byte dim m, n, p as long dim i, j, k as long, cs on error resume next sendhexdatastring = false senddata = "029c " 'senddata = strsenddata 'trim(text2.text) '½«òª•¢ëíµäîä±¾¿òäúµä¿õ¸ñ襳ý£¬²¢çò¸³¸øsenddata if frmmain.mscomm1.portopen = false then frmmain.mscomm1.portopen = true 'msgbox "çë´ò¿ª´®¿ú ", vbokonly, "´íîó " 'exit function end if if len(senddata) = 0 then 'èç¹ûîä±¾¿òäúã»óðêý¾ý msgbox "çëêäèëêý¾ý ", vbokonly, "´íîó " exit function end if 'if check2.value = 0 then 'èç¹ûã»óðñ¡ôñêç•ñòô16½øöæ•¢ëí 'p = len(senddata) 'redim buf(p - 1) as byte 'for i = 1 to p ' buf(i - 1) = asc(mid(senddata, i, 1)) '½«ã¿¸ö×ö•ûòôascâë•¢ëí 'next i 'else 'èç¹ûñ¡ôñòô16½øöæ•¢ëí senddata = replace(senddata, " ", " ") senddata = replace(senddata, vbcrlf, " ") p = len(senddata) \ 2 - 1 redim buf(p) as byte for i = 0 to p buf(i) = clng( "&h " & mid(senddata, i * 2 + 1, 2)) 'òô16½øöæêý•¢ëí next i 'end if 'í¨¹ý´®¿ú•¢ëíêý¾ý frmmain.mscomm1.inputmode = cominputmodebinary frmmain.mscomm1.output = buf() 'sleep (100) 'procgetdata sendhexdatastring = true exit function '³ö´í´¦àí doerr: if err.number = 13 then msgbox "êý¾ý¸ñê½²»¶ô ", vbokonly, "´íîó " else msgbox err.description end if end function | | |
|