/* Get Digital Input for i-8048W modules.

   Author: Moki Matsushima

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

/* File level history (record changes for this file here.)

   v 1.0.0  27 May 2016 by Winson
     Use 8048W API to replace old code.

   v 0.0.0  1 Feb 2008 by Moki Matsushima
     create, blah blah... */


#include <stdio.h>
#include <unistd.h>
#include "msw.h"
#include "i8048W.h"

int main(int argc, char **argv)
{
	int  slotIndex=-1, slot,Ret,Id,ch, ret_init, di_all;
	char *status;

	for(slot=1;slot<9;slot++)
	{
		 Ret = Open_Slot(slot);
		 if (Ret == 0) 
     {    		         
            ret_init=I8048W_Init(slot);
            if (ret_init == 0){        //find I-8048W
                slotIndex=slot;
            }
            else
               Close_Slot(slot);
               // printf("Failed to open module I-8048W on Slot%d.\n",slot);
              
     }
  }
  
  
  
  if(slotIndex==-1)
	{
		printf("There is no I-8048W at LinPAC. \n");
		return FAILURE;  // end of program
	}
	else
		printf("There is an I-8048W at slot %d\n", slotIndex);
    

	di_all = I8048W_DI_ALL(slotIndex);
	printf("0~7 bit corresponding I-8048W 0~7 channel\n");
	printf("The DI Status of read All channels: %d\n",di_all);

	ch = 0;  //channel
	Ret = I8048W_DI_Ch(slotIndex,ch);

	if(Ret)
		status = "ON";
	else
		status = "OFF";

	printf("Channel %d status: %s\n",ch, status);

	Close_Slot(slotIndex);
	return SUCCESS;
}

