Module1.bas
资源名称:VBTest.rar [点击查看]
上传用户:hbj111
上传日期:2022-07-30
资源大小:107k
文件大小:5k
源码类别:
串口编程
开发平台:
Visual Basic
- Attribute VB_Name = "Module1"
- Public Declare Function CloseAllConnect Lib "EdSockServer" () As Long
- Public Declare Function CloseConnect Lib "EdSockServer" (ByVal ConnectID As Long) As Long
- Public Declare Function OpenConnect Lib "EdSockServer" (ByVal PeerIP As String, ByVal PeerPort As Long, ByVal LocalIP As String, ByVal LocalPort As Long) As Long
- Public Declare Function GetLocalIP Lib "EdSockServer" (ByVal ConnectID As Long) As Long
- Public Declare Function GetLocalPort Lib "EdSockServer" (ByVal ConnectID As Long) As Long
- Public Declare Function GetMAC Lib "EdSockServer" (ByVal ConnectID As Long, ByVal lpMac As String, ByVal maclen As Long) As Long
- Public Declare Function GetModel Lib "EdSockServer" (ByVal ConnectID As Long) As Long
- Public Declare Function GetPeerIP Lib "EdSockServer" (ByVal ConnectID As Long) As Long
- Public Declare Function GetPeerPort Lib "EdSockServer" (ByVal ConnectID As Long) As Long
- Public Declare Function StartListen Lib "EdSockServer" (ByVal LocalIP As String, ByVal LocalPort As Long) As Long
- Public Declare Function IsSocket Lib "EdSockServer" () As Long
- Public Declare Function SendToCOM Lib "EdSockServer" (ByVal ConnectID As Long, ByVal COMNum As Long, ByVal pDataBuf As String, ByVal DataLength As Long) As Long
- Public Declare Function SetCallback Lib "EdSockServer" (ByVal lpOnAccept As Long, ByVal lpOnConnectClose As Long, ByVal lpOnError As Long, ByVal lpOnReceConfigData As Long, ByVal lpOnReceFromCOM As Long, ByVal lpOnSwitchChange As Long) As Long
- Public Declare Function SetSocket Lib "EdSockServer" (ByVal IsSocketValue As Long) As Long
- Public Declare Function StopListen Lib "EdSockServer" () As Long
- Public Declare Function mac_ntoa Lib "EdSockServer" (ByVal mac As String, ByVal maclen As Long, ByVal strmac As String, ByVal strlen As Long) As Long
- Public Declare Function LoadLibrary Lib "KERNEL32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
- Public Declare Function FreeLibrary Lib "KERNEL32" (ByVal hLibModule As Long) As Long
- Public Declare Function net_ntoa Lib "EdSockServer" (ByVal addr As Long, ByVal strBuf As String, ByVal strlen As Long) As Long
- Declare Sub RtlMoveMemory Lib "KERNEL32" (ByVal lpvDest As Long, ByVal lpvSource As Long, ByVal cbCopy As Long)
- Public g_AutoSendConnectID As Long
- Public g_bAutoSend As Boolean
- Public g_SendConnectID As Long
- Public g_IsSocket As Long
- Public g_hIns As Long
- Public g_lngTxCount As Long
- Public g_lngRxCount As Long
- Public Sub Send(ByVal ConnectID As Long)
- Dim strlen As Long
- strlen = Len(frmMain.txtTxData.Text)
- If (strlen = 0) Then Exit Sub
- If SendToCOM(ConnectID, 1, frmMain.txtTxData.Text, strlen) Then
- g_lngTxCount = g_lngTxCount + strlen
- frmMain.lblTxCount.Caption = CStr(g_lngTxCount)
- End If
- End Sub
- Public Sub OnAccept(ByVal ConnectID As Long)
- Dim model As Long
- Dim mac As String
- Dim ip As Long
- Dim port As Long
- mac = String(6, " ")
- model = GetModel(ConnectID)
- ip = GetPeerIP(ConnectID)
- port = GetPeerPort(ConnectID)
- GetMAC ConnectID, mac, 6
- AddItem ConnectID, mac, ip, port, model
- If (g_SendConnectID = 0) Then g_SendConnectID = ConnectID
- End Sub
- Public Function AddItem(ByVal ConnectID As Long, ByVal mac As String, ByVal ipAddr As Long, ByVal port As Long, ByVal model As Long) As Long
- Dim str As String
- Dim Item As ListItem
- With frmMain.ListView1
- str = CStr(ConnectID)
- Set Item = .ListItems.Add(, , str)
- str = String(20, " ")
- mac_ntoa mac, 6, str, 17
- Item.ListSubItems.Add 1, , str
- str = String(20, " ")
- net_ntoa ipAddr, str, 20
- Item.ListSubItems.Add 2, , str
- str = CStr(port)
- Item.ListSubItems.Add 3, , str
- str = CStr(model)
- Item.ListSubItems.Add 4, , str
- Item.Tag = CStr(ConnectID)
- End With
- End Function
- Public Sub OnConnectClose(ByVal ConnectID As Long)
- Dim str As String
- Dim i As Long
- str = CStr(ConnectID)
- With frmMain.ListView1
- For i = 1 To .ListItems.Count
- If .ListItems(i).Tag = str Then
- .ListItems.Remove i
- Exit For
- End If
- Next
- If ConnectID = g_SendConnectID Then
- If .ListItems.Count = 0 Then
- g_SendConnectID = 0
- End If
- End If
- End With
- End Sub
- Public Sub OnReceFromCOM(ByVal ConnectID As Long, ByVal COMNum As Long, ByVal pDataBuf As Long, ByVal DataLength As Long)
- Dim str As String
- Dim txtLen As Long
- If (g_AutoSendConnectID = 0 And g_SendConnectID = ConnectID) Or g_AutoSendConnectID = ConnectID Then
- If frmMain.chkStopShow.Value = 0 Then
- str = String(DataLength, " ")
- RtlMoveMemory StrPtr(str), pDataBuf, DataLength
- str = StrConv(str, vbUnicode)
- str = Left(str, DataLength)
- frmMain.txtRxData.Text = frmMain.txtRxData.Text + str
- txtLen = Len(frmMain.txtRxData.Text)
- If (txtLen > 3000) Then txtLen = txtLen - 3000
- frmMain.txtRxData.Text = Right$(frmMain.txtRxData.Text, txtLen)
- End If
- g_lngRxCount = g_lngRxCount + DataLength
- frmMain.lblRxCount.Caption = CStr(g_lngRxCount)
- End If
- End Sub