急问VB串口程序

来源:百度知道 编辑:UC知道 时间:2024/07/02 08:11:33
要求利用232通信,传输数字,字母和汉字

望高手赐教!!!

使用MSCOMM控件:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub cmdsent_Click()
Dim strsent As String
strsent = txtsent.Text
MsComm1.Output = strsent
End Sub

Private Sub Mscomm2_OnComm()
Dim jieshou As String
Select Case MsComm2.CommEvent
Case comEvReceive
Sleep (30) '延迟
'comreceive.InputMode = comInputModeText 'ASCII接收
jieshou = MsComm2.Input
txtreceive.Text = jieshou
End Select
End Sub
Private Sub Form_Load()
With MsComm1
.InBufferSize = 5120
.CommPort = 1
.Settings = "9600,N,8,1"
.InputMode = comInputModeText
.RThreshold = 0
.PortOpen = True
End With

With MsComm2
.InBufferSize = 5120
.CommPort = 2<