Attribute VB_Name = "AdamRtuCE"
Option Explicit

Public Const DATEBITS_4 = 4
Public Const DATEBITS_5 = 5
Public Const DATEBITS_6 = 6
Public Const DATEBITS_7 = 7
Public Const DATEBITS_8 = 8

Public Const ADAMRTU_PARITY_NO = 0
Public Const ADAMRTU_PARITY_ODD = 1
Public Const ADAMRTU_PARITY_EVEN = 2
Public Const ADAMRTU_PARITY_MARK = 3
Public Const ADAMRTU_PARITY_SPACE = 4

Public Const STOPBIT_1 = 0
Public Const STOPBIT_1POINT5 = 1
Public Const STOPBIT_2 = 2

Public Const MODBUS_ASCII = 0
Public Const MODBUS_RTU = 1

'------------------ define error code -----------------------

Public Const ADAMRTU_OK = (0)
Public Const ADAMRTU_PortNotOpen = (-1)
Public Const ADAMRTU_CannotOpen = (-2)
Public Const ADAMRTU_CannotClose = (-3)
Public Const ADAMRTU_InvalidModbusProtocol = (-4)
Public Const ADAMRTU_InvalidParity = (-5)
Public Const ADAMRTU_ComPortReadFailure = (-6)
Public Const ADAMRTU_ComPortWriteFailure = (-7)
Public Const ADAMRTU_TimeoutOccur = (-8)
Public Const ADAMRTU_InvalidPortHandle = (-9)
Public Const ADAMRTU_InvalidPortNumber = (-10)

'**********************************************************
'----------------------  AdamRtuCE.dll --------------------
Declare Function ADAMRTU_GetDLLVersion Lib "AdamRtuCE.dll" () As Long
Declare Function ADAMRTU_Open Lib "AdamRtuCE.dll" (ByVal lPortNumber As Long) As Long
Declare Function ADAMRTU_Close Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long) As Long

Declare Function ADAMRTU_SetCommState Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long, ByVal lBaudrate As Long, _
                        ByVal lParity As Long, ByVal lDataBits As Long, ByVal lStopBits As Long) As Long

Declare Function ADAMRTU_AdamCommand Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long, ByVal szSend As String, _
                                                          ByVal szReceive As String, ByVal lTimeout As Long) As Long
Declare Function ADAMRTU_ComPortWrite Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long, ByVal szSend As String, _
                                                           ByVal lLength As Long, ByVal lTimeout As Long) As Long
Declare Function ADAMRTU_ComPortRead Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long, ByVal szSend As String, _
                                                          lLength As Long, ByVal lTimeout As Long) As Long

Declare Function ADAMRTU_ReadHoldingRegister Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long, ByVal wID As Integer, _
                                                                  ByVal wStartAddress As Integer, ByVal wCount As Integer, ByVal strDataString As String, _
                                                                ByVal lTimeout As Long) As Long
Declare Function ADAMRTU_WriteHoldingRegister Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long, ByVal wID As Integer, _
                                                                   ByVal wStartAddress As Integer, ByVal wCount As Integer, ByVal strDataString As String, _
                                                                   ByVal lTimeout As Long) As Long
                
Declare Function ADAMRTU_ReadCoil Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long, ByVal wID As Integer, _
                                                       ByVal wStartAddress As Integer, ByVal wCount As Integer, ByVal strDataString As String, _
                                                       ByVal lTimeout As Long) As Long
Declare Function ADAMRTU_WriteCoil Lib "AdamRtuCE.dll" (ByVal lPortHandle As Long, ByVal wID As Integer, _
                                                        ByVal wStartAddress As Integer, ByVal wCount As Integer, ByVal strDataString As String, _
                                                        ByVal lTimeout As Long) As Long

                

