Source

Reminder

The source code given in this section is published to illustrate the function of ParaPort and its usage. Nevertheless, the source code reference for software development is the distribution in the Download Area.

By using any material from this site, you must accept the Terms of Use.

Application Programming Interface

The standard C header with basic defines and structs
A C++ class to use with interface ParaPortCycle
A C++ class to access the dynamic link library

/*
///////////////////////////////////////////////////////////////////////////////
// 
// C interface of ParaPort
//
// copyright (c) 2002, 2003, 2004 by Paul ADAM
// all rights reserved
// read the "http://www.ParaPort.net/TermsOfUse.html"
//
// more information on "http://www.ParaPort.net"
//
///////////////////////////////////////////////////////////////////////////////
*/

#ifndef ParaPort_h
#define ParaPort_h

#pragma pack( 1 )

/*
///////////////////////////////////////////////////////////////////////////////
// interface for openPort( )
*/

#define                      PARAPORT_LPT_MAX                                  9  /* LPT1 up to LPT9 */

/*
// on Windows 9x systems, the number of parallel ports is limited to 3 
*/
#define                      PARAPORT_LPT_MAX_ON_WIN9X                         3  /* LPT1, LPT2, LPT3 */

/*
///////////////////////////////////////////////////////////////////////////////
// interface for executeCycle( )
*/

#define                      PARAPORT_MASK_DATA_D0                             0x01
#define                      PARAPORT_MASK_DATA_D1                             0x02
#define                      PARAPORT_MASK_DATA_D2                             0x04
#define                      PARAPORT_MASK_DATA_D3                             0x08
#define                      PARAPORT_MASK_DATA_D4                             0x10
#define                      PARAPORT_MASK_DATA_D5                             0x20
#define                      PARAPORT_MASK_DATA_D6                             0x40
#define                      PARAPORT_MASK_DATA_D7                             0x80
#define                      PARAPORT_MASK_DATA                                0xFF

#define                      PARAPORT_MASK_CONTROL_STROBE                      0x01
#define                      PARAPORT_MASK_CONTROL_LINEFEED                    0x02
#define                      PARAPORT_MASK_CONTROL_INIT                        0x04
#define                      PARAPORT_MASK_CONTROL_SELECTIN                    0x08
#define                      PARAPORT_MASK_CONTROL_DIRECTION                   0x20      /* only for internal use */
#define                      PARAPORT_MASK_CONTROL                             ( PARAPORT_MASK_CONTROL_INIT     | \
                                                                                 PARAPORT_MASK_CONTROL_LINEFEED | \
                                                                                 PARAPORT_MASK_CONTROL_SELECTIN | \
                                                                                 PARAPORT_MASK_CONTROL_STROBE   )

#define                      PARAPORT_MASK_STATUS_ERROR                        0x08
#define                      PARAPORT_MASK_STATUS_SELECT                       0x10
#define                      PARAPORT_MASK_STATUS_PAPEREND                     0x20
#define                      PARAPORT_MASK_STATUS_ACKNOWLEDGE                  0x40
#define                      PARAPORT_MASK_STATUS_BUSY                         0x80
#define                      PARAPORT_MASK_STATUS                              ( PARAPORT_MASK_STATUS_ACKNOWLEDGE | \
                                                                                 PARAPORT_MASK_STATUS_BUSY        | \
                                                                                 PARAPORT_MASK_STATUS_ERROR       | \
                                                                                 PARAPORT_MASK_STATUS_PAPEREND    | \
                                                                                 PARAPORT_MASK_STATUS_SELECT      )

typedef struct
{
 UCHAR                       Data; 
 UCHAR                       Status;
 UCHAR                       Control;
 UCHAR                       MaskData;
 UCHAR                       MaskStatus;
 UCHAR                       MaskControl;
 UCHAR                       RepeatFactor; 
}
PARAPORT_CYCLE; 

/*
///////////////////////////////////////////////////////////////////////////////
// interface for getPortAddress( ), input( ) and output( )
*/

typedef unsigned char*       PARAPORT_ADDRESS;

/*
// only the following registers of the parallel port will be accessed
*/
#define                      PARAPORT_ADDRESS_DATA                             0
#define                      PARAPORT_ADDRESS_STATUS                           1
#define                      PARAPORT_ADDRESS_CONTROL                          2

#define                      PARAPORT_ADDRESS_MIN                              PARAPORT_ADDRESS_DATA
#define                      PARAPORT_ADDRESS_MAX                              ( PARAPORT_ADDRESS_CONTROL + 1 )

/*
// this error will be returned by functions input( ) and output( ), if there was an error
// but it might be also a valid value!
*/
#define                      PARAPORT_BYTE_ON_ERROR                            0xFF

/*
///////////////////////////////////////////////////////////////////////////////
// interface for error handling
*/

