7,763
社区成员
发帖
与我相关
我的任务
分享
Public Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public xywhExitThread As Boolean
Dim url(20) As String, Temp, dd, j, cc(200), tou, wei
Sub test()
Static i_len As Integer
Dim INByte() As Byte
Dim Buf As String, a, n
Dim btLoCRC As Byte, btHiCRC As Byte
Dim Data As Integer
l = 0
url(0) = 20002
getd url(0) '这里调用另一模块的方法
Do While l = 0
Form1.Controls("Winsock" & 2).SendData bisend
te: Sleep 1300
i_len = Winsock2.BytesReceived
If i_len = 0 Then
GoTo te
Form1.Shape2.BackColor = &H8000000F
Form1.Command7.Caption = "开始监听"
'Exit Sub
End If
If i_len > 10 Then
Form1.Shape2.BackColor = &HFF00&
Form1.Command7.Caption = "停止监听"
End If
If Buf = a7 Then wmFF (16022)
If Len(Buf) > 25 Then
Form1.Winsock2.GetData INByte
If INByte(1) = 3 Then '读寄存器
'CRC校验
crc = CRC16(INByte, UBound(INByte) - LBound(INByte) - 1, btLoCRC, btHiCRC)
If INByte(UBound(INByte) - 1) = btLoCRC And INByte(UBound(INByte)) = btHiCRC Then
For i = 3 To UBound(INByte) - 2 Step 2
Data = "&h" + Hex(INByte(i)) + Hex(INByte(i + 1))
Buf = Buf + Str(Data) '转换为十进制显示
Next i
Form1.Text6.Text = Text6.Text & Buf
n = chrasc(Buf)
a = Left(n, 2)
Select Case a
Case "$$"
uid2 = Left(n, 6)
url(0) = 20202
GoTo re1
Case "Q0"
num2 = n
a7 = Buf
url(0) = 20202
GoTo re1
End Select
End If
re1: If uid2 <> "" And num2 <> "" Then
Exit Do
Form1.read (2)
Exit Sub
End If
End If
End If
Loop
End Sub
Public Function getd(sr As String)
Dim bisend() As Byte
Dim crc, X, Y
Dim btLoCRC As Byte, btHiCRC As Byte
Dim Data As Integer
ReDim bisend(7)
X = Left(sr, 4)
Y = Mid(sr, 5, Len(sr))
A1 = Hex(&H8000& + CLng(X))
A2 = Mid(A1, 1, 2)
A3 = Mid(A1, 3, 2)
bisend(0) = "&h" + Hex(2)
bisend(1) = "&h" + Hex(3)
bisend(2) = "&h" + A2
bisend(3) = "&h" + A3
bisend(4) = "&h" + Hex(0)
bisend(5) = "&h" + Hex(8)
crc = CRC16(bisend, 6, btLoCRC, btHiCRC)
bisend(6) = "&h" + Hex(btLoCRC)
bisend(7) = "&h" + Hex(btHiCRC)
Form1.Controls("Winsock" & Y).SendData bisend
End Function
Public Function getd(sr As String)
'...............
dim frm as form
for each frm in forms
if frm.name="Form1" then exit for
next
frm.Controls("Winsock" & Y).SendData bisend
set frm=nothing
end function
dim frm as form
for each frm in forms
if frm.name="form1" then exit for
next
getd url(0),frm '这里调用另一模块的方法
set frm=nothing
Public Function getd(sr As String, frm as object)
'...............
frm.Controls("Winsock" & Y).SendData bisend
end function
'在调用窗口,把当前窗口作为参数传进来
getd str,me