Sending Raw Data to the Zebra Kiosk Printer

Article ID: 56495182

Details


Topic or Information

Sending raw data to Zebra Kiosk Printers

Applies To

Zebra Kiosk Printers

Details

In some cases, you may wish to send Zebra Kiosk printer commands to a printer, even while using the Windows driver. To do this, you must manually construct a print job that contains the control codes you wish to use. Below you will find a function that does this. (Written in VC++ 6.)

For example, to send the command ESC P 0 (print a self-test parameter sheet) you will call the function like this:/p> char buf[] = {0x1B, 0x50, 0x00};
bool result = RawDataToPrinter("TTP8200", (unsigned char *)buf, 3);

BOOL RawDataToPrinter(LPSTR szPrinterName, LPBYTE lpData, DWORD dwCount)
     {
       HANDLE       hPrinter;
       DOC_INFO_1       DocInfo;
       DWORD      dwJob;
       DWORD      dwBytesWritten;

        // Need a handle to the printer.
        if( ! OpenPrinter( szPrinterName, &hPrinter, NULL ) )
          return FALSE;

        // Fill in the structure with info about this "document."
        DocInfo.pDocName = "Demo Page";
        DocInfo.pOutputFile = NULL;
        DocInfo.pDatatype = "RAW";
        // Inform the spooler the document is beginning.
        if( (dwJob = StartDocPrinter( hPrinter, 1, (BYTE *)&DocInfo )) == 0 )
        {
          ClosePrinter( hPrinter );
          return FALSE;
        }
        // Start a page.
        if( ! StartPagePrinter( hPrinter ) )
        {
          EndDocPrinter( hPrinter );
          ClosePrinter( hPrinter );
          return FALSE;
        }
        // Send the data to the printer.
        if( !WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten ) )
        {
          EndPagePrinter( hPrinter );
          EndDocPrinter( hPrinter );
          ClosePrinter( hPrinter );
          return FALSE;
        }
        // End the page.
        if( ! EndPagePrinter( hPrinter ) )
        {
          EndDocPrinter( hPrinter );
          ClosePrinter( hPrinter );
          return FALSE;
        }
        // Inform the spooler that the document is ending.
        if( ! EndDocPrinter( hPrinter ) )
        {
          ClosePrinter( hPrinter );
          return FALSE;
        }
        // Tidy up the printer handle.
        ClosePrinter( hPrinter );
        // Check to see if correct number of bytes were written.
        if( dwBytesWritten != dwCount )
          return FALSE;
        return TRUE;
      }