#define                      PARAPORT_ERROR                                    ( 0x20000000 )
#define                      PARAPORT_ERROR_INTERNAL_1                         ( PARAPORT_ERROR | 1  )
#define                      PARAPORT_ERROR_INTERNAL_2                         ( PARAPORT_ERROR | 2  )
#define                      PARAPORT_ERROR_INTERNAL_3                         ( PARAPORT_ERROR | 3  )
#define                      PARAPORT_ERROR_INVALID_HANDLE                     ( PARAPORT_ERROR | 4  )
#define                      PARAPORT_ERROR_INVALID_PORTNAME                   ( PARAPORT_ERROR | 5  )
#define                      PARAPORT_ERROR_LIBRARY_NOT_IMPLEMENTED            ( PARAPORT_ERROR | 6  )
#define                      PARAPORT_ERROR_LIBRARY_NOT_LOADED                 ( PARAPORT_ERROR | 7  )
#define                      PARAPORT_ERROR_INVALID_ADDRESS                    ( PARAPORT_ERROR | 8  )
#define                      PARAPORT_ERROR_INVALID_CYCLE                      ( PARAPORT_ERROR | 9  )
#define                      PARAPORT_ERROR_LIBRARY_NOT_COMPATIBLE             ( PARAPORT_ERROR | 10 )

#define                      PARAPORT_ERROR_MIN                                PARAPORT_ERROR_INTERNAL_1
#define                      PARAPORT_ERROR_MAX                                ( PARAPORT_ERROR_LIBRARY_NOT_COMPATIBLE + 1 )

#pragma pack( )

#endif /* ParaPort_h */

/*
///////////////////////////////////////////////////////////////////////////////
*/

/*
///////////////////////////////////////////////////////////////////////////////
// 
// class ParaPortCycle
//
// copyright (c) 2002, 2003, 2004 by Paul ADAM
// all rights reserved
// read the "http://www.ParaPort.net/TermsOfUse.html"
//
// more information on "http://www.ParaPort.net"
//
///////////////////////////////////////////////////////////////////////////////
*/

#ifndef ParaPortCycle_h
#define ParaPortCycle_h

#include < windows.h >

#include "ParaPort.h"

#pragma pack( 1 )

#ifdef __cplusplus

///////////////////////////////////////////////////////////////////////////////
class ParaPortCycle : public PARAPORT_CYCLE
{

///////////////////////////////////////////////////////////////////////////////
// public interface:
public:

// constructor
                             ParaPortCycle( )    { clear( ); }

 void                        clear( )            {
                                                  Control     = Data     = Status     = 0x00;
                                                  MaskControl = MaskData = MaskStatus = 0x00;
                                                  RepeatFactor = 0x00;
                                                 }

///////////////////////////////////////////////////////////////////////////////
// access to data byte

 UCHAR                       getData( ) const    { return Data; }
 void                        setData( UCHAR Byte )
                                                 {
                                                  Data = Byte;
                                                  MaskData = 0xFF;
                                                 }
 void                        setData( UCHAR Byte, UCHAR Mask )
                                                 {
                                                  Data = Byte;
                                                  MaskData = Mask;
                                                 }

 bool                        isDataInput( )      { return Control & PARAPORT_MASK_CONTROL_DIRECTION ? true : false; }
 bool                        isDataOutput( )     { return !isDataInput( ); }
 
 void                        setDataInput( )     { Control |= PARAPORT_MASK_CONTROL_DIRECTION; }
 void                        setDataOutput( )    { Control &= ~PARAPORT_MASK_CONTROL_DIRECTION; }
 
///////////////////////////////////////////////////////////////////////////////
// access to control byte

 void                        clearControl( )     {
                                                  clearInit( );
                                                  clearLineFeed( );
                                                  clearSelectIn( );
                                                  clearStrobe( );
                                                 }
 UCHAR                       getControl( ) const { return Control; }


 void                        setControl( )       {
                                                  setInit( );
                                                  setLineFeed( );
                                                  setSelectIn( );
                                                  setStrobe( );
                                                 }

 void                        setControl( UCHAR Byte )
                                                 {
                                                  Control = Byte & PARAPORT_MASK_CONTROL;
                                                  MaskControl = PARAPORT_MASK_CONTROL;
                                                 }

 void                        clearInit( )        {
                                                  Control &= ~PARAPORT_MASK_CONTROL_INIT;
                                                  MaskControl |= PARAPORT_MASK_CONTROL_INIT;
                                                 }
 void                        setInit( )          {
                                                  Control |= PARAPORT_MASK_CONTROL_INIT;
                                                  MaskControl |= PARAPORT_MASK_CONTROL_INIT;
                                                 }

