## Printer Device Driver

[prev][next][parent][TOC]

### Sample Protocol Converter

A protocol converter is a DLL written to support printers capable of returning information to the host PC. A protocol converter is responsible for understanding the control language of the printer. Example control languages are Network Printer Alliance Protocol (NPAP), Printer Job Language (PJL), and Simple Network Management Protocol (SNMP). The protocol converter does not get involved in the physical transmission of commands or data to the printer. The converter generates appropriate printer commands to send to the printer, and the converter is able to translate data sent from the printer to the host PC.

Developers can write a usable protocol converter if they have a port driver that can communicate with a set of printers.

Our sample protocol converter does not support any control language. It uses strings as examples of data sent and received from a printer. An actual protocol converter would use printer control-language commands to query or set information in the printer.

Make copies of our protocol-converter makefile and source; then, change the string "PROTCNV" in the names of these files to a string that matches the new protocol converter being developed-e.g., "MYCNV". The OS2SYS.INI entry to install the sample protocol converter is:

      Application - "PM_PROTOCOL_CONVERTER"

      KeyName     - "PROTCNV"                  // Change to new converter name

      KeyValue    - "C:\OS2\DLL\PROTCNV.CNV"   // Change to path of new converter

Here is a code roadmap:

buildcmd.c Routines to build commands to send to the printer.

cache.c Routines to store information returned by the printer in the protocol converter's cache.

getcmd.c Routines to get response data from the protocol converter's cache.

init.c DLL initialization and termination routines.

passthru.c Routines to handle a bidirectional passthru session.

proctype.c Routines to process the ulType field to determine whether to get data from the cache or to ask the printer for the information.

sendcmd.c Exports SplProtSendCmd API, which is the main entry point for the protocol converter. For each command, this generates the control-language buffer to send to the port driver for transmission to the printer.

util.c Utility functions for the converter, including memory-allocation and global semaphore-access routines.

xlatecmd.c Exports SplProtXlateCmd API, which the port driver calls when data is received from the printer. These routines interpret the data coming from the printer and look for threads that may be waiting for this data.