Home Page About Us
Links to other internet sites Contact Us

Source Code of "sampleInput.cpp"

///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // sampleInput.cpp: main procedure of sample "Input" // // copyright (c) 2003, 2004 by Paul R. ADAM // all rights reseved // read the "http://www.ParaPort.net/TermsOfUse.html" // // more information on "http://www.ParaPort.net" // ///////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <stdio.h> #include "../include/ParaPortDll.h" ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // this define replaces the standard function known from DOS with the call of the ParaPort.dll #define _inp(a) Dll->input(a) #define _outp(a,b) Dll->output(a,b) ///////////////////////////////////////////////////////////////////////////////////////////////////////////// int main( int argc, char *argv[ ] ) { printf( "test program \"Input\"\n\n" ); // load dll ParaPortDll* Dll = ParaPortDll::getSingleton( ); if ( !Dll->loadLibrary( "../../bin/ParaPort.dll" ) ) { printf( "Error: %d in Dll->loadLibrary( \"../../bin/ParaPort.dll\" );\n", GetLastError( ) ); ParaPortDll::deleteSingleton( ); getchar( ); return 1; } // get address of port char* PortName = argc == 2 ? argv[ 1 ] : "LPT1"; PARAPORT_ADDRESS PortAddress = Dll->getPortAddress( PortName ); printf( "Port: %s\n", PortName ); printf( "PortAddress: 0x%X\n", PortAddress ); if ( !PortAddress ) { printf( "Error: %d in Dll->getPortAddress( \"%s\" );\n", GetLastError( ), PortName ); ParaPortDll::deleteSingleton( ); getchar( ); return 2; } printf( "\nATTENTION: To well interprete the output, you must \n take in account the hardware inversion!\n\n" ); printf( "input from parallel port:\n" ); DWORD LastError; UCHAR Byte; // to set the data register into "input" mode, the bit 0x20 of the // control port must be set _outp( PortAddress + PARAPORT_ADDRESS_CONTROL, PARAPORT_MASK_CONTROL_DIRECTION ); LastError = GetLastError( ); if ( LastError != ERROR_SUCCESS ) printf("Error on Dll->output( ): %d\n", LastError ); // endless loop, this sample program will never end while ( true ) { // input from data register Byte = _inp( PortAddress + PARAPORT_ADDRESS_DATA ); LastError = GetLastError( ); if ( LastError != ERROR_SUCCESS ) printf("Error on Dll->input( ): %d\n", LastError ); else printf( " Data: 0x%02X\n", Byte ); // input from status register Byte = _inp( PortAddress + PARAPORT_ADDRESS_STATUS ) & PARAPORT_MASK_STATUS; LastError = GetLastError( ); if ( LastError != ERROR_SUCCESS ) printf("Error on Dll->input( ): %d\n", LastError ); else printf( " Status: 0x%02X\n", Byte ); // wait 100 micro seconds ::Sleep( 100 ); // printf( "<RETURN> to continue\n" ); // getchar( ); } // unload dll ParaPortDll::deleteSingleton( ); return 0; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////

Copyright (c) 2002, 2003, 2004 by , v2.0, read the Terms of Use

 

Documentation about ParaPort
Source code of ParaPort
Licenses for ParaPort
Download Software
Customer Feedback

Last Site Update: 07.01.2004

Current Site Release: v2.0 b2

Current Software Release: v2.0 beta b3