从来不会用串口控件,也不知道对不对Private Sub Command1_Click() Dim aa(0 To 10) As Byte MSComm1.Output = aa End SubPrivate Sub Form_Load() MSComm1.CommPort = 1 '通道1 MSComm1.Settings = "9600,N,8,1" '"9600,N,8,1" MSComm1.PortOpen = True '打开串口 MSComm1.RThreshold = 1 '一个字符产生 OnComm 事件 End Sub
Private Sub Command1_Click() Dim iStr1 As String Dim iStr2() As String Dim iStr3() As Byte Dim i As Integer iStr1 = "10 02 55 fa 03 00 00 00 d1 b1 10 03" 'iStr1中就是你要发送的数据 iStr2 = Split(iStr1) ReDim iStr3(UBound(iStr2)) For i = 0 To UBound(iStr2) iStr3(i) = "&H" & iStr2(i) Next MSComm1.Output = iStr3 '将处理后的数据用MSComm控件发送出去。 End Sub 下边是根据你自己的要求对MSComm控件进行设置,至于MSComm下边属性的详细意思到网上一查就说的很清楚了。 With MSComm1 .CommPort = 1 .Settings = "9600,n,8,1" .InBufferCount = 0 .InputLen = 0 .RThreshold = 1 .InputMode = comInputModeBinary '以2进制接收 .PortOpen = True End With
Dim aa(100) As Byte . . . MSComm1.Output = aa
dim aa(100) as byte dim bb . . . bb=aa MSComm1.Output = bb
Dim aa(0 To 10) As Byte
MSComm1.Output = aa
End SubPrivate Sub Form_Load()
MSComm1.CommPort = 1 '通道1
MSComm1.Settings = "9600,N,8,1" '"9600,N,8,1"
MSComm1.PortOpen = True '打开串口
MSComm1.RThreshold = 1 '一个字符产生 OnComm 事件
End Sub
Dim iStr1 As String
Dim iStr2() As String
Dim iStr3() As Byte
Dim i As Integer
iStr1 = "10 02 55 fa 03 00 00 00 d1 b1 10 03" 'iStr1中就是你要发送的数据
iStr2 = Split(iStr1)
ReDim iStr3(UBound(iStr2))
For i = 0 To UBound(iStr2)
iStr3(i) = "&H" & iStr2(i)
Next
MSComm1.Output = iStr3 '将处理后的数据用MSComm控件发送出去。
End Sub
下边是根据你自己的要求对MSComm控件进行设置,至于MSComm下边属性的详细意思到网上一查就说的很清楚了。
With MSComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.InBufferCount = 0
.InputLen = 0
.RThreshold = 1
.InputMode = comInputModeBinary '以2进制接收
.PortOpen = True
End With
.
.
.
MSComm1.Output = aa
dim bb
.
.
.
bb=aa
MSComm1.Output = bb