/******************************************************************************
//                                                                           //
//  Project: Software Interface for USB-RFID Devices                         //
//                                                                           //
//  CGC Instruments, (c) 2009-2017, Version 1.22. All rights reserved.       //
//                                                                           //
//  Definition for USB-RFID DLL Routines                                     //
//                                                                           //
******************************************************************************/

#ifndef __USB_RFID_H__
#define __USB_RFID_H__


#ifdef __cplusplus
extern "C" {
#endif


#define USB_RFID_MAX_PORT 8 /* Maximum PortNumber */

/*
	The listed routines accept the number of the port PortNumber in the range 0..USB_RFID_MAX_PORT-1,
	thus maximum USB_RFID_MAX_PORT independent communication channels (ports) can be defined

	Each communication channel must be opened before the first usage. The Open routine assigns a specified virtual COMx port to the channel.
	The ComNumber specifies the number of the port - 1 stands for COM1, 2 for COM2, etc.

	If necessary, the channel may be closed and assigned by the Open routine to a new virtual COMx port.
	The channels are closed automatically at the end of the program, the main program does not need to take care about it.

	The return values of the routines are the following defines USB_RFID_ERR_XXX
		 0: routine finished without any error, USB_RFID_CheckAutoInput returns 0 if all notification messages could be decoded
		 1: USB_RFID_CheckAutoInput returns 1 if the received command does not match any notification message
		<0: errors USB_RFID_ERR_XXX

	The last error code can be obtained by calling USB_RFID_State.
	The routine USB_RFID_ErrorMessage returns a pointer to a zero-terminated character string.

	If a communication error occurred, the error code can be red again by USB_RFID_IO_State,
	The routine USB_RFID_IO_ErrorMessage provides the corresponding error message.
*/

#define USB_RFID_ERR_PORT_RANGE       -1 /* PortNumber out of range                         */
#define USB_RFID_ERR_OPEN             -2 /* Error opening the port                          */
#define USB_RFID_ERR_CLOSE            -3 /* Error closing the port                          */
#define USB_RFID_ERR_PURGE            -4 /* Error purging the port                          */
#define USB_RFID_ERR_CONTROL          -5 /* Error setting the port control lines            */
#define USB_RFID_ERR_STATUS           -6 /* Error reading the port status lines             */
#define USB_RFID_ERR_COMMAND_SEND     -7 /* Error sending command                           */
#define USB_RFID_ERR_DATA_SEND        -8 /* Error sending data                              */
#define USB_RFID_ERR_TERM_SEND        -9 /* Error sending termination character             */
#define USB_RFID_ERR_COMMAND_RECEIVE -10 /* Error receiving command                         */
#define USB_RFID_ERR_DATA_RECEIVE    -11 /* Error receiving data                            */
#define USB_RFID_ERR_TERM_RECEIVE    -12 /* Error receiving termination character           */
#define USB_RFID_ERR_COMMAND_WRONG   -13 /* Wrong command received                          */
#define USB_RFID_ERR_ARGUMENT_WRONG  -14 /* Wrong argument received                         */
#define USB_RFID_ERR_ARGUMENT        -15 /* Wrong argument passed to the function           */

#define USB_RFID_ERR_NOT_CONNECTED  -100 /* Device not connected                            */
#define USB_RFID_ERR_NOT_READY      -101 /* Device not ready                                */
#define USB_RFID_ERR_READY          -102 /* Device state could not be set to not ready      */

#define USB_RFID_ERR_DEBUG_OPEN     -400 /* Error opening the file for debugging output     */
#define USB_RFID_ERR_DEBUG_CLOSE    -401 /* Error closing the file for debugging output     */

#define USB_RFID_AUTO     64 /* Automatic RFID data received */
int FAR _export __pascal USB_RFID_Open  (WORD PortNumber, WORD COMNumber);      /* Open the port  */
int FAR _export __pascal USB_RFID_Close (WORD PortNumber);                      /* Close the port */

int FAR _export __pascal USB_RFID_Purge        (WORD PortNumber);               /* Clear data buffers for the port                                               */
int FAR _export __pascal USB_RFID_Buffer_State (WORD PortNumber, BOOL & Empty); /* Return true if the input data buffer of the device is empty                   */
int FAR _export __pascal USB_RFID_Device_Purge (WORD PortNumber, BOOL & Empty); /* Clear output data buffer of the device, return value as USB_RFID_Buffer_State */

int FAR _export __pascal USB_RFID_CheckAutoInput (WORD PortNumber, WORD & CommandMask); /* Check for new automatic notification data            */
int FAR _export __pascal USB_RFID_GetAutoMask    (WORD PortNumber, WORD & CommandMask); /* Get the mask of the last automatic notification data */

WORD FAR _export __pascal USB_RFID_RetCheckAutoInput (WORD PortNumber); /* Pascal optimized: check for new automatic notification data, return the command mask */
WORD FAR _export __pascal USB_RFID_RetGetAutoMask    (WORD PortNumber); /* Pascal optimized: return the mask of the last automatic notification data            */

/* RFID */
#define USB_RFID_INVALID_BYTE  0xFF       /* RFID data if no transponder is present or if its code is invalid */
#define USB_RFID_INVALID_DWORD 0xFFFFFFFF
#define USB_RFID_INVALID       -1
int FAR _export __pascal USB_RFID_EnableRFID  (WORD PortNumber, BOOL Enable);    /* Enable RFID                                      */
int FAR _export __pascal USB_RFID_GetRFID     (WORD PortNumber, BYTE Value [8]); /* Getting RFID data                                */
int FAR _export __pascal USB_RFID_AutoRFID    (WORD PortNumber);                 /* Receiving RFID data automatically                */
int FAR _export __pascal USB_RFID_GetLastRFID (WORD PortNumber, BYTE Value [8]); /* Getting last automatically transmitted RFID data */


/* LED */
#define USB_RFID_LED_NO      0
#define USB_RFID_LED_RED     1
#define USB_RFID_LED_GREEN   2
#define USB_RFID_LED_ORANGE  3
#define USB_RFID_LED_MAX_DELAY  256
int FAR _export __pascal USB_RFID_SetLED (WORD PortNumber, BYTE   Color, float Seconds); /* Get the LED state for a specified duration */
int FAR _export __pascal USB_RFID_GetLED (WORD PortNumber, BYTE & Color);                /* Get current LED state                      */

/* General */
WORD FAR _export __pascal USB_RFID_Version();                                                        /* Get the USB-RFID software version */

int FAR _export __pascal USB_RFID_GetUptime (WORD PortNumber, DWORD & Seconds, WORD & Milliseconds); /* Get device uptime */

int FAR _export __pascal USB_RFID_FW_Ver  (WORD PortNumber, WORD & Version);            /* Get the USB-RFID firmware version                                                          */
int FAR _export __pascal USB_RFID_FW_Date (WORD PortNumber, char * FAR DateString);     /* Get the USB-RFID firmware date, the buffer DateString should be 16 bytes long              */
int FAR _export __pascal USB_RFID_Prod_ID (WORD PortNumber, char * FAR Identification); /* Get the USB-RFID product identification, the buffer Identification should be 81 bytes long */
int FAR _export __pascal USB_RFID_Prod_No (WORD PortNumber, DWORD & Number);            /* Get the USB-RFID product number                                                            */

int          FAR _export __pascal USB_RFID_State (WORD PortNumber);           /* Get software interface state                                           */
const char * FAR _export __pascal USB_RFID_ErrorMessage (WORD PortNumber);    /* Get the error message corresponding to the software interface state    */
int          FAR _export __pascal USB_RFID_IO_State (WORD PortNumber);        /* Get serial port interface state                                        */
const char * FAR _export __pascal USB_RFID_IO_ErrorMessage (WORD PortNumber); /* Get the error message corresponding to the serial port interface state */

int FAR _export __pascal USB_RFID_OpenDebugFile  (WORD PortNumber, const char * FAR FileName); /* Open a text file for debugging output */
int FAR _export __pascal USB_RFID_CloseDebugFile (WORD PortNumber);                            /* Close the file for debugging output   */


#ifdef __cplusplus
}
#endif


#endif//__USB_RFID_H__
