// i8172W_FR_2053DI.c : Defines the entry point for the console application.
//
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "msw.h"
#include "i8172W.h"

static int slotIndex=-1;
int main(int argc, char **argv)
{
	int id, slot=2, RetValue ;
	int diData,group,i,channel,mode,status,port;

	RetValue = Open_Slot(slot);
	if (RetValue >0) {
		printf("Open Slot %d failed!\n",slot);
		return FAILURE;
	}else {
		id = i8172W_Init(slot);
		if (id==0)
			printf("\nThere is a I-8172W located at Slot %d.\n",slot);
		else {
			printf("There is no I-8172W located at LinPAC.\n");
			return FAILURE;
		}
	}

	printf("Please input the port number of i-8172W (Range: 0 or 1): ");
	scanf("%d",&port);
	
	printf("Please input the group index(Dip switch) of FR-2053 (Range: 8~15): ");
	scanf("%d",&group);
	
	printf("\nPlease select read mode:\n");
	printf("  0. Read single channel\n\r");
	printf("  1. Read all channel\n\r"); 
	printf("Input read mode: ");
	scanf("%d",&mode);
	printf("\n");

	if(mode)    //1. Read all channel
	{
		diData=i8172W_ReadDIGroup(slot,port,group);
		printf("DI data: %X\n",diData);
	}
	else       //0. Read single channel
	{
		for(channel=0;channel<16;channel++)
			printf("CH[%d]= %d \n", channel,i8172W_ReadDIBit(slot,port,group,channel));
	}

	Close_Slot(slot);
	return 0;
}