 void                        clearLineFeed( )    {
#ifdef PARAPORT_NO_HARDWARE_INVERSION
                                                  Control &= ~PARAPORT_MASK_CONTROL_LINEFEED;
#else // PARAPORT_NO_HARDWARE_INVERSION
                                                  Control |= PARAPORT_MASK_CONTROL_LINEFEED;
#endif // PARAPORT_NO_HARDWARE_INVERSION
                                                  MaskControl |= PARAPORT_MASK_CONTROL_LINEFEED;
                                                 }
 void                        setLineFeed( )      {
#ifdef PARAPORT_NO_HARDWARE_INVERSION
                                                  Control |= PARAPORT_MASK_CONTROL_LINEFEED;
#else // PARAPORT_NO_HARDWARE_INVERSION
                                                  Control &= ~PARAPORT_MASK_CONTROL_LINEFEED;
#endif // PARAPORT_NO_HARDWARE_INVERSION
                                                  MaskControl |= PARAPORT_MASK_CONTROL_LINEFEED;
                                                 }

 void                        clearSelectIn( )    {
#ifdef PARAPORT_NO_HARDWARE_INVERSION
                                                  Control &= ~PARAPORT_MASK_CONTROL_SELECTIN;
#else // PARAPORT_NO_HARDWARE_INVERSION
                                                  Control |= PARAPORT_MASK_CONTROL_SELECTIN;
#endif // PARAPORT_NO_HARDWARE_INVERSION
                                                  MaskControl |= PARAPORT_MASK_CONTROL_SELECTIN;
                                                 }
 void                        setSelectIn( )      {
#ifdef PARAPORT_NO_HARDWARE_INVERSION
                                                  Control |= PARAPORT_MASK_CONTROL_SELECTIN;
#else // PARAPORT_NO_HARDWARE_INVERSION
                                                  Control &= ~PARAPORT_MASK_CONTROL_SELECTIN;
#endif // PARAPORT_NO_HARDWARE_INVERSION
                                                  MaskControl |= PARAPORT_MASK_CONTROL_SELECTIN;
                                                 }

 void                        clearStrobe( )      {
#ifdef PARAPORT_NO_HARDWARE_INVERSION
                                                  Control &= ~PARAPORT_MASK_CONTROL_STROBE;
#else // PARAPORT_NO_HARDWARE_INVERSION
                                                  Control |= PARAPORT_MASK_CONTROL_STROBE;
#endif // PARAPORT_NO_HARDWARE_INVERSION
                                                  MaskControl |= PARAPORT_MASK_CONTROL_STROBE;
                                                 }
 void                        setStrobe( )        {
#ifdef PARAPORT_NO_HARDWARE_INVERSION
                                                  Control |= PARAPORT_MASK_CONTROL_STROBE;
#else // PARAPORT_NO_HARDWARE_INVERSION
                                                  Control &= ~PARAPORT_MASK_CONTROL_STROBE;
#endif // PARAPORT_NO_HARDWARE_INVERSION
                                                  MaskControl |= PARAPORT_MASK_CONTROL_STROBE;
                                                 }


///////////////////////////////////////////////////////////////////////////////
// access to status byte

 UCHAR                       getStatus( ) const  { return Status & PARAPORT_MASK_STATUS; }

 bool                        isStatusAcknoledge( )
                                                 {
                                                  return Status & PARAPORT_MASK_STATUS_ACKNOWLEDGE ? true : false;
                                                 }
 bool                        isStatusBusy( )     {
#ifdef PARAPORT_NO_HARDWARE_INVERSION
                                                  return Status & PARAPORT_MASK_STATUS_BUSY ? true : false;
#else // PARAPORT_NO_HARDWARE_INVERSION
                                                  return Status & PARAPORT_MASK_STATUS_BUSY ? false : true;
#endif // PARAPORT_NO_HARDWARE_INVERSION
                                                 }
 bool                        isStatusError( )    { return Status & PARAPORT_MASK_STATUS_ERROR ? true : false; }
 bool                        isStatusPaperEnd( ) { return Status & PARAPORT_MASK_STATUS_PAPEREND ? true : false; }
 bool                        isStatusSelect( )   { return Status & PARAPORT_MASK_STATUS_SELECT ? true : false; }

///////////////////////////////////////////////////////////////////////////////
// modify masks
 void                        addMaskControl( UCHAR Mask )
                                                 { MaskControl |= ( Mask & PARAPORT_MASK_CONTROL ); }
 void                        removeMaskControl( UCHAR Mask )
                                                 { MaskControl &= ~( Mask & PARAPORT_MASK_CONTROL ); }
 void                        setMaskControl( UCHAR Mask )
                                                 { MaskControl = ( Mask & PARAPORT_MASK_CONTROL ); }

 void                        addMaskData( UCHAR Mask )
                                                 { MaskData |= ( Mask & PARAPORT_MASK_DATA ); }
 void                        removeMaskData( UCHAR Mask )
                                                 { MaskData &= ~( Mask & PARAPORT_MASK_DATA ); }
 void                        setMaskData( UCHAR Mask )
                                                 { MaskData = ( Mask & PARAPORT_MASK_DATA ); }

 void                        addMaskStatus( UCHAR Mask )
                                                 { MaskStatus |= ( Mask & PARAPORT_MASK_STATUS ); }
 void                        removeMaskStatus( UCHAR Mask )
                                                 { MaskStatus &= ~( Mask & PARAPORT_MASK_STATUS ); }
 void                        setMaskStatus( UCHAR Mask )
                                                 { MaskStatus = ( Mask & PARAPORT_MASK_STATUS ); }

///////////////////////////////////////////////////////////////////////////////
// access to repeat factor

 UCHAR                       getRepeatFactor( ) const
                                                 { return RepeatFactor; }
 void                        setRepeatFactor( UCHAR Byte )
                                                 { RepeatFactor = Byte; }

};

#endif /* __cplusplus */

#pragma pack( )

#endif /* ParaPortCycle_h */

/*
///////////////////////////////////////////////////////////////////////////////
*/

/*
///////////////////////////////////////////////////////////////////////////////
// 
// class ParaPortDll
//
// copyright (c) 2002, 2003, 2004 by Paul ADAM
// all rights reserved
// read the "http://www.ParaPort.net/TermsOfUse.html"
//
// more information on "http://www.ParaPort.net"
//
///////////////////////////////////////////////////////////////////////////////
*/

#ifndef ParaPortDll_h
#define ParaPortDll_h

#include < windows.h >

#include "ParaPort.h"

#pragma pack( 1 )

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

///////////////////////////////////////////////////////////////////////////////
// interface compatible with v1.3

 BOOL                        closePort( HANDLE Handle );

 BOOL                        executeCycle( HANDLE Handle, PARAPORT_CYCLE* ParaPortCycle, int Count );

 HANDLE                      openPort( const char* PortName );
 
///////////////////////////////////////////////////////////////////////////////
// new interface v2.0

 PARAPORT_ADDRESS            __stdcall getPortAddress( const char* PortName );

 UCHAR                       __stdcall input( PARAPORT_ADDRESS Address );

 UCHAR                       __stdcall output( PARAPORT_ADDRESS Address, UCHAR Byte );


#ifdef __cplusplus
}
#endif  /* __cplusplus */


///////////////////////////////////////////////////////////////////////////////
// interface compatible with v1.3

 typedef BOOL                ( *ParaPort_closePort     ) ( HANDLE Handle );

 typedef BOOL                ( *ParaPort_executeCycle  ) ( HANDLE Handle, PARAPORT_CYCLE* ParaPortCycle, int Count );
 
 typedef HANDLE              ( *ParaPort_openPort      ) ( const char* PortName );

///////////////////////////////////////////////////////////////////////////////
// new interface v2.0

 typedef PARAPORT_ADDRESS    ( __stdcall *ParaPort_getPortAddress ) ( const char* PortName );

 typedef UCHAR               ( __stdcall *ParaPort_input            ) ( PARAPORT_ADDRESS Address );

 typedef UCHAR               ( __stdcall *ParaPort_output           ) ( PARAPORT_ADDRESS Address, UCHAR Byte );


#ifdef __cplusplus

///////////////////////////////////////////////////////////////////////////////
class ParaPortDll
{

///////////////////////////////////////////////////////////////////////////////
// interface compatible with v1.3:
public:

 BOOL                        closePort( HANDLE Handle )
                                                 {
                                                  if ( !_closePort )
                                                  {
                                                   ::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
                                                   return FALSE;
                                                  }
                                                  return _closePort( Handle );
                                                 }

 static void                 deleteSingleton( )  { initSingleton( true ); }

 BOOL                        executeCycle( HANDLE Handle, PARAPORT_CYCLE* Cycle, int Count = 1 )
                                                 {
                                                  if ( !_executeCycle )
                                                  {
                                                   ::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
                                                   return FALSE;
                                                  }
                                                  return _executeCycle( Handle, Cycle, Count );
                                                 }

 static ParaPortDll*         getSingleton( )     { return initSingleton( false ); }

 BOOL                        loadLibrary( const char* FileName )
                                                 {
                                                  _Instance = ::LoadLibrary( FileName );
                                                  if ( !_Instance )
                                                   return FALSE;
                                                  _closePort      = ( ParaPort_closePort      ) ::GetProcAddress( _Instance, "closePort" );
                                                  _executeCycle   = ( ParaPort_executeCycle   ) ::GetProcAddress( _Instance, "executeCycle" );
                                                  _openPort       = ( ParaPort_openPort       ) ::GetProcAddress( _Instance, "openPort" );

                                                  _getPortAddress = ( ParaPort_getPortAddress ) ::GetProcAddress( _Instance, "getPortAddress" );
                                                  _input          = ( ParaPort_input          ) ::GetProcAddress( _Instance, "input" );
                                                  _output         = ( ParaPort_output         ) ::GetProcAddress( _Instance, "output" );
                                                  return TRUE;
                                                 }

