Reading status from Zebra Printer

后端 未结 5 1051
日久生厌
日久生厌 2021-01-04 08:52

I\'m working on a project where we need to use a Zebra Printer for barcode labels. We\'re using C#, and we\'re doing OK on the printing side of things, sending raw ZPL stri

5条回答
  •  离开以前
    2021-01-04 09:30

    ReadPrinter will not help in this situation. It will read back the print job you have submitted to the printer, not the printer's response. However, for the sake of completeness: In order to use ReadPrinter, you must open the printer again, using the combined "printer name - job id" syntax:

    OpenPrinter("Zebra,Job 12345", ...);
    ReadPrinter(hPrinter, ...);
    

    This will only work if the job 12345 has not been removed yet.


    As for answering the question, you have to use WriteFile to send data and ReadFile to get the response. To use those functions, you need to open the printer with CreateFile. After you've done that, the rest is absolutely trivial.

    The problem here is getting the device path that must be passed to CreateFile in order to open the printer. If your printer is an LPT one, that's as simple as "LPT:", but for a USB printer you have to obtain the device path, which looks like this:

    \\?\usb#vid_0a5f&pid_0027#46a072900549#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}

    I have found a way to obtain this path, but it only works if you have just one printer installed. If you have more, you will need a relation between the device path and the printer name you see in the control panel, and that relation is something I haven't figured yet. I've created a question for that: Figuring which printer name corresponds to which device ID.

提交回复
热议问题