⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtmo.bas

📁 使用Microsoft Visual Basic编写实现中国联通SGIP 2.0协议的源代码
💻 BAS
字号:
Attribute VB_Name = "mtmo"
Option Explicit




'获取命令ID
Public Function GetID(Bins() As Byte) As Long
Dim Flag As Integer
Dim i As Integer
Dim R As Long
Flag = 1
If Bins(0) = &H80 Then Flag = -1
R = 0
For i = 1 To 3
    R = R * 256 + Bins(i)
Next

GetID = Flag * R

End Function

'获取时间
Public Function SetTime() As Double

Dim Ttime As String
Dim Tint As Integer
Dim mydate As Date

Ttime = Month(Date)

Tint = Day(Date)
If Tint < 10 Then Ttime = Ttime & "0"
Ttime = Ttime & Tint

Tint = Hour(Time)
If Tint < 10 Then Ttime = Ttime & "0"
Ttime = Ttime & Tint

Tint = Minute(Time)
If Tint < 10 Then Ttime = Ttime & "0"
Ttime = Ttime & Tint

Tint = Second(Time)
If Tint < 10 Then Ttime = Ttime & "0"
Ttime = Ttime & Tint

SetTime = Ttime

End Function


Public Function FormatTime(dTime As Double) As String

Dim Str As String
Dim Rtn As String
Dim i As Integer

Str = dTime
Rtn = Year(Date)

For i = 1 To 4 Step 2
    Rtn = Rtn & "-" & Mid(Str, i, 2)
    
Next

Rtn = Rtn & " " & Mid(Str, 5, 2)

For i = 7 To 10 Step 2
    Rtn = Rtn & ":" & Mid(Str, i, 2)
    
Next

FormatTime = Rtn

End Function


Public Function inc(ByVal i As Long) As Long '返回i+1
'序号加一
    Select Case i
    Case &H7FFFFFFF
        inc = &H80000000
        Exit Function
    Case &HFFFFFFFF
        inc = 0
        Exit Function
    Case Else
        inc = i + 1
    End Select
End Function

Public Sub Send_4byte(ByVal d As Long, sck As Winsock) 'send a long data,htonl
Dim i As Byte
Dim b(3) As Integer
Dim f As Byte 'sign flag
f = 0

If d < 0 Then
    f = &H80
    d = d And &H7FFFFFFF
End If

For i = 0 To 3
    b(i) = d Mod 256
    d = d \ 256
Next
sck.SendData CByte(b(3) And 255) Or f
sck.SendData CByte(b(2) And 255)
sck.SendData CByte(b(1) And 255)
sck.SendData CByte(b(0) And 255)
End Sub


Public Function SendHead(Lens As Long, IDs As Long, Nums As Long, sck As Winsock) As Boolean
'lens 包总长度    Nums递增序号

'总长度
Send_4byte Lens, sck
'命令
Send_4byte IDs, sck

'节点号
sck.SendData JieDian

'时间
Send_4byte SetTime, sck

'递增序号
Send_4byte Nums, sck


End Function

Public Function SendHeadResp(Lens As Long, IDs As Long, nos() As Byte, sck As Winsock) As Boolean
'lens 包总长度    Nums递增序号

'总长度
Send_4byte Lens, sck
'命令
Send_4byte IDs, sck

'原序列号
sck.SendData nos


End Function


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -