 |
Source Code of "sampleOutput.cpp"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// sampleOutput.cpp: main procedure of sample "Output"
//
// 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
#include "../include/ParaPortDll.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// this define replaces the standard function known from DOS with the call of the ParaPort.dll
#define _outp(a,b) Dll->output(a,b)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main( int argc, char *argv[ ] )
{
printf( "test program \"Output\"\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( "output on parallel port:\n" );
DWORD LastError;
// to set the data register into "output" mode, the bit 0x20 of the
// control port must be cleared
_outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x00 );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
// output on data register
printf( " _outp( PortAddress + PARAPORT_ADDRESS_DATA, 0x55 );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_DATA, 0x55 );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
printf( " _outp( PortAddress + PARAPORT_ADDRESS_DATA, 0xAA );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_DATA, 0xAA );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
printf( " _outp( PortAddress + PARAPORT_ADDRESS_DATA, 0x0F );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_DATA, 0x0F );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
printf( " _outp( PortAddress + PARAPORT_ADDRESS_DATA, 0xF0 );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_DATA, 0xF0 );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
printf( " _outp( PortAddress + PARAPORT_ADDRESS_DATA, 0xFF );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_DATA, 0xFF );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
printf( " _outp( PortAddress + PARAPORT_ADDRESS_DATA, 0x00 );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_DATA, 0x00 );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
// output on control register
printf( " _outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x01 );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x01 );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
printf( " _outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x02 );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x02 );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
printf( " _outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x04 );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x04 );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
printf( " _outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x08 );\n" );
_outp( PortAddress + PARAPORT_ADDRESS_CONTROL, 0x08 );
LastError = GetLastError( );
if ( LastError != ERROR_SUCCESS )
printf("Error on Dll->output( ): %d\n", LastError );
getchar( );
// unload dll
ParaPortDll::deleteSingleton( );
getchar( );
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2002, 2003, 2004 by Paul R. ADAM,
v2.0, read the Terms of Use
|
 |