该控件的ONCOMM事件有一个值1001对应的是收到断开信号,这是为什么?该如何处理该通信错误呢?
解决方案 »
- 自已用VB做的俄罗斯方块,共同学习
- [有个超级菜问题...惭愧发问了]DateDiff中有没有interval可以表示“分钟”的??"m"表示的好象是月份,晕。。。
- 请问如何用VB调用AutoCAD里面的图形呢?
- 怎样inet1控制,从客户端上传文件到服务端呢?
- 如何捕捉mshflexgrid中用鼠标改变单元宽窄的事件?
- 如何删除非空文件夹。
- 编辑ADO数据库系统提示“jet引擎找不到表”但再逐步调试又可以了
- 如何做出点击任务栏QQ弹出的菜单中那条长的图片和每个选项旁边那个小图标?
- commmondialog 的shoufont参数调用后,为何提示字体没有,要重装字体,怎样解决
- 我找了整个CSDN都没发现那张帖子,我想知道怎么把WEBBROWSER的网页存盘而不通知用户
- RichTextBox
- 请教:把一个界面的值加到另一个界面的comboBOX上。combobox值并不保存
ST = MSComm1.Input'不用处理它,就用这个input来清空接收缓冲区就行
end if
Const Xoff = &H13 Private Sub Form_Load()
Form1.Caption = "App2"
With MSComm1
.CommPort = 2
.Handshaking = 2 - comRTS
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.PortOpen = True
End With
Text1.Text = ""
Label1.Caption = "No input yet"
End Sub Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub Private Sub MSComm1_OnComm()
Dim InBuff As String Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement. ' This template is found in the Example
' section of the OnComm event help topic
' in VB help. ' Errors
Case comEventBreak ' A Break was received.
Case comEventCDTO ' CD (RLSD) Timeout.
Case comEventCTSTO ' CTS Timeout.
Case comEventDSRTO ' DSR Timeout.
Case comEventFrame ' Framing Error
Case comEventOverrun ' Data Lost.
Case comEventRxOver ' Receive buffer overflow.
Case comEventRxParity ' Parity Error.
Case comEventTxFull ' Transmit buffer full.
Case comEventDCB ' Unexpected error retrieving DCB] ' Events
Case comEvCD ' Change in the CD line.
Case comEvCTS ' Change in the CTS line.
Case comEvDSR ' Change in the DSR line.
Case comEvRing ' Change in the Ring Indicator.
Case comEvReceive ' Received RThreshold # of chars.
Label1.Caption = "Input"
InBuff = MSComm1.Input
Call ParseChars(InBuff)
Case comEvSend ' There are SThreshold number of
' characters in the transmit
' buffer.
Case comEvEOF ' An EOF character was found in
' the input stream.
End Select End Sub Sub HandleInput(InBuff As String)
' This is where you will process your input. This
' includes trapping characters, parsing strings,
' separating data fields, etc. For this case, you
' are simply going to display the data in the text
' box. Text1.Text = Text1.Text & InBuff
End Sub Sub ParseChars(ByVal InString As String)
Dim temp As String
Dim x As Long
Dim OutString as String For x = 1 To Len(InString)
temp = Mid$(InString, x, 1)
If temp = Chr$(Xoff) Then
Label1.ForeColor = vbRed
Label1.Caption = "Xoff received"
temp = ""
ElseIf temp = Chr$(Xon) Then
Label1.ForeColor = vbGreen
Label1.Caption = "Xon received"
temp = ""
End If
OutString = OutString & temp
temp = ""
Next x
Call HandleInput(OutString)
End Sub
我用的是mscomm1.inbuffercount=0来清除了缓冲区,结果,程序在此处会有短时间的'死掉',稍后继续运行。
如何处理比较妥当呢?