1.如何用VB的源码MScomm打开两端口(如COM2和3),并实现通信?
如何用VB的源码ue源码详解MScomm打开两端口(如COM2和3),并实现通信?
用以下代码检查你机器有几个COM口,源码读取粘贴源码那些COM口可用,那些不存在,
Option Explicit
Dim a As Integer
Private Sub Command1_Click()
On Error GoTo uerror
For a = 1 To 4
MSComm1.CommPort = a
MSComm1.PortOpen = True '当True时是打开
If MSComm1.PortOpen = True Then
Print "可用Com号= "; a
MSComm1.PortOpen = False 当False时是关闭
Else
End If
Next
Exit Sub
uerror:
If Err.Number = Then
Print "端口" & a & "已打开,请关闭其它应用程序占用的源码转换网站源码端口" & a
ElseIf Err.Number = Then
Print "出错Com号= "; a
End If
Resume Next
End Sub
以下代码使用COM2口和COM3口通信:
Option Explicit
Dim strData As String
Dim bytInput() As Byte
Dim dataSend() As Byte
Dim sj() As Byte
Dim i As Long
Dim Ulen As Long
Dim Llen As Long
Dim for_Sum As Long
Dim Yu_sum As Integer
Private Sub Form_Load() '初始化
Timer2.Interval =
MSComm1.Settings = ",n,8,1"
MSComm1.CommPort = 2
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
MSComm2.Settings = ",n,8,1"
MSComm2.CommPort = 3
MSComm2.RThreshold = 1
MSComm2.PortOpen = True
End Sub
Private Sub MsComm1_OnComm()
Dim intInputLen As Integer
Select Case Me.MSComm1.CommEvent
Case comEvReceive
'此处添加处理接收的代码
Me.MSComm1.InputMode = comInputModeBinary '二进制接收
intInputLen = Me.MSComm1.InBufferCount
ReDim bytInput(intInputLen)
bytInput = Me.MSComm1.Input
jieshou
End Select
End Sub
Public Function jieshou() '接收数据处理为进制字符
Dim i As Integer
For i = 0 To UBound(bytInput)
If Len(Hex(bytInput(i))) = 1 Then
strData = strData & "0" & Hex(bytInput(i))
Else
strData = strData & Hex(bytInput(i))
End If
Next
RichTextBox1 = strData
Text1 = Len(strData) \ 2
End Function
Private Sub Command2_Click()
Dim byts() As Byte
Dim l As Integer
byts(0) = &H1
byts(1) = &H
byts(2) = &H0
byts(3) = &H0
byts(4) = &HFF
For l = 5 To
byts(l) = - l + 5
Next
MSComm2.Output = byts
End Sub
2024-11-19 08:182543人浏览
2024-11-19 08:161959人浏览
2024-11-19 07:15692人浏览
2024-11-19 06:46823人浏览
2024-11-19 05:552114人浏览
2024-11-19 05:531836人浏览
1.Signatureï¼Checksumï¼Linkï¼ä»ä¹åºå«ï¼åºè¯¥ä¸è½½åªä¸ªï¼2.WSL2 安装并下载、编译AOSP源码3.第二届“祥云杯”
1.数据结构 BF算法数据结构 BF算法 建议动手画一画会比较直观 i,j是这里作位置指针 i指向SString S中的一个位置 j指向SString T的一个位置 while后的括号中是