 HANDLE                      openPort( const char* PortName )
                                                 {
                                                  if ( !_openPort )
                                                  {
                                                   ::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
                                                   return INVALID_HANDLE_VALUE;
                                                  }
                                                  return _openPort( PortName );
                                                 }

///////////////////////////////////////////////////////////////////////////////
// new interface v2.0:
public:

 PARAPORT_ADDRESS            getPortAddress( const char* PortName )
                                                 {
                                                  if ( !_getPortAddress )
                                                  {
                                                   ::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
                                                   return NULL;
                                                  }
                                                  return _getPortAddress( PortName );
                                                 }

 UCHAR                       input( PARAPORT_ADDRESS Address )
                                                 {
                                                  if ( !_input )
                                                  {
                                                   ::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
                                                   return 0x00;
                                                  }
                                                  return _input( Address );
                                                 }

 UCHAR                       output( PARAPORT_ADDRESS Address, UCHAR Byte )
                                                 {
                                                  if ( !_output)
                                                  {
                                                   ::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
                                                   return 0x00;
                                                  }
                                                  return _output( Address, Byte );
                                                 }

///////////////////////////////////////////////////////////////////////////////
// implementation:
protected:

// constructor
                             ParaPortDll( )      : _Instance( NULL ) 
                                                 , _closePort( NULL )
                                                 , _executeCycle( NULL )
                                                 , _openPort( NULL )
                                                 
                                                 , _getPortAddress( NULL )
                                                 , _input( NULL )
                                                 , _output( NULL )
                                                 { }
                            
                            ~ParaPortDll( )      {
                                                  if ( _Instance )
                                                   ::FreeLibrary( _Instance );
                                                 }

 static ParaPortDll*         initSingleton( bool Delete )
                                                 {
                                                  static ParaPortDll* Singleton = NULL;
                                                  if ( Delete )
                                                  {
                                                   if ( Singleton )
                                                   {
                                                    delete Singleton;
                                                    Singleton = NULL;
                                                   }
                                                  }
                                                  else
                                                  {
                                                   if ( !Singleton )
                                                    Singleton = new ParaPortDll;
                                                  }
                                                  return Singleton;
                                                 }

 HMODULE                     _Instance;
 ParaPort_closePort          _closePort;
 ParaPort_executeCycle       _executeCycle;
 ParaPort_openPort           _openPort;

 ParaPort_getPortAddress     _getPortAddress;
 ParaPort_input              _input;
 ParaPort_output             _output;
 
};

#endif /* __cplusplus */

#pragma pack( )

#endif /* ParaPortDll_h */

/*
///////////////////////////////////////////////////////////////////////////////
*/

Sample Applications using ParaPort

How to use ParaPort with inp( )
How to use ParaPort with outp( )
How to read from parallel port using ParaPortCycle
How to write to parallel port using ParaPortCycle
sampleMFC The download distribution contains a complete MFC project with source code ( Visual C++ 6.0 )
The source code published here has been developed by Benjamin NICOLLE. It shows how to access the new interface "direct register access".

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// sampleInput.cpp: main procedure of sample "Input"
//
// copyright (c) 2003, 2004 by Paul ADAM
// all rights reserved
// 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 _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( " to continue\n" );
//  getchar( );
 }

// unload dll
 ParaPortDll::deleteSingleton( );
 return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// sampleOutput.cpp: main procedure of sample "Output"
//
// copyright (c) 2003, 2004 by Paul 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;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// sampleReadCycle.cpp: main procedure of sample "ReadCycle"
//
// copyright (c) 2002, 2003, 2004 by Paul ADAM
// all rights reserved
// 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;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// sampleRepeatFactor.cpp: main procedure of sample "RepeatFactor"
//
// copyright (c) 2002, 2003, 2004 by Paul 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 \"RepeatFactor\"\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[ 10 ];
 Cycle[ 0 ].setData( 0x00 );
 Cycle[ 0 ].clearInit( );
 Cycle[ 0 ].clearLineFeed( );
 Cycle[ 0 ].clearSelectIn( );
 Cycle[ 0 ].clearStrobe( );

 Cycle[ 1 ].setData( 0x01 );
 Cycle[ 1 ].setInit( );
 
 Cycle[ 2 ].setData( 0x02 );
 Cycle[ 2 ].clearInit( );

 Cycle[ 3 ].setData( 0x03 );
 Cycle[ 3 ].setLineFeed( );
 Cycle[ 3 ].setRepeatFactor( 1 );

 Cycle[ 4 ].setData( 0x04 );
 Cycle[ 4 ].clearLineFeed( );

 Cycle[ 5 ].setData( 0x05 );
 Cycle[ 5 ].setSelectIn( );
 Cycle[ 5 ].setRepeatFactor( 2 );
 
 Cycle[ 6 ].setData( 0x06 );
 Cycle[ 6 ].clearSelectIn( );

 Cycle[ 7 ].setData( 0x07 );
 Cycle[ 7 ].setStrobe( );
 Cycle[ 7 ].setRepeatFactor( 4 );
 
 Cycle[ 8 ].setData( 0x08 );
 Cycle[ 8 ].clearStrobe( );
 
 Cycle[ 9 ].setData( 0x09 );

 if ( !Dll->executeCycle( Handle, Cycle, sizeof( Cycle ) / sizeof( Cycle[ 0 ] ) ) )
  printf( "Error: %d in Dll->executeCycle( );\n", GetLastError( ) );

 for ( int i = 0; i < sizeof( Cycle ) / sizeof( Cycle[ 0 ] ); i ++ )
 {
  printf( "i: %d\n", i );
  if ( !Dll->executeCycle( Handle, Cycle + i, 1 ) )
   printf( "Error: %d in Dll->executeCycle( );\n", GetLastError( ) );
  getchar( );
 }
 Dll->closePort( Handle );
 ParaPortDll::deleteSingleton( );
 getchar( );
 return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

