// InpoutTest.cpp : Sample program, derived from Logix4U's sample and updated

//                  a little for MY x64 compaqtible distribution of InpOut

// 

// NOTE: This sample MUST be linked to the CORRECT DLL.

//       For a native x64 application, you must compile with the x64 compatible compiler

//           eg. VS2005 or an older verison with the latest MS Platform SDK.

//           AND link to InpOutx64.dll (v1.0.0.1 minimum, preferably 1.0.0.6!)

//

//       For a 32bit application that will run (and work) on both x86 and x64

//       link to InpOut32.dll (v1.0.0.6 minimum)

//

//       Setup the linker options in the project properties->linker options tab/menu

//

//       I am unfamilier with other C++ development environments but this info should apply to any!

//

//       Of course, instead of linking at compile time, you could write your code to interface with the DLL

//       at runtime. This may be a better option for furture proofing (this is how LCDSmartie links to it's

//       DLPortIO driver, allowing use of my x64 compatible InpOut32.dll simply by renaming it to DLPortIO.DLL !!!

//

 

#include "stdafx.h"

#include "stdio.h"

#include "string.h"

#include "stdlib.h"

 

//Note: The following header is in MY distribution of InpOut for x86 and x64.

//      It contains the function definitions exported by the DLL(s)

//       the one header is for BOTH x86 (inpout32.dll) and x64 (inpoutx64.dll)

 

//       To compile in NATIVE 64bit mode, you need a compatible compiler

//         *AND* you must link to InpOutx64.dll

//       To compile in 32bit mode (to run on x86 AND x64 windows)

//         you must link to InpOut32.dll

// 

#include "InpOut32.h"

 

/*--------------------------------*/

int main(int argc, char* argv[])

{

     

      if(argc<3)

      {

            //too few command line arguments, show usage

            printf( "Error : too few arguments\n\n***** Usage *****\n\n"

                   "InpoutTest read <ADDRESS> \nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n");

      }

      else

      {

            //First, check that we successfully opened the driver.

            BOOL bResult = IsInpOutDriverOpen();     

           

            if (bResult)

            {

                  if(strcmp(argv[1],"read")==0)

                  {

                        data = Inp32(atoi(argv[2]));

                        printf("Data read from address %s is %d \n\n\n\n",argv[2],data);

                 

                  }

                  else if(strcmp(argv[1],"write")==0)

                  {

                        if(argc<4)

                        {

                              printf("Error in arguments supplied");

                              printf( "\n***** Usage *****\n\nInpoutTest read <ADDRESS>"

                                     "\nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n");

                        }

                        else

                        {

                        Out32(atoi(argv[2]),atoi(argv[3]));

                        printf("data written to %s\n\n\n",argv[2]);

                        }

                  }

            }

            else

            {

                  printf("Unable to open InpOut Driver (HWInterface)\n");

                  return -1;

            }

      }

 

      return 0;

}