发表于:2006-07-13 15:04:00
1楼
参考以下串口收发程序,或许会有收获!
Private Sub Button_RECV_C_Click()
Text_RECV.Text = ""
Text_SEND.SetFocus
End Sub
Private Sub Button_SEND_C_Click()
Text_SEND.Text = ""
Text_SEND.SetFocus
End Sub
Private Sub Button_SEND_Click()
Dim x As String
If Text_SEND.Text = "" Then
x = MsgBox("发送数据不能为空", 16)
Exit Sub
End If
If Not MSComm.PortOpen Then
MSComm.PortOpen = True
End If
MSComm.Output = Text_SEND.Text + Chr$(13)
For i = 1 To 20000000
Next
End Sub
Private Sub Form_Load()
MSComm.CommPort = 1
MSComm.Settings = "9600,n,8,1"
MSComm.InputLen = 0
MSComm.InBufferSize = 1024
MSComm.OutBufferSize = 512
MSComm.PortOpen = True
MSComm.SThreshold = 0
MSComm.RThreshold = 1
MSComm.InBufferCount = 0
MSComm.OutBufferCount = 0
Text_SEND.Text = ""
Text_RECV.Text = ""
End Sub
Private Sub MSComm_OnComm()
Select Case MSComm.CommEvent
Case comEventOverun
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEventRxOver
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEventTxFull
Text_SEND.Text = ""
Text_RECV.Text = ""
Text_SEND.SetFocus
Exit Sub
Case comEvReceive
Dim str As String
str = MSComm.Input
Text_RECV.Text = Text_RECV.Text + str
End Select
End Sub