Attribute VB_Name = "ParaPort"
' ///////////////////////////////////////////////////////////////////////////////
' //
' // VB types for the interface of ParaPort
' //
' // copyright (c) 2002, 2003, 2004 by Paul ADAM
' // all rights reserved
' // read the "http://www.ParaPort.net/TermsOfUse.html"
' //
' // more information on "http://www.ParaPort.net"
' //
' ///////////////////////////////////////////////////////////////////////////////


' ///////////////////////////////////////////////////////////////////////////////
' // interface for getPortAddress( ), input( ) and output( )
' ///////////////////////////////////////////////////////////////////////////////

Public Const PARAPORT_LPT_MAX = 9&

' // only the following registers of the parallel port will be accessed
Public Const PARAPORT_ADDRESS_DATA = 0&
Public Const PARAPORT_ADDRESS_STATUS = 1&
Public Const PARAPORT_ADDRESS_CONTROL = 2&

Public Const PARAPORT_ADDRESS_MIN = PARAPORT_ADDRESS_DATA
Public Const PARAPORT_ADDRESS_MAX = (PARAPORT_ADDRESS_CONTROL + 1)

' // this error will be returned by functions input( ) and output( ), if there was an error
' // but it might be also a valid value!
Public Const PARAPORT_BYTE_ON_ERROR = &HFF


' ///////////////////////////////////////////////////////////////////////////////
' // interface for error handling
' ///////////////////////////////////////////////////////////////////////////////

Public Const PARAPORT_ERROR = &H20000000
Public Const PARAPORT_ERROR_INTERNAL_1 = (PARAPORT_ERROR Or 1&)
Public Const PARAPORT_ERROR_INTERNAL_2 = (PARAPORT_ERROR Or 2&)
Public Const PARAPORT_ERROR_INTERNAL_3 = (PARAPORT_ERROR Or 3&)
Public Const PARAPORT_ERROR_INVALID_HANDLE = (PARAPORT_ERROR Or 4&)
Public Const PARAPORT_ERROR_INVALID_PORTNAME = (PARAPORT_ERROR Or 5&)
Public Const PARAPORT_ERROR_LIBRARY_NOT_IMPLEMENTED = (PARAPORT_ERROR Or 6&)
Public Const PARAPORT_ERROR_LIBRARY_NOT_LOADED = (PARAPORT_ERROR Or 7&)
Public Const PARAPORT_ERROR_INVALID_ADDRESS = (PARAPORT_ERROR Or 8&)
Public Const PARAPORT_ERROR_INVALID_CYCLE = (PARAPORT_ERROR Or 9&)
Public Const PARAPORT_ERROR_LIBRARY_NOT_COMPATIBLE = (PARAPORT_ERROR Or 10&)

Public Const PARAPORT_ERROR_MIN = PARAPORT_ERROR_INTERNAL_1
Public Const PARAPORT_ERROR_MAX = (PARAPORT_ERROR_LIBRARY_NOT_COMPATIBLE + 1)

' ///////////////////////////////////////////////////////////////////////////////
     

Attribute VB_Name = "ParaPortDll"
' ///////////////////////////////////////////////////////////////////////////////
' //
' // VB interface of ParaPort
' //
' // copyright (c) 2002, 2003, 2004 by Paul ADAM
' // all rights reserved
' // read the "http://www.ParaPort.net/TermsOfUse.html"
' //
' // more information on "http://www.ParaPort.net"
' //
' ///////////////////////////////////////////////////////////////////////////////

' ///////////////////////////////////////////////////////////////////////////////
' // new interface v2.0
' ///////////////////////////////////////////////////////////////////////////////

Public Declare Function getPortAddress Lib "C:\Program Files\ParaPort\bin\ParaPort.dll" (ByVal PortName As String) As Long
Public Declare Function inputPort Lib "C:\Program Files\ParaPort\bin\ParaPort.dll" Alias "input" (ByVal Address As Long) As Byte
Public Declare Function outputPort Lib "C:\Program Files\ParaPort\bin\ParaPort.dll" Alias "output" (ByVal Address As Long, ByVal ByteValue As Byte) As Byte

