VB 串口通讯 事件监听 问题
mQney 2009-12-24 08:42:50 请问大家,我这个方法在页面中为什么不能够监听发送事件?
Private Sub GetData() '打开通讯串口
Dim ls_bm As String
Dim Ls_Band As String, Ls_Check As String, ls_Data As String, Ls_Stop As String, Ls_Port As String
ls_bm = "select * from t_band"
AdoRes ls_bm
If Not gLocalRes.EOF Then
Ls_Band = NUL(gLocalRes("bandP")) '速率
Ls_Check = NUL(gLocalRes("checkP")) '校验位
ls_Data = NUL(gLocalRes("dataP")) '数据位
Ls_Stop = NUL(gLocalRes("stopp")) '停止位
Ls_Port = NUL(gLocalRes("portP")) '端口号
Ls_Band = Ls_Band + "," + Ls_Check + "," + ls_Data + "," + Ls_Stop
MS_Set.CommPort = CInt(Ls_Port)
MS_Set.Settings = Ls_Band
End If
gLocalRes.Close
End Sub
Private Sub MS_Set_OnComm()
Static lbl_flag As Boolean
Dim vReceive As Variant
Dim ll_pos As Long, ll_kk As Long
Dim vDispose As Variant
Dim ll_RecieveLen As Long, arr() As Byte
Select Case MS_Set.CommEvent '错误
Case comEventBreak ' 收到 Break。
Case comEventCDTO ' CD (RLSD) 超时
Case comEventCTSTO ' CTS Timeout。
Case comEventDSRTO ' DSR Timeout。
Case comEventFrame ' Framing Error
Case comEventOverrun ' 数据丢失。
Case comEventRxOver ' 接收缓冲区溢出。
Case comEventRxParity ' Parity 错误。
Case comEventTxFull ' 传输缓冲区已满。
Case comEventDCB ' 获取 DCB] 时意外错误
'事件
Case comEvCD ' CD 线状态变化。
Case comEvCTS ' CTS 线状态变化。
Case comEvDSR ' DSR 线状态变化。
Case comEvRing ' Ring Indicator 变化。
Case comEvReceive ' 收到 RThreshold # of chars.
vReceive = MS_Set.Input
arr = vReceive
ll_RecieveLen = LenB(vReceive)
For ll_pos = 1 To ll_RecieveLen
If arr(ll_pos - 1) = 2 Then '开始字符
lbl_err.Caption = "开始接收数据......"
Timer2.Enabled = True
Timer2.Interval = 3000
vRec = ""
vRec = vRec + Mid(vReceive, ll_pos)
Exit Sub
End If
If arr(ll_pos - 1) = 3 Then '结束字符
lbl_err.Caption = "处理数据......"
vDispose = vRec + Left(vReceive, ll_pos)
If Len(vDispose) < 39 Then
lbl_err.Caption = "不是接收数据,等待接收..."
Timer2.Enabled = False
Exit Sub
End If
vRec = Right(vReceive, ll_pos)
CheckValue vDispose
Exit Sub
End If
Next
vRec = vRec + vReceive
Text1.Text = vRec
Case comEvSend ' 传输缓冲区有 Sthreshold 个字符
End Select
End Sub