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

📄 adamtcp.bas

📁 基于化工行业造气岗位的自动化监控系统
💻 BAS
字号:
Attribute VB_Name = "ADAMTCP"
Global Const ADAMTCP_NoError = 0
Global Const ADAMTCP_StartupFailure = (-1)
Global Const ADAMTCP_SocketFailure = (-2)
Global Const ADAMTCP_UdpSocketFailure = (-3)
Global Const ADAMTCP_SetTimeoutFailure = (-4)
Global Const ADAMTCP_SendFailure = (-5)
Global Const ADAMTCP_ReceiveFailure = (-6)
Global Const ADAMTCP_ExceedMaxFailure = (-7)
Global Const ADAMTCP_CreateWsaEventFailure = (-8)
Global Const ADAMTCP_ReadStreamDataFailure = (-9)
Global Const ADAMTCP_InvalidIP = (-10)
Global Const ADAMTCP_ThisIPNotConnected = (-11)
Global Const ADAMTCP_AlarmInfoEmpty = (-12)
Global Const ADAMTCP_NotSupportModule = (-13)
Global Const ADAMTCP_ExceedDONo = (-14)
Global Const ADAMTCP_InvalidRange = (-15)
Global Const ADAMTCP_BI_10V = 0
Global Const ADAMTCP_BI_5V = 1        ' -5V ~ 5V
Global Const ADAMTCP_BI_2Point5V = 2  ' -2.5V ~ 2.5V
Global Const ADAMTCP_BI_1V = 3        ' -1V ~ 1V
Global Const ADAMTCP_BI_500mV = 4     ' -500mV ~ 500mV
Global Const ADAMTCP_BI_150mV = 5     ' -150mV ~ 150mV
Global Const ADAMTCP_BI_100mV = 6     ' -100mV ~ 100mV
Global Const ADAMTCP_BI_50mV = 7      ' -50mV ~ 50mV
Global Const ADAMTCP_BI_15mV = 8      ' -15mV ~ 15mV
Global Const ADAMTCP_UNI_4TO20mA = 9  ' 4 ~ 20mA
Global Const ADAMTCP_UNI_0TO20mA = 10 ' 0 ~ 20mA
Global Const ADAMTCP_BI_20mA = 11     ' -20 ~ 20mA
Global Const ADAMTCP_TypeB = 20       ' TypeB 500-1800'C
Global Const ADAMTCP_TypeE = 21       ' TypeE 0-1000'C
Global Const ADAMTCP_TypeJ = 22       ' TypeJ 0-760'C
Global Const ADAMTCP_TypeK = 23       ' TypeK 0-1370'C
Global Const ADAMTCP_TypeR = 24       ' TypeR 500-1750'C
Global Const ADAMTCP_TypeS = 25       ' TypeS 500-1750'C
Global Const ADAMTCP_TypeT = 26       ' TypeT -100 to 400'C
Global Const ADAMTCP_ReceiveStreamIngoreAlarm = 0
Global Const ADAMTCP_ReceiveStreamWhenAlarm = 1
Type TypeOfStreamData
    DIO(0 To 7) As Integer
    Slot0(0 To 7) As Integer
    Slot1(0 To 7) As Integer
    Slot2(0 To 7) As Integer
    Slot3(0 To 7) As Integer
    Slot4(0 To 7) As Integer
    Slot5(0 To 7) As Integer
    Slot6(0 To 7) As Integer
    Slot7(0 To 7) As Integer
End Type
Type TypeOfAlarmInfo
    bySlot         As Byte
    byChannel      As Byte
    byAlarmType    As Byte
    byAlarmaStatus As Byte
    byIndexOf5KTCP As Byte
    szIP           As String * 20
    szDataTime     As String * 48
End Type
Declare Function ADAMTCP_Open Lib "ADAMTCP.dll" () As Long
Declare Function ADAMTCP_Connect Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal Port As Integer, _
                                            ByVal ConnectionTimeout As Long, ByVal SendTimeout As Long, ByVal ReceiveTimeout As Long) As Long
Declare Sub ADAMTCP_Disconnect Lib "ADAMTCP.dll" ()
Declare Function ADAMTCP_GetDLLVersion Lib "ADAMTCP.dll" () As Long
Declare Function ADAMTCP_ReadReg Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal wIDAddress As Integer, ByVal wStartAddress As Integer, _
                                                                ByVal wCount As Integer, wData As Integer) As Long