' ///////////////////////////////////////////////////////////////////////////////
     

VERSION 5.00
Begin VB.Form dlgSampleVB 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "sampleVB"
   ClientHeight    =   5145
   ClientLeft      =   6495
   ClientTop       =   5235
   ClientWidth     =   5745
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5145
   ScaleWidth      =   5745
   Begin VB.CommandButton btnExit 
      Cancel          =   -1  'True
      Caption         =   "Exit Application"
      Height          =   375
      Left            =   3960
      TabIndex        =   9
      Top             =   4560
      Width           =   1575
   End
   Begin VB.Frame fmRegAccess 
      Caption         =   "Direct Register Access"
      Height          =   3015
      Left            =   120
      TabIndex        =   11
      Top             =   1320
      Width           =   5415
      Begin VB.CommandButton btnControlRegWrite 
         Caption         =   "Write"
         Height          =   375
         Left            =   3000
         TabIndex        =   8
         Top             =   2400
         Width           =   975
      End
      Begin VB.CommandButton btnStatusRegRead 
         Caption         =   "Read"
         Height          =   375
         Left            =   4200
         TabIndex        =   6
         Top             =   1800
         Width           =   975
      End
      Begin VB.CommandButton btnDataRegRead 
         Caption         =   "Read"
         Height          =   375
         Left            =   4200
         TabIndex        =   4
         Top             =   1200
         Width           =   975
      End
      Begin VB.CommandButton btnDataRegWrite 
         Caption         =   "Write"
         Height          =   375
         Left            =   3000
         TabIndex        =   3
         Top             =   1200
         Width           =   975
      End
      Begin VB.TextBox tbControlReg 
         Height          =   405
         Left            =   2160
         TabIndex        =   7
         Top             =   2400
         Width           =   615
      End
      Begin VB.TextBox tbStatusReg 
         Height          =   405
         Left            =   2160
         TabIndex        =   5
         Top             =   1800
         Width           =   615
      End
      Begin VB.TextBox tbDataReg 
         Height          =   405
         Left            =   2160
         TabIndex        =   2
         Top             =   1200
         Width           =   615
      End
      Begin VB.Label lblControlReg 
         Caption         =   "Control Register:"
         Height          =   255
         Left            =   360
         TabIndex        =   17
         Top             =   2520
         Width           =   1695
      End
      Begin VB.Label lblStatusReg 
         Caption         =   "Status Register:"
         Height          =   255
         Left            =   360
         TabIndex        =   16
         Top             =   1920
         Width           =   1695
      End
      Begin VB.Label lblDataReg 
         Caption         =   "Data Register:"
         Height          =   255
         Left            =   360
         TabIndex        =   15
         Top             =   1320
         Width           =   1695
      End
      Begin VB.Label lblText3 
         Caption         =   "To write to data register, bit 4 of control register (32 ) must be cleared."
         Height          =   255
         Left            =   120
         TabIndex        =   14
         Top             =   840
         Width           =   5175
      End
      Begin VB.Label lblText2 
         Caption         =   "To read from data register, bit 4 of control register ( 32 ) must be set."
         Height          =   255
         Left            =   120
         TabIndex        =   13
         Top             =   600
         Width           =   5175
      End
      Begin VB.Label lblText1 
         Caption         =   "The values must be given or are displayed in decimal format."
         Height          =   255
         Left            =   120
         TabIndex        =   12
         Top             =   360
         Width           =   5175
      End
   End
   Begin VB.Frame fmPortParam 
      Caption         =   "Port Parameter"
      Height          =   975
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5415
      Begin VB.ComboBox cbxPort 
         Height          =   315
         Left            =   3240
         Style           =   2  'Dropdown List
         TabIndex        =   1
         Top             =   360
         Width           =   1935
      End
      Begin VB.Label lblPort 
         Caption         =   "Select one of the possible parallel ports:"
         Height          =   255
         Left            =   240
         TabIndex        =   10
         Top             =   360
         Width           =   2895
      End
   End
End
Attribute VB_Name = "dlgSampleVB"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' ///////////////////////////////////////////////////////////////////////////////
' //
' // sampleVB application main dialog management
' //
' // copyright (c) 2002, 2003, 2004 by Paul ADAM
' // all rights reserved
' // read the "http://www.ParaPort.net/TermsOfUse.html"
' //
' // more information on "http://www.ParaPort.net"
' //
' ///////////////////////////////////////////////////////////////////////////////


' ///////////////////////////////////////////////////////////////////////////////
' // Win32 API declarations (from the APIViewer tool)
' ///////////////////////////////////////////////////////////////////////////////
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Const ERROR_SUCCESS = 0&

' ///////////////////////////////////////////////////////////////////////////////
' // Internal variables
' ///////////////////////////////////////////////////////////////////////////////
Private SelectedPortAddress As Long




