The following is an alphabetical listing of the PortIO95 control codes that the PortIO95 VxD will accept through a DeviceIoControl() call and the actions performed. Also given are sample calls (for Visual C++ Version 4.0), possible error conditions and the names of related or similar control codes. All calls require a hDevice parameter obtained by loading the PortIO95 VxD. See the section entitled Loading the PortIO95 VxD for more information.
int retval; retval=DeviceIoControl(hDevice, PORTIO_DEBUGMODEOFF, NULL, \ 0, NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_DEBUGMODEOFF"); printf("Debug mode is off\n");
The PORTIO_DEBUGMODEOFF control code disables the PortIO95 VxD debug mode. It will close the debug output file (C:\portio95.log) gently.
Failures:
int retval; retval=DeviceIoControl(hDevice, PORTIO_DEBUGMODEON, NULL, \ 0, NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_DEBUGMODEON"); printf("Debug mode is on\n");
The PORTIO_DEBUGMODEON control code enables the PortIO95 VxD debug mode. Debug information is written to a file and every subsequent call to any PortIO95 VxD control code will record its actions there. The file created will be called C:\portio95.log and will always be truncated if it already exists. If this function is called when debug mode is already on, it will leave with success and ignore the call without truncating the output file. In this version of PortIO95, the debug filename is hard coded. It is (currently) not possible to point the debugging file at another destination.
Failures:
Warnings:
int retval; char cLPT1; retval=DeviceIoControl(hDevice, PORTIO_FINDLPT1, NULL, 0, &cLPT1,\ sizeof(cLPT1), NULL, NULL); if (!retval) Handle_Error("PORTIO_FINDLPT1"); if(cLPT1 == '1') printf("LPT1 found \n"); else printf ("LPT1 not found \n");
The PORTIO_FINDLPT? function calls return information about the presence or non-presence of the specified LPT port on the computer. Requires a pointer to a byte field in the lpOutBuffer of the DeviceIoControl call. On successful return, the contents of the lpOutBuffer will be non-zero indicating the port is present or NULL if the port is not present. The actual non-zero value placed in the lpOutBuffer is an ASCII numeral '1', '2', or '3' depending on the call made. Internally these calls access the bytes in memory location 0x408 to determine which ports are present.
Failures:
Warnings:
int retval; char szVersionStr[MAX_PORTIO_VERSION_STR_LEN+1]; retval=DeviceIoControl(hDevice, PORTIO_GETVERSION, NULL, 0, \ &szVersionStr, MAX_PORTIO_VERSION_STR_LEN, NULL, NULL); if (!retval) Handle_Error("PORTIO_GETVERSION"); printf("Version is %s\n",szVersionStr);
The PORTIO_GETVERSION control code returns a string containing the current version number. Memory for the version string must be allocated within the application and a pointer to it is passed in lpInBuffer field of the DeviceIoControl call. It is possible to pass a NULL in this field (or insufficient size in the nInBufferSize field) in which case the call will still return success (i.e. true or 1). This mode is useful to determine whether the VxD is loaded as a successful return always indicates contact with the PortIO95 VxD.
int retval; retval=DeviceIoControl(hDevice, PORTIO_PIN2LOW, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_ PIN2LOW");The PORTIO_PIN?LOW control codes set a bit in the appropriate parallel port register such that the attached pin is false (i.e. logic 0). Any hardware inversion on the pin is compensated for internally and the pin state will always be low. These calls are designed to provide a simple method of setting the state of certain pins.
The control codes marked with a * access the control register. These pins can be set individually as inputs or outputs (but not both at the same time). To access these pins as outputs you must set them up as outputs via the PORTIO_SETPIN?ASOUTPUT control call (individually) or PORTIO_SETPINS_1_14_16_17_AS_OUTPUT (for all). This only needs to be done once and stays in effect until reset.
Failures:
See Also:
int retval; retval=DeviceIoControl(hDevice, PORTIO_PIN2HIGH, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_ PIN2HIGH");
The PORTIO_PIN?HIGH control codes set a bit in the appropriate parallel port register such that the attached pin is true (i.e. logic 1). Any hardware inversion on the pin is compensated for internally and the pin state will always be high. These calls are designed to provide a simple method of setting the state of certain pins.
The control codes marked with a * access the control register. These pins can be set individually as inputs or outputs (but not both at the same time). To access these pins as outputs you must set them up as outputs via the PORTIO_SETPIN?ASOUTPUT control call (individually) or PORTIO_SETPINS_1_14_16_17_AS_OUTPUT (for all). This only needs to be done once and stays in effect until reset.
Failures:
See Also:
int retval; char cOutData; retval=DeviceIoControl(hDevice, PORTIO_READC0, NULL, 0,\ &cOutData, sizeof(cOutData), NULL, NULL); if (!retval) Handle_Error("PORTIO_READC0"); if (cOutData == '\0') printf("Bit C0 is LOW\n"); else printf("Bit C0 is HIGH\n");
The PORTIO_READC? control codes reads the specified bit in the parallel port control register. Any hardware inversion on the bit is compensated for internally and the bit state will always correspond to the state (logic high or low) of the corresponding pin. The return value is true (i.e. non-zero) for success.
The pins attached to the control register are capable of being used as inputs or outputs. PortIO95 considers the pins to be outputs by default. To read these pins, they must be activated within PortIO95 as inputs. Calls to activate each of the four control register bits for input individually via PORTIO_SETC?INPUT must be made. Alternatively, a call to PORTIO_SETCREGINPUT before this function, would also be acceptable.
The bits in the parallel port control register correspond to the following pins:
Note: the PORTIO_READC? control codes are synonyms for some of the PORTIO_READPIN? codes. The exact mapping is as given above.
Failures:
See Also:
int retval; char cOutData; retval=DeviceIoControl(hDevice, PORTIO_READCREG, NULL,\ 0, &cOutData, sizeof(cOutData), NULL, NULL); if (!retval) Handle_Error("PORTIO_READCREG"); printf("The C Register value is: 0x%X hex\n",cOutData);
The PORTIO_READCREG control code reads the parallel port control register and returns the lower nibble (the only really meaningful portion) in a byte to the caller. This call is designed to provide a simple, logical 4 bit input mechanism. Several pins (those associated with bits 0,1,3) connected to the control register are inverted by the hardware. The PORTIO_READCREG control code internally compensates for this. Thus, all returned bits reflect the true logic state of the pins attached to the parallel ports control register. The upper 4 bits returned in this call are always set to 0 (logic low).
The pins attached to the control register are capable of being used as inputs or outputs. PortIO95 considers the pins to be outputs by default. To read these pins they must be activated within PortIO95 as inputs. A call must be made to PORTIO_SETCREGINPUT before this function. Alternatively, calls to activate each of the four control register bits for input individually via PORTIO_SETC?INPUT would also be acceptable.
Note that in the returned byte:
Failures:
See Also:
int retval; char cOutData; retval=DeviceIoControl(hDevice, PORTIO_READCREGRAW, NULL,\ 0, &cOutData, sizeof(cOutData), NULL, NULL); if (!retval) Handle_Error("PORTIO_READCREGRAW"); printf("The raw C Register value is: 0x%X hex\n",cOutData);
The PORTIO_READCREGRAW control code reads the parallel ports control register and returns the entire byte to the caller - as is. This call is designed to return exactly what the LPT port thinks it has there. The PortIO95 VxD does nothing but read. Several pins (those associated with bits 0,1,3) connected to the control register are inverted by the hardware. This inversion is preserved as-is.
The pins attached to the control register are capable of being used as inputs or outputs. PortIO95 considers the pins to be outputs by default. These pins must be activated within PortIO95 as inputs before they can be read. Call PORTIO_SETCREGINPUT before this function. Alternatively, calls to activate each of the four control register bits for input individually via PORTIO_SETC?INPUT would also be acceptable.
Note that in the returned byte:
Failures:
See Also:
int retval; char cOutData; retval=DeviceIoControl(hDevice, PORTIO_READ_CS_BYTE, NULL,\ 0, &cOutData, sizeof(cOutData), NULL, NULL); if (!retval) Handle_Error("PORTIO_READCREG"); printf("The CS byte value is: 0x%X hex\n",cOutData);The PORTIO_READ_CS_BYTE control code returns a composite byte consisting of selected bits from the control and status registers. This byte always compensates for any hardware inversion on the pins and gives you bits that reflect the true state of the pins. This call is designed to provide an easy to use, readily assembled 8 bit input.
Internally the status register (minus bit 6 which can be used as an interrupt trigger) is set up as the low nibble and the control register is the high nibble. The bit to pin mapping works as follows:
The pins attached to the control register are capable of being used as inputs or outputs. PortIO95 considers the pins to be outputs by default. To read these pins they must be activated within PortIO95 as inputs. A call must be made to PORTIO_SETCREGINPUT before this function. Alternatively, calls to activate each of the four control register bits for input individually via PORTIO_SETC?INPUT would also be acceptable.
Failures:
See Also:
int retval; char cOutData; retval=DeviceIoControl(hDevice, PORTIO_READPIN10, NULL, 0,\ &cOutData, sizeof(cOutData), NULL, NULL); if (!retval) Handle_Error("PORTIO_READPIN10"); if (cOutData == '\0') printf("Pin 10 is is LOW\n"); else printf("Pin 10 is HIGH\n");The PORTIO_READPIN? control codes read the appropriate parallel port register and return a value of true or false (i.e. 1 or 0) indicating the logic state of the pin. Any hardware inversion on the pin is compensated for internally and the value returned reflects the true logic state of the pin. These calls are designed to provide a simple method of detecting the state of certain pins.
The control codes marked with a * access the control register. These pins can be set individually as inputs or outputs (but not both at the same time). To read data from these pins you must set them up as inputs via the PORTIO_SETPIN?ASINPUT control call (individually) or PORTIO_SETPINS_1_14_16_17_AS_INPUT (for all). This only needs to be done once and stays in effect until reset.
Failures:
See Also:
int retval; char cOutData; retval=DeviceIoControl(hDevice, PORTIO_READS3, NULL, 0,\ &cOutData, sizeof(cOutData), NULL, NULL); if (!retval) Handle_Error("PORTIO_READS3"); if (cOutData == '\0') printf("Bit S3 is is LOW\n"); else printf("Bit S3 is HIGH\n");
The PORTIO_READS? control codes read the specified bit in the parallel port status register. Any hardware inversion on the bit is compensated for internally and the bit state will always correspond to the state (logic high or low) of the corresponding pin. The return value is true (i.e. non-zero) for success.
The bits in the parallel port status register correspond to the following pins:
Note: the PORTIO_READS? control codes are synonyms for some of the PORTIO_READPIN? codes. The exact mapping is as given above.
Failures:
See Also:
int retval; char cOutData; retval=DeviceIoControl(hDevice, PORTIO_READSREG, NULL,\ 0, &cOutData, sizeof(cOutData), NULL, NULL); if (!retval) Handle_Error("PORTIO_READSREG"); printf("The S Register value is: 0x%X hex\n",cOutData);The PORTIO_READSREG control code reads the parallel port status register and returns a byte (only the lower nibble is significant) composed of certain bits in the status register. This call is designed to provide a simple, logical 4 bit input mechanism. Pin 11 (associated with bit 3) is inverted by the hardware. The PORTIO_READSREG control code internally compensates for this. Thus, all returned bits reflect the true logic state of the pins attached to the parallel ports status register. The upper 4 bits returned in this call are always set to 0 (logic low). The presence of pin 10 (usually at bit 6) is removed from the information returned by this call. This pin is usually used to trigger interrupts.
Note that pins:
Failures:
See Also:
int retval; char cOutData; retval=DeviceIoControl(hDevice, PORTIO_READSREGRAW, NULL,\ 0, &cOutData, sizeof(cOutData), NULL, NULL); if (!retval) Handle_Error("PORTIO_READSREGRAW"); printf("The raw S Register value is: 0x%X hex\n",cOutData);
The PORTIO_READSREGRAW control code reads the parallel ports
status register and returns the entire byte to the caller - as
is. This call is designed to return exactly what the LPT port
thinks it has there - the PortIO95 VxD does nothing but read.
Pin 11 (associated with bit 7) connected to the status register
is inverted by the hardware. This inversion is preserved as-is.
Bits 0, 1 and 2 are not attached to pins and are reported unmodified
from the status register state.
Note that pins:
Failures:
See Also:
The PORTIO_SEND_BYTE_TO_PINS1_14_16_17 control code is a synonym for PORTIO_WRITECREG. See the PORTIO_WRITECREG for more details.
The PORTIO_SEND_BYTE_TO_PINS2_TO_9 control code is a synonym
for PORTIO_WRITEDREG. See the PORTIO_WRITEDREG for more details.
These are synonyms for the PORTIO_SETPIN?ASINPUT control codes. The equivalence is as follows:
See the PORTIO_SETPIN?ASINPUT section for more information.
These are synonyms for the PORTIO_SETPIN?ASOUTPUT control codes. The equivalence is as follows:
See the PORTIO_SETPIN?ASOUTPUT section for more information.
int retval; retval=DeviceIoControl(hDevice, PORTIO_SETCREGINPUT, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_SETCREGINPUT ");
Pins attached to the control register are capable of being used as inputs or outputs. The PORTIO_SETCREGINPUT control code tells the PortIO95 VxD that the pins attached to the control register should be enabled as inputs. Alternatively, the four control register pins can be enabled as inputs using calls with PORTIO_SETC?INPUT control code. The PORTIO_SETCREGINPUT control call enables all pins in the control register as inputs and overrides any individual pin settings. Note that in order to enable the control register pins as inputs the pins must be set to logic high. This is done internally in the PORTIO_SETCREGINPUT call. This control code only needs to be called once and stays in effect until reset.
Failures:
See Also:
Warnings:
int retval; retval=DeviceIoControl(hDevice, PORTIO_SETCREGOUTPUT, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_SETCREGOUTPUT ");
Pins attached to the control register are capable of being used as inputs or outputs. The PORTIO_SETCREGOUTPUT control code tells the PortIO95 VxD that the pins attached to the control register should be enabled as outputs. Alternatively, the four control register pins can be enabled as outputs using calls with PORTIO_SETC?OUTPUT control code. The PORTIO_SETCREGOUTPUT control call enables all pins in the control register as outputs and overrides any individual pin settings. This control code only needs to be called once and stays in effect until reset.
Failures:
See Also:
Warnings:
int retval; retval=DeviceIoControl(hDevice, PORTIO_SETC0, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_SETC0");The PORTIO_SETC? control codes set the specified bit in the parallel port control register to a logical high (i.e. 1). Any hardware inversion on the pin is compensated for internally and the pin state will always be high. The return value is true (i.e. non-zero) for success.
The pins attached to the control register are capable of being
used as inputs or outputs. PortIO95 considers the pins to be outputs
by default. However, these pins should be activated within PortIO95
as outputs before they are written. Call PORTIO_SETCREGOUTPUT
before this function. Alternatively, calls to activate the appropriate
control register bits for output individually via PORTIO_SETC?OUTPUT
would also be acceptable.
The bits in the parallel ports control register correspond to the following pins:
Note: the PORTIO_SETC? control codes are synonyms for some of the PORTIO_PIN?HIGH codes. The exact mapping is as given above.
Failures:
See Also:
int retval; retval=DeviceIoControl(hDevice, PORTIO_SETD0, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_SETD0");
The PORTIO_SETD? control codes set the specified bit in the parallel ports data register to a logical high (i.e. 1). The return value is true (i.e. non-zero) for success. The bits in the parallel ports data register correspond to the following pins:
Note: the PORTIO_SETD? control codes are synonyms for some of the PORTIO_PIN?HIGH codes. The exact mapping is as given above.
Failures:
See Also:
int retval; retval=DeviceIoControl(hDevice, PORTIO_SETPIN1ASINPUT, NULL,0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_SETPIN1ASINPUT ");Pins attached to the control register are capable of being used as inputs or outputs. The PORTIO_SETPIN?ASINPUT control code tells the PortIO95 VxD that the specified pin attached to the control register should be enabled as an input. Note that in order to enable the control register pins as inputs the pins must be set to logic high. This is done internally in the PORTIO_SETPIN?ASINPUT call. This control code only needs to be called once and stays in effect until reset.
Failures:
See Also:
Warnings:
int retval; retval=DeviceIoControl(hDevice, PORTIO_SETPIN1ASOUTPUT, NULL,0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_SETPIN1ASOUTPUT ");Pins attached to the control register are capable of being used as inputs or outputs. The PORTIO_SETPIN?ASOUTPUT control code tells the PortIO95 VxD that the specified pin attached to the control register should be enabled as an output. This control code only needs to be called once and stays in effect until reset.
Failures:
See Also:
Warnings:
The PORTIO_SET_PINS_1_14_16_17_AS_INPUT control code is a synonym for PORTIO_SETCREGINPUT. See the PORTIO_SETCREGINPUT for more details.
The PORTIO_SET_PINS_1_14_16_17_AS_OUTPUT control code is a synonym for PORTIO_SETCREGOUTPUT. See the PORTIO_SETCREGOUTPUT for more details.
int retval; char cPortToUse='1'; retval=DeviceIoControl(hDevice, PORTIO_SETPORT, &cPortToUse,\ sizeof(cPortToUse), NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_SETPORT"); printf("PortIO95 set to use LPT%c \n",cPortToUse);
The PORTIO_SETPORT control code will set the parallel port that the PortIO95 VxD will use for subsequent calls to the port. This is a very important call and is required. No PortIO95 control codes other than this one accept a parallel port number to operate on. This call is the only way the PortIO95 VxD can be told the port to manipulate. Requires a pointer to a byte field in the lpInBuffer of the DeviceIoControl call. This byte field should contain an ASCII character indicating the parallel port to use. Currently the values '1', '2', and '3' are allowed. The only function calls that can operate without a set parallel port are:
Failures:
Warnings:
int retval; retval=DeviceIoControl(hDevice, PORTIO_UNSETC0, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_UNSETC0");
The PORTIO_UNSETC? control codes set the specified bit in the
parallel port control register to a logical low (i.e. 0). Any
hardware inversion on the pin is compensated for internally and
the pin state will always be low. The return value is true (i.e.
non-zero) for success.
The pins attached to the control register are capable of being used as inputs or outputs. PortIO95 considers the pins to be outputs by default. However, these pins should be activated within PortIO95 as outputs before they are written. Call PORTIO_SETCREGOUTPUT before this function. Alternatively, calls to activate the appropriate control register bits for output individually via PORTIO_SETC?OUTPUT would also be acceptable.
The bits in the parallel ports control register correspond to the following pins:
Note: the PORTIO_SETC? control codes are synonyms for some of the PORTIO_PIN?HIGH codes. The exact mapping is as given above.
Failures:
See Also:
int retval; retval=DeviceIoControl(hDevice, PORTIO_UNSETD0, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_UNSETD0");
The PORTIO_UNSETD? control codes set the specified bit in the parallel port data register to a logical low (i.e. 0). The return value is true (i.e. non-zero) for success. The bits in the parallel ports data register correspond to the following pins:
Note: the PORTIO_UNSETD? control codes are synonyms for some of the PORTIO_PIN?LOW codes. The exact mapping is as given above.
Failures:
See Also:
int retval; retval=DeviceIoControl(hDevice, PORTIO_UNSETPORT, NULL, 0,\ NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_UNSETPORT");
The PORTIO_UNSETPORT control code will undefine the parallel port (set by PORTIO_SETPORT) that PortIO95 VxD uses for subsequent calls. Calling PORTIO_UNSETPORT will reset the port (if any) in use. If no port has been set this call will return success (i.e. true or 1). This function should be called on program exit.
Warnings:
int retval; cInData=0xA; retval=DeviceIoControl(hDevice, PORTIO_WRITECREG, &cInData,\ sizeof(cInData), NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_WRITECREG");The PORTIO_WRITECREG control code writes a byte (of which only the lower nibble is meaningful) out to the parallel port control register. Several pins (those associated with bits 0,1,3) connected to the control register are inverted by the hardware. The PORTIO_WRITECREG control code internally compensates for this. Thus, the output logic state of the pins attached to the parallel ports control register (as seen by any devices reading them) will reflect logic of the bits in this call. This call is designed to provide a simple, logical 4 bit output mechanism. The upper 4 bits of the control register will be preserved through this call.
The pins attached to the control register are capable of being
used as inputs or outputs. PortIO95 considers the pins to be outputs
by default. However, these pins should be activated within PortIO95
as outputs before they are written. Call PORTIO_SETCREGOUTPUT
before this function. Alternatively, calls to activate each of
the four control register bits for output individually via PORTIO_SETC?OUTPUT
would also be acceptable.
Note that in the input byte:
Failures:
See Also:
int retval; cInData=0xA; retval=DeviceIoControl(hDevice, PORTIO_WRITECREGRAW, &cInData,\ sizeof(cInData), NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_WRITECREGRAW");The PORTIO_WRITECREGRAW control code writes a byte (of which only the lower nibble is meaningful) out to the parallel port control register. Several pins (those associated with bits 0,1,3) connected to the control register are inverted by the hardware. The PORTIO_WRITECREGRAW control code makes no compensation for this. Thus, the logic of the bits in this call will have to be adjusted to cope with the hardware inversion if output logic state of the pins attached to the parallel ports control register (as seen by any devices reading them) are to be correctly manipulated. This call is designed to provide a non interpreted 4 bit output mechanism. The upper 4 bits of the control register will be preserved through this call.
The pins attached to the control register are capable of being
used as inputs or outputs. PortIO95 considers the pins to be outputs
by default. However, these pins should be activated within PortIO95
as outputs before they are written. Call PORTIO_SETCREGOUTPUT
before this function. Alternatively, calls to activate each of
the four control register bits for output individually via PORTIO_SETC?OUTPUT
would also be acceptable.
Note that in the output byte:
Failures:
See Also:
int retval; cInData=0xA; retval=DeviceIoControl(hDevice, PORTIO_WRITEDREG, &cInData,\ sizeof(cInData), NULL, 0, NULL, NULL); if (!retval) Handle_Error("PORTIO_WRITEDREG");The PORTIO_WRITEDREG control code writes a byte out to the parallel port data register. The output logic state of the pins attached to the parallel ports control register (as seen by any devices reading them) will reflect logic of the bits in this call. This call is designed to provide a simple, logical 8 bit output mechanism. This call always returns true (i.e. 1) for success.
Failures:
See Also: