 |
Source Code of "sampleReadCycle.cpp"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// sampleReadCycle.cpp: main procedure of sample "ReadCycle"
//
// copyright (c) 2002, 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
#include "../include/ParaPortDll.h"
#include "../include/ParaPortCycle.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main( int argc, char *argv[ ] )
{
printf( "test program \"ReadCycle\"\n\n" );
ParaPortDll* Dll = ParaPortDll::getSingleton( );
HANDLE Handle;
if ( !Dll->loadLibrary( "../../bin/ParaPort.dll" ) )
{
printf( "Error: %d in Dll->loadLibrary( \"../../bin/ParaPort.dll\" );\n", GetLastError( ) );
ParaPortDll::deleteSingleton( );
getchar( );
return 1;
}
// open port
char* PortName = argc == 2 ? argv[ 1 ] : "LPT1";
printf( "Port: %s\n", PortName );
Handle = Dll->openPort( PortName );
if ( Handle == INVALID_HANDLE_VALUE )
{
printf( "Error: %d in Dll->openPort( \"%s\" );\n", GetLastError( ), PortName );
ParaPortDll::deleteSingleton( );
getchar( );
return 2;
}
ParaPortCycle Cycle;
Cycle.setDataInput( );
Cycle.setMaskData( PARAPORT_MASK_DATA );
Cycle.setMaskStatus( PARAPORT_MASK_STATUS );
while ( true )
{
if ( !Dll->executeCycle( Handle, &Cycle, 1 ) )
printf( "Error: %d in Dll->executeCycle( );\n", GetLastError( ) );
else
printf( "reading from parallel port:\n"
" Data: 0x%02X\n"
" Status: 0x%02X\n", Cycle.getData( ), Cycle.getStatus( ) );
printf( " to continue\n" );
getchar( );
}
Dll->closePort( Handle );
ParaPortDll::deleteSingleton( );
getchar( );
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2002, 2003, 2004 by Paul R. ADAM,
v2.0, read the Terms of Use
|
 |