Declare Function ADAMTCP_WriteReg Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal wIDAddress As Integer, ByVal wStartAddress As Integer, _
                                                                ByVal wCount As Integer, wData As Integer) As Long
Declare Function ADAMTCP_ReadCoil Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal wIDAddress As Integer, ByVal wStartAddress As Integer, _
                                                                ByVal wCount As Integer, byData As Byte) As Long
Declare Function ADAMTCP_WriteCoil Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal wIDAddress As Integer, ByVal wStartAddress As Integer, _
                                                                ByVal wCount As Integer, byData As Byte) As Long
Declare Function ADAMTCP_SendReceive5KTCPCmd Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                ByVal szSend As String, ByVal szResult As String, ByVal szModbusSend As String, ByVal szModbusReceive As String) As Long
                
Declare Function ADAMTCP_AddTCPForStream Lib "ADAMTCP.dll" (ByVal IPAddress As String) As Long
Declare Function ADAMTCP_ReadStreamData Lib "ADAMTCP.dll" (ByVal IPAddress As String, StreamData As TypeOfStreamData) As Long
Declare Function ADAMTCP_ReadAlarmInfo Lib "ADAMTCP.dll" (AlarmInfo As TypeOfAlarmInfo) As Long
Declare Function ADAMTCP_StartStream Lib "ADAMTCP.dll" (hEvent As Long) As Long
Declare Function ADAMTCP_StopStream Lib "ADAMTCP.dll" () As Long
Declare Function ADAMTCP_SetStreamAlarmState Lib "ADAMTCP.dll" (ByVal wStreamAlarmState As Integer) As Long
Declare Function ADAMTCP_Debug Lib "ADAMTCP.dll" (iMatchIndex%, iReceiveCount%, iThreadRun%, iTotalStream%, ByVal szFromIP As String) As Long
Declare Function ADAMTCP_UDPOpen Lib "ADAMTCP.dll" (ByVal SendTimeout As Long, ByVal ReceiveTimeout As Long) As Long
Declare Function ADAMTCP_UDPClose Lib "ADAMTCP.dll" () As Long
Declare Function ADAMTCP_SendReceiveUDPCmd Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                ByVal szSend As String, ByVal szResult As String) As Long
Declare Function ADAMTCP_Read6KDIO Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, byDI As Byte, byDO As Byte) As Long
Declare Function ADAMTCP_Write6KDO Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, ByVal wStartDO As Integer, ByVal wCount As Integer, byDO As Byte) As Long
Declare Function ADAMTCP_Read6KAI Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, wGain As Integer, wHex As Integer, fValue As Double) As Long
Declare Function ADAMTCP_Read6KDIOMode Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, byDIMode As Byte, byDOMode As Byte) As Long
Declare Function ADAMTCP_Write6KDIOMode Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, byDIMode As Byte, byDOMode As Byte) As Long
Declare Function ADAMTCP_Read6KSignalWidth Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, ulLoWidth As Long, ulHiWidth As Long) As Long
Declare Function ADAMTCP_Write6KSignalWidth Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, ulLoWidth As Long, ulHiWidth As Long) As Long
                                                                 
Declare Function ADAMTCP_Read6KCounter Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, ulCounterValue As Long) As Long
Declare Function ADAMTCP_Clear6KCounter Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wIDAddress As Integer, ByVal wChIndex As Integer, wData As Integer) As Long
                                                                 
Declare Function ADAMTCP_Start6KCounter Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wIDAddress As Integer, ByVal wChIndex As Integer) As Long
Declare Function ADAMTCP_Stop6KCounter Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wIDAddress As Integer, ByVal wChIndex As Integer) As Long
Declare Function ADAMTCP_Read6KPulseDelayWidth Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wModule As Integer, ByVal wIDAddress As Integer, _
                                                                 ulLoPulseWidth As Long, ulHiPulseWidth As Long, _
                                                                 ulLoDelayWidth As Long, ulHiDelayWidth As Long) As Long
