|
Dim rID
Dim lap() As Byte
Private Sub Command1_Click()
Dim ip As String
Dim port As String
ip = Text1.Text
port = Text2.Text
With Winsock1
If .State = 0 Then
.RemoteHost = ip
.RemotePort = port
.Connect
Command1.Caption = "断开"
Else
.Close
Command1.Caption = "连接"
End If
End With
End Sub
Private Sub Command2_Click()
Dim temp() As String
Dim sendmsg() As Byte
Dim s As Integer
s = 0
msg = "09 00 48 BC 44 56 FE 01 00"
temp = Split(msg, " ")
For i = 0 To UBound(temp)
If Len(temp(i)) > 0 Then
temp(i) = "&H" & temp(i)
ReDim Preserve sendmsg(s)
sendmsg(s) = Val(temp(i))
s = s + 1
End If
Next
List1.Clear
ReDim lap(2, 0)
Winsock1.SendData sendmsg
End Sub
Private Sub Command3_Click()
If List1.ListIndex < 0 Then Exit Sub
Dim temp() As String
Dim sendmsg() As Byte
Dim s As Integer
s = 0
msg = "16 00 48 bc 44 56 fe 82 0d 02 ff ff 00 00 00 00 00 00 0b 00 00 01"
temp = Split(msg, " ")
For i = 0 To UBound(temp)
If Len(temp(i)) > 0 Then
temp(i) = "&H" & temp(i)
ReDim Preserve sendmsg(s)
sendmsg(s) = Val(temp(i))
s = s + 1
End If
Next
sendmsg(10) = lap(0, List1.ListIndex)
sendmsg(11) = lap(1, List1.ListIndex)
sendmsg(18) = lap(2, List1.ListIndex)
Winsock1.SendData sendmsg
End Sub
Private Sub Command4_Click()
If List1.ListIndex < 0 Then Exit Sub
Dim temp() As String
Dim sendmsg() As Byte
Dim s As Integer
s = 0
msg = "16 00 48 bc 44 56 fe 82 0d 02 ff ff 00 00 00 00 00 00 0b 00 00 00"
temp = Split(msg, " ")
For i = 0 To UBound(temp)
If Len(temp(i)) > 0 Then
temp(i) = "&H" & temp(i)
ReDim Preserve sendmsg(s)
sendmsg(s) = Val(temp(i))
s = s + 1
End If
Next
sendmsg(10) = lap(0, List1.ListIndex)
sendmsg(11) = lap(1, List1.ListIndex)
sendmsg(18) = lap(2, List1.ListIndex)
Winsock1.SendData sendmsg
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Winsock1.Close
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strGet() As Byte
ReDim strGet(bytesTotal - 1)
Dim ccom As String
Winsock1.GetData strGet '注释:读取到达的数据
Text3.Text = strGet
Select Case strGet(0)
Case 1
x = 2
j = List1.ListCount
While x < UBound(strGet)
ReDim Preserve lap(2, j)
List1.AddItem ("灯" & Str(List1.ListCount))
For i = 0 To 2
lap(i, j) = strGet(x + i)
Debug.Print lap(i, j);
Next
Debug.Print
x = x + strGet(x - 1) + 2
j = j + 1
Wend
End Select
End Sub
开关灯的VB6.0原码自写的。呵呵。 |
|