📄 module1.bas
字号:
Attribute VB_Name = "Module1"
Public T_E0(128) As Byte
'public T_E1(128) as byte
Public T_OFFSET0 As Integer
'public T_OFFSET1 as integer
Public T_CMD0 As Boolean
'public T_CMD1 as boolean
Public T_PNAME(31) As String
Public T_IP(31) As String
Public T_SN(31) As Integer
Public T_TMP(31, 31) As Double
Public T_WET(31, 31) As Double
Public T_FIRE(31) As Integer
Function gettem(t() As Byte, n As Integer) '接收到的数据为参数,获得第n个传感器的温度
Dim tem As Double
Dim offset As Integer
offset = 4 * n + 8
If (t(offset) And &H4) = &H4 Then
tem = tem + 64
End If
If (t(offset) And &H2) = &H2 Then
tem = tem + 32
End If
If (t(offset) And &H1) = &H1 Then
tem = tem + 16
End If
If (t(offset - 1) And &H80) = &H80 Then
tem = tem + 8
End If
If (t(offset - 1) And &H40) = &H40 Then
tem = tem + 4
End If
If (t(offset - 1) And &H20) = &H20 Then
tem = tem + 2
End If
If (t(offset - 1) And &H10) = &H10 Then
tem = tem + 1
End If
If (t(offset - 1) And &H8) = &H8 Then
tem = tem + 0.5
End If
If (t(offset - 1) And &H4) = &H4 Then
tem = tem + 0.25
End If
If (t(offset - 1) And &H2) = &H2 Then
tem = tem + 0.125
End If
If (t(offset - 1) And &H1) = &H1 Then
tem = tem + 0.0625
End If
gettem = tem
End Function
Function getwet(t() As Byte, n As Integer) '接收到的数据为参数,获得第n个传感器的湿度
Dim offset As Integer
offset = 6 + 4 * n
getwet = CInt(t(offset)) / 2
End Function
Function testfire(t() As Byte)
If t(5) = 13 Then
testfire = -1
Else
testfire = CInt(t(6))
End If
End Function
Function read_conf() '读配置文件并将配置填入全局变量
Dim strT_SN As String
Dim n As Integer
Open "conf.txt" For Input As #1
n = 0
While EOF(1) = False
Line Input #1, T_PNAME(n)
Line Input #1, T_IP(n)
Line Input #1, strT_SN
T_SN(n) = Val(strT_SN)
n = n + 1
Wend
read_conf = 2
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -