Reading from a Port

A language monitor’s ReadPort implementation can call the port monitor’s ReadPort routine to get information from a bidirectional printer that it supports. The port monitor should simply return the raw data it receives from the printer to the calling language monitor.

Language monitors set time-outs on port monitors, and port monitors set time-outs on the physical device. A port monitor’s ReadPort implementation should time-out and log an error code if it cannot read data from the printer associated with the specified port or if it receives no response from the printer within some appropriate time interval. A port might return zero bytes on a read; in this case, ReadPort should return success.

Note that a port monitor must implement ReadPort, because a language monitor’s only method of communication with a bidirectional printer is through a port monitor.

Only language monitors are able to parse the strings of data read from a port to which a bidirectional printer is attached. A language monitor’s ReadPort or GetPrinterDataFromPort implementation calls the port monitor’s corresponding function to get data from a bidirectional printer. It is the port monitor’s ReadPort or GetPrinterDataFromPort function that reads any data available from the printer and passes that data back to the language monitor, but the port monitor should not change this data in any way. It is up to the language monitor to interpret the meaning of the data read from the printer.

The language monitor can call the port monitor’s GetPrinterDataFromPort or ReadPort from a background thread on a periodic basis, for example, every few seconds, to read unsolicited status information from a bidirectional printer. The PJLMON source code shows how to read unsolicited printer status information in this way.

A language monitor can support GetPrinterDataFromPort to query information from a bidirectional printer that supports the IEEE 1284 standard. A vendor defines the status request strings passed from the language monitor to the associated bidirectional printer.

A port monitor can implement GetPrinterDataFromPort to accommodate communication between a language monitor and bidirectional printer that support the IEEE 1284 specification. A port monitor’s GetPrinterDataFromPort routine makes supported IOCTL calls to IEEE 1284-compliant bidirectional printers and returns any data received from the printer to the calling language monitor. GetPrinterDataFromPort should use the Win32 DeviceIoControl function to send the IOCTL to the printing device.

All monitors that support GetPrinterDataFromPort should fail immediately with ERROR_INVALID_PARAMETER for registry keys they do not understand. This forces the spooler to obtain the key value itself from the registry.

A port monitor can implement GetPrinterDataFromPort to make IEEE 1284 specification IOCTL calls to bidirectional printers that support this specification. GetPrinterDataFromPort should call the Win32 DeviceIoControl function to send the IOCTL to the printing device.