' ///////////////////////////////////////////////////////////////////////////////
' // Dialog box loading (entry point)
' ///////////////////////////////////////////////////////////////////////////////
Private Sub Form_Load()
    Dim Count As Long
    Dim PortAddress As Long
    Dim PortName As String

    For Count = 1 To PARAPORT_LPT_MAX
        PortName = "LPT" & Count
        PortAddress = getPortAddress(PortName)
        If (PortAddress <> 0&) And (GetLastError = ERROR_SUCCESS) Then
            cbxPort.AddItem PortName
        End If
    Next
    If cbxPort.ListCount = 0 Then
        MsgBox "No parallel port could be opened!" & vbLf & vbLf & "Check, if the ParaPort driver has been installed" & vbLf & "with the " & Chr(34) & "Add/Remove Hardware" & Chr(34) & " wizard." & vbLf & vbLf & "For help see " & Chr(34) & "http://www.paraport.net" & Chr(34) & ".", vbOKOnly, "sampleVB: Error"
    Else
        cbxPort.ListIndex = 0
    End If
    cbxPort_Change
End Sub

' ///////////////////////////////////////////////////////////////////////////////
' // Change of the selected port
' ///////////////////////////////////////////////////////////////////////////////
Private Sub cbxPort_Change()
    SelectedPortAddress = getPortAddress(cbxPort.Text)
End Sub

' ///////////////////////////////////////////////////////////////////////////////
' // Data register write button click
' ///////////////////////////////////////////////////////////////////////////////
Private Sub btnDataRegWrite_Click()
    Dim Result As Long
    Dim RegValue As Byte
  
    If IsNumeric(tbDataReg.Text) Then
        RegValue = tbDataReg.Text
    Else
        RegValue = 0&
    End If
    outputPort SelectedPortAddress + PARAPORT_ADDRESS_DATA, RegValue
    Result = GetLastError
    If Result <> ERROR_SUCCESS Then
        MsgBox "outputPort( PARAPORT_ADDRESS_DATA ) executed with error: " & Result & vbLf & "For help see " & Chr(34) & "http://www.paraport.net" & Chr(34) & ".", vbOKOnly, "sampleVB: Error"
    End If
End Sub

' ///////////////////////////////////////////////////////////////////////////////
' // Data register read button click
' ///////////////////////////////////////////////////////////////////////////////
Private Sub btnDataRegRead_Click()
    Dim Result As Long
    Dim RegValue As Byte
  
    RegValue = inputPort(SelectedPortAddress + PARAPORT_ADDRESS_DATA)
    Result = GetLastError
    If Result <> ERROR_SUCCESS Then
        MsgBox "inputPort( PARAPORT_ADDRESS_DATA ) executed with error: " & Result & vbLf & "For help see " & Chr(34) & "http://www.paraport.net" & Chr(34) & ".", vbOKOnly, "sampleVB: Error"
        tbDataReg.Text = ""
    Else
        tbDataReg.Text = RegValue
    End If
End Sub

' ///////////////////////////////////////////////////////////////////////////////
' // Status register read button click
' ///////////////////////////////////////////////////////////////////////////////
Private Sub btnStatusRegRead_Click()
    Dim Result As Long
    Dim RegValue As Byte
  
    RegValue = inputPort(SelectedPortAddress + PARAPORT_ADDRESS_STATUS)
    Result = GetLastError
    If Result <> ERROR_SUCCESS Then
        MsgBox "inputPort( PARAPORT_ADDRESS_STATUS ) executed with error: " & Result & vbLf & "For help see " & Chr(34) & "http://www.paraport.net" & Chr(34) & ".", vbOKOnly, "sampleVB: Error"
        tbStatusReg.Text = ""
    Else
        tbStatusReg.Text = RegValue
    End If
End Sub

' ///////////////////////////////////////////////////////////////////////////////
' // Control register write button click
' ///////////////////////////////////////////////////////////////////////////////
Private Sub btnControlRegWrite_Click()
    Dim Result As Long
    Dim RegValue As Byte
  
    If IsNumeric(tbControlReg.Text) Then
        RegValue = tbControlReg.Text
    Else
        RegValue = 0&
    End If
    outputPort SelectedPortAddress + PARAPORT_ADDRESS_CONTROL, RegValue
    Result = GetLastError
    If Result <> ERROR_SUCCESS Then
        MsgBox "outputPort( PARAPORT_ADDRESS_CONTROL ) executed with error: " & Result & vbLf & "For help see " & Chr(34) & "http://www.paraport.net" & Chr(34) & ".", vbOKOnly, "sampleVB: Error"
    End If
End Sub

' ///////////////////////////////////////////////////////////////////////////////
' // Exit button click
' ///////////////////////////////////////////////////////////////////////////////
Private Sub btnExit_Click()
    Unload dlgSampleVB
End Sub

' ///////////////////////////////////////////////////////////////////////////////
Copyright 2002 - 2017 by Paul ADAM, read the Terms of Use