/* -------------------------------------------------------------------- *
*                                                                      *
*   3333   CCCC      CCCC  OOOO  N     N  CCCC  EEEEE  PPPP  TTTTTTT   *
*       3 C         C     O    O NN    N C      E      P   P    T      *
*       3 C         C     O    O N N   N C      E      P   P    T      *
*   3333  C         C     O    O N  N  N C      EEEE   PPPP     T      *
*       3 C         C     O    O N   N N C      E      P        T      *
*       3 C         C     O    O N    NN C      E      P        T      *
*   3333   CCCC      CCCC  OOOO  N     N  CCCC  EEEEE  P        T      *
*                                                                      *
*                                                                      *
*	     TCUSB48IO Dynamically Loaded Library For Linux            *
*                 (32 Inputs 16 Outputs 32 Counters)                   *
*                                                                      *
*                                                                      *
* (c)2009 3C CONCEPT S.A.                v0.0.2		 01/10/2009    *
* v0.0.1 01/06/06 : Creation					       *
* v0.0.2 01/10/09 : DB:AJout OpenN,Version,modif openN & checkconfigfile  *
* V1.0.0 04/11/15 : DB:Modif num version, suppresssion warnings
*                                                                      *
* -------------------------------------------------------------------- *
*/

// Begin Header File

#ifndef _libTCUSB48IO_H
#define _libTCUSB48IO_H

#ifdef __cplusplus
extern "C" {
#endif

#include "ftd2xx.h"

//
// Maximum Modules
//

#define  maxmodule  8
#define  DLLVersion 3

//
// FTDI IO Buffer Sizes
//

#define FT_In_Buffer_Size   64
#define FT_Out_Buffer_Size  8

//
// TCUSB48IO Error Flags
//

#define  erNoError    0   // OK 
#define  erNumSerie   1   // Incorrect Serial Number
#define  erModule     2   // Incorrect Module Number
#define  erNoModule   3   // No TC/USB-48IO Module detected
#define  erConfig     4   // No TC/USB-48IO Configuration file
#define  erOpen       5   // Open Error
#define  erNoInit     6   // No initialized Module
#define  erWrite      7	  // Write Error
#define  erRead       8	  // Read Error
#define  erRxBytes    9	  // Read Bytes Error 
#define  erPurge      10  // Purge Buffer Error
#define  erClose      11  // Close Error


	FT_HANDLE hTCUSB48IO[maxmodule];
	FT_STATUS ftStatus;
	 
//  Input and Output Buffers Declaration
	char FT_In_Buffer[FT_In_Buffer_Size];
	char FT_Out_Buffer[FT_Out_Buffer_Size];
		
// Input State Buffer / Output State Buffer / Counter Buffer
	WORD Output[maxmodule];
	DWORD Input[maxmodule];
	DWORD Counter[maxmodule][32];


// Library exported functions
	
void TCUSB48IO_DeviceList();						// Create the connected device list
int TCUSB48IO_Open(int NModule,char ** NumSerie);			// TCUSB/48IO Module Open Function
int TCUSB48IO_OpenN(int NModule,DWORD *NumSerieNB);			// TCUSB/48IO Module OpenN Function
int TCUSB48IO_Close(int NModule);					// Module Close Function
int CheckConfigFile(DWORD * iVID, DWORD * iPID);
int TCUSB48IO_Refresh(int NModule);					// Data Refresh Function
int TCUSB48IO_Input(int NModule, DWORD *Data);				// Read from the Input port
int TCUSB48IO_Output(int NModule,WORD Data);				// Send data to the Output port
int TCUSB48IO_BitInput(int NModule, int Entree);			// Read data from the selected Input 
void TCUSB48IO_BitOutput(int NModule,int Sortie,int etat);		// Send state to the selected Output 
int TCUSB48IO_BitReadBack(int NModule, int Sortie);			// Read data from the selected Output 
int TCUSB48IO_Counter(int NModule, int Entree, BYTE *Data);		// Read counters value
void TCUSB48IO_WdgRun(int NModule);					// Start / Restart the Watchdog
void TCUSB48IO_WdgStop(int NModule);					// Stop the Watchdog
void TCUSB48IO_WdgRearm(int NModule);					// Reset the Watchdog
void TCUSB48IO_ResetPort(int NModule);					// Module USB Port Reset
 int TCUSB48IO_Version(int NModule,BYTE *DLL_V);				// Get dll version

#ifdef __cplusplus
}
#endif


#endif	// End Header File
