#ifndef __AdamTcpCE_h__
#define __AdamTcpCE_h__

#ifdef __cplusplus
     extern "C"	// only need to export C interface if used by C++ source code
	 {
	#define EXPORTS __declspec( dllimport )
#else
	#define EXPORTS __declspec( dllexport ) 
#endif


struct _StreamData
{
    WORD DIO[8];     // DI/DO data for Slot0, Slot1,...., Slot7
    WORD Slot0[8];   // AI/AO data for slot0
    WORD Slot1[8];   // AI/AO data for slot1
    WORD Slot2[8];   // AI/AO data for slot2
    WORD Slot3[8];   // AI/AO data for slot3
    WORD Slot4[8];   // AI/AO data for slot4
    WORD Slot5[8];   // AI/AO data for slot5
    WORD Slot6[8];   // AI/AO data for slot6
    WORD Slot7[8];   // AI/AO data for slot6
};   //StreamData,*pStreamData;

struct _AlarmInfo
{
	BYTE    bySlot;		 // the Slot of 5000/TCP which cause the alarm change	
	BYTE    byChannel;      // the Channel of 5000/TCP which cause the alarm change	
	BYTE    byAlarmType;    // 0: Low Alarm, 1: High Alarm
	BYTE    byAlarmStatus;  // 0: Alarm Off, 1: Alarm On
	BYTE    byIndexOf5KTCP; // indicate the index 5000/TCP which cause the alarm change, zero-based
	char    szIP[20];       // the IP address which cause the alarm change
	char    szDateTime[48]; // e.x 2001/09/23 10:12:34:567 (Year/Month/Day Hour:Minute:Second:mSecond)
};

// return code
#define    ADAMTCP_NoError                      0
#define    ADAMTCP_StartupFailure               (-1)
#define    ADAMTCP_SocketFailure                (-2)
#define    ADAMTCP_UdpSocketFailure             (-3)
#define    ADAMTCP_SetTimeoutFailure            (-4)
#define    ADAMTCP_SendFailure                  (-5)
#define    ADAMTCP_ReceiveFailure               (-6)
#define    ADAMTCP_ExceedMaxFailure             (-7)
#define    ADAMTCP_CreateWsaEventFailure        (-8)
#define    ADAMTCP_ReadStreamDataFailure        (-9)
#define    ADAMTCP_InvalidIP                    (-10)
#define    ADAMTCP_ThisIPNotConnected           (-11)
#define    ADAMTCP_AlarmInfoEmpty               (-12)
#define    ADAMTCP_UdpSocketNotOpened           (-13)
#define    ADAMTCP_InvalidSlot                  (-14)

// always receiving sream data in despite of if alarm change
#define    ADAMTCP_ReceiveStreamIngoreAlarm     0  
// only receiving sream data when any alarm status change
// for example:    Hi-Alarm On -> Off , Hi-Alarm Off ->On, 
//                 Lo-Alarm On -> Off , Lo-Alarm Off ->On
#define    ADAMTCP_ReceiveStreamWhenAlarm       1

EXPORTS int CALLBACK ADAMTCP_GetDLLVersion(void);

//********************************************************
//---- functions for Read/Write Modbus ---
//********************************************************
EXPORTS int		CALLBACK	ADAMTCP_Open(void);
EXPORTS void	CALLBACK	ADAMTCP_Close(void);
EXPORTS int		CALLBACK	ADAMTCP_Connect(wchar_t* szwIP, unsigned short port,
							 int iConnectionTimeout, int iSendTimeout, int iReceiveTimeout);
EXPORTS void	CALLBACK	ADAMTCP_Disconnect(void);
EXPORTS int		CALLBACK	ADAMTCP_ReadReg(wchar_t* szwIP, WORD wID, 
										WORD wStartAddress, WORD wCount, WORD wData[]); 
EXPORTS int		CALLBACK	ADAMTCP_WriteReg(wchar_t* szwIP, WORD wID, 
										WORD wStartAddress, WORD wCount, WORD wData[]);
EXPORTS int		CALLBACK	ADAMTCP_ReadCoil(wchar_t* szwIP, WORD wID, 
										WORD wStartAddress, WORD wCount, WORD wData[]); 
EXPORTS int		CALLBACK	ADAMTCP_WriteCoil(wchar_t* szwIP, WORD wID, 
										WORD wStartAddress, WORD wCount, WORD wData[]);
EXPORTS int		CALLBACK	ADAMTCP_SendReceive5KTCPCmd(wchar_t* szwIP,  
										wchar_t* szSendToTCP,  wchar_t* szReceiveFromTCP, 
										wchar_t* szModbusSend, wchar_t* szModbusReceive);

//*******************************************************
//---- functions for UDP command ---
//********************************************************
EXPORTS int CALLBACK  ADAMTCP_UDPOpen(int iSendTimeout, int iReceiveTimeout);
EXPORTS int CALLBACK  ADAMTCP_UDPClose();
EXPORTS int CALLBACK  ADAMTCP_SendReceiveUDPCmd(wchar_t* szwIP, wchar_t* szwSend, wchar_t* szwReceive);


//*******************************************************
//---- functions for Stream Data ---
//*******************************************************
EXPORTS int CALLBACK  ADAMTCP_Add5KTCPForStream(wchar_t* szwIP);
EXPORTS int CALLBACK  ADAMTCP_ReadStreamData(wchar_t* szwIP, struct _StreamData  *pStreamData);
EXPORTS int CALLBACK  ADAMTCP_ReadAlarmInfo(struct _AlarmInfo  *pAlarmInfo);
EXPORTS int CALLBACK  ADAMTCP_ReadAlarmInfoEVB(BYTE *bySlot, BYTE *byChannel,BYTE *byAlarmType,
					BYTE *byAlarmStatus, BYTE *byIndexOf5KTCP, wchar_t* szwIP, wchar_t* szwDateTime);
					
//--- stream data for Embedded Visual Basic ---
EXPORTS int CALLBACK  ADAMTCP_CaptureStreamDataEVB(wchar_t* szwIP);
EXPORTS int CALLBACK  ADAMTCP_GetDIODataEVB(WORD *DIOs0, WORD *DIOs1, WORD *DIOs2, WORD *DIOs3,
										   WORD *DIOs4, WORD *DIOs5, WORD *DIOs6, WORD *DIOs7);
EXPORTS int CALLBACK  ADAMTCP_GetAIODataEVB(WORD SlotIndex, // which slot to read
										   WORD *AIOc0, WORD *AIOc1, WORD *AIOc2, WORD *AIOc3,
										   WORD *AIOc4, WORD *AIOc5, WORD *AIOc6, WORD *AIOc7);

EXPORTS int CALLBACK  ADAMTCP_StartStream(HANDLE *EventFromApp );
EXPORTS int CALLBACK  ADAMTCP_StopStream( );
EXPORTS int CALLBACK  ADAMTCP_SetStreamAlarmState(WORD wStreamAlarmState);
EXPORTS int CALLBACK  ADAMTCP_Debug(int *iMatchIndex, int *iReceiveCount, 
									  int *iThreadRun, int *iTotalStream, wchar_t* szwFromIP);

#ifdef __cplusplus
     }// only need to export C interface if used by C++ source code
#endif

#endif //__AdamTcpCE_h__