#include <stdio.h>
#include <windows.h>

#include "COM-RFID.h"


int main()
	{
	// check the DLL version:
	if ((COM_RFID_Version() & 0xFF00) != 0x0100)
		{
		printf ("Wrong DLL Version: expected 1.x, found %d.%02d\n",
			COM_RFID_Version() / 0x100, COM_RFID_Version() & 0xFF);
		return -1;
		}

	// define the port number:
	const unsigned short PortNum = 0;

	// open the port, attach it to COM1:
	if (COM_RFID_Open (PortNum, 1))
		{
		// handle a possible error:
		printf ("%s\n", COM_RFID_ErrorMessage (PortNum));
		return 1;
		}

	// insert setup here

	// main program loop:
	while (true)
		{
		// check for automatic data:
		WORD CommandID;
		const int Result =
			COM_RFID_CheckAutoInput (PortNum, CommandID);

		if (Result != 0) // handle possible errors
			{
			if (Result < 0)
				printf ("%s\n", COM_RFID_ErrorMessage (PortNum));
			else
				printf ("Unexpected command received\n");
			continue; // do not proceed on errors
			}

		// check if digital input data is ready
		if (CommandID & AUTO_DIN)
			{
			WORD Data;
			if (COM_RFID_GetLastDigitalInput (PortNum, Data))
				printf ("%s\n", COM_RFID_ErrorMessage (PortNum));
			else
				{
				// handle digital input data here
				}
			}

		// check if RFID data is ready
		if (CommandID & AUTO_RFID)
			{
			BYTE Data [8];
			if (COM_RFID_GetLastRFID (PortNum, Data))
				printf ("%s\n", COM_RFID_ErrorMessage (PortNum));
			else
				{
				// handle RFID data here
				}
			}

		// insert further cases here

		// insert service of other commands here

		}

	//finish the program:
	return 0;
	}