Declare Function ADAMTCP_Clear6KDILatch Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal wIDAddress As Integer, ByVal wChIndex As Integer) As Long
Declare Function ADAMTCP_SendReceive6KTCPCmd Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                 ByVal szSend As String, ByVal szResult As String, ByVal szModbusSend As String, ByVal szModbusReceive As String) As Long
                
'**********************************************************
'--------------- the functions for ADAM-5000 only ---------

Declare Function ADAM5KTCP_Open Lib "ADAMTCP.dll" () As Long
'Declare Sub ADAM5KTCP_Close Lib "ADAMTCP.dll" ()
Declare Function ADAM5KTCP_Connect Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal Port As Integer, _
                                                                ByVal ConnectionTimeout As Long, ByVal SendTimeout As Long, ByVal ReceiveTimeout As Long) As Long
Declare Sub ADAM5KTCP_Disconnect Lib "ADAMTCP.dll" ()
Declare Function ADAM5KTCP_GetDLLVersion Lib "ADAMTCP.dll" () As Long
Declare Function ADAM5KTCP_ReadReg Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal wIDAddress As Integer, ByVal wStartAddress As Integer, _
                                                                ByVal wCount As Integer, wData As Integer) As Long
Declare Function ADAM5KTCP_WriteReg Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal wIDAddress As Integer, ByVal wStartAddress As Integer, _
                                                                ByVal wCount As Integer, wData As Integer) As Long
Declare Function ADAM5KTCP_ReadCoil Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal wIDAddress As Integer, ByVal wStartAddress As Integer, _
                                                                ByVal wCount As Integer, byData As Byte) As Long
Declare Function ADAM5KTCP_WriteCoil Lib "ADAMTCP.dll" (ByVal IPAddress As String, ByVal wIDAddress As Integer, ByVal wStartAddress As Integer, _
                                                                ByVal wCount As Integer, byData As Byte) As Long
Declare Function ADAM5KTCP_SendReceive5KTCPCmd Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                ByVal szSend As String, ByVal szResult As String, ByVal szModbusSend As String, ByVal szModbusReceive As String) As Long
                
Declare Function ADAM5KTCP_AddTCPForStream Lib "ADAMTCP.dll" (ByVal IPAddress As String) As Long
Declare Function ADAM5KTCP_ReadStreamData Lib "ADAMTCP.dll" (ByVal IPAddress As String, StreamData As TypeOfStreamData) As Long
Declare Function ADAM5KTCP_ReadAlarmInfo Lib "ADAMTCP.dll" (AlarmInfo As TypeOfAlarmInfo) As Long
Declare Function ADAM5KTCP_StartStream Lib "ADAMTCP.dll" (hEvent As Long) As Long
Declare Function ADAM5KTCP_StopStream Lib "ADAMTCP.dll" () As Long
Declare Function ADAM5KTCP_SetStreamAlarmState Lib "ADAMTCP.dll" (ByVal wStreamAlarmState As Integer) As Long
Declare Function ADAM5KTCP_Debug Lib "ADAMTCP.dll" (iMatchIndex%, iReceiveCount%, iThreadRun%, iTotalStream%, ByVal szFromIP As String) As Long
Declare Function ADAM5KTCP_UDPOpen Lib "ADAMTCP.dll" (ByVal SendTimeout As Long, ByVal ReceiveTimeout As Long) As Long
Declare Function ADAM5KTCP_UDPClose Lib "ADAMTCP.dll" () As Long
Declare Function ADAM5KTCP_SendReceiveUDPCmd Lib "ADAMTCP.dll" (ByVal IPAddress As String, _
                                                                ByVal szSend As String, ByVal szResult As String) As Long
Public Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
End Type
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" (lpEventAttributes As SECURITY_ATTRIBUTES, ByVal bManualReset As Long, ByVal bInitialState As Long, ByVal lpName As String) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Global szSend           As String
Global szReceive        As String
Global szModbusSend     As String
Global szModbusReceive  As String
Global StreamData As TypeOfStreamData
Global AlarmInfo  As TypeOfAlarmInfo
Global Const SOCK_STREAM = 1
Global Const ModbusTCPPort = 502
Global Const WAIT_OBJECT_0 = 0&
Global Const WAIT_TIMEOUT = &H102&
Function MakeDWord(HiWord As Integer, LoWord As Integer) As Long
     MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function

⌨️ 快捷键说明

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