1.VB6.0中的串口程序串口串口通讯
2.如何用VB6.0通过串口从电子秤中获取数据?
VB6.0中的串口通讯
Dim Buffer As Variant
Dim Arr() As Byte
' 设定并开启连接埠
MSComm1.CommPort = 1
' 连线速度 baud、无同位检查、通信通讯首板寻妖副图指标源码资料位元 8、源码米表网站源码停止位元 1
MSComm1.Settings = ",串口程序串口神仙道网站源码N,8,1"
告诉控制项当使用 Input 时,读取整个暂存区
MSComm1.InputLen = 0
MSComm1.PortOpen = True
' 设定 InputMode 以读取二进制模式
MSComm1.InputMode = comInputModeBinary
' 等待直到输入缓冲区有 个字节
Do Until MSComm1.InBufferCount <
DoEvents
Loop
' 将二进制数据放入Buffer中
Buffer = MSComm1.Input
' 把数据给指定的通信通讯php整源码调试数组
Arr = Buffer
MSComm1.PortOpen = False
' 通过Arr(5) 就可以得到第N个元素了
如何用VB6.0通过串口从电子秤中获取数据?
Option Explicit
Dim strss As String
Private Sub Form_Load()
MSComm1.CommPort = 1 '串口号,
MSComm1.Settings = ",源码灰色顶目源码n,8,1 " '串口的属性
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
strss = strss & MSComm1.Input
If Right(strss, 2) = vbCrLf Then
Label1.Caption = strss
Open "D:\DATA.txt" For Append As #1
Print #1, Mid(strss, 1, Len(strss) - 2) '去除回车换行
Close
strss = ""
End If
End Select
End Sub