关于VB串口通讯的问题

来源:百度知道 编辑:UC知道 时间:2024/06/14 06:51:35
Option Explicit
Dim intTime As Integer
Private strSendText As String '发送文本数据
Private bytSendByte() As Byte '发送二进制数据
Private blnReceiveFlag As Boolean
Private blnAutoSendFlag As Boolean
Private intPort As Integer
Private strSet As String
Private intReceiveLen As Integer
Private bytReceiveByte() As Byte
Private strAscii As String '设置初值
Private strHex As String
Private intHexWidth As Integer
Private intLine As Integer
Private m As Integer
Private strAddress As String
'字符表示的十六进制数转化为相应的整数,错误则返回 -1
Function ConvertHexChr(str As String) As Integer
Dim test As Integer
test = Asc(str)
If test >= Asc("0") And test <= Asc("9") Then
test = test - Asc("0")
ElseIf test >= Asc("a") And test <= Asc("f") Then
test = test - Asc("a") + 10
ElseIf test >= Asc("A") A

请你确认你要问的问题是什么,串口通讯问题? 还是数据转换或其它?
上面的代码基本上与串口通讯没什么关系,而且效率也不咋地,比如十六进制转化为整数,可以这么写:
Function ConvertHexChr(str As String) As Integer
on error goto Err '出错时跳转至行号为Err的代码处
converthexchr=val("&H" & str)'十六进制数在vb里的表示法:&H + 16进制数

exit function'跳出过程,在以上代码正确执行时,不执行错误处理代码。
Err:
converthexchr=-1'转换错误时返回-1
end function

你要的是什么?如果你要串口通讯的软件,我这里有完整的。