#include <stdio.h>
#include <unistd.h>
#include "i8094_dll.h"


#define TARGET_RA_ID		FRNET_RA0
#define TARGET_SA_ID		FRNET_SA8

int main( void )
{
   BYTE bCardID = 0;//bCardID=(bSlotNum-1), if the I-8094 plug-in Slot 2 of LinPAC, bCardID=2-1=1 
   short nRet;
   int i;
   WORD wDOData, wDIStatus;

   nRet = i8094_open( bCardID ); 
   if( nRet == SUCCESS_NO_ERROR )
   {
	   printf(" This sample needs both DI & DO FRnet-modules,\n please configure the Group-Address of DO module with RA0, DI module with SA8\n");
	   printf(" And please connect each DI channel to DO channel\n");

	   wDOData = 0x0001; 
	   for( i=0; i<32; i++ )
	   {
	       nRet = i8094_set_FRnet_DO( bCardID, TARGET_RA_ID, wDOData );
	       if( nRet == ERROR_UNSUPPORTED_FUNCTION ) 
	       {
	         	printf(" only I8094F support FRnet feature\n" );
		        break;
	       }

	       if( wDOData > 0x7FFF ) // ie 0x8000
		        wDOData = 0x0001;
	       else
		        wDOData = (wDOData << 1 );

	       usleep( 200000 );

	       nRet = i8094_get_FRnet_DI( bCardID, TARGET_SA_ID, &wDIStatus, FRNET_ENABLE_DIRECT_ACCESS );
	       printf(" DI Status : 0x%04X\n", wDIStatus );
	   }

	i8094_close( bCardID );
  }
  else
	   printf(" i8094_open() return %d !\n", nRet ); 

   return 0;
}

