Lazarus

Programming => General => Topic started by: Jonvy on August 19, 2022, 02:28:18 pm

Title: How to read data from printer?
Post by: Jonvy on August 19, 2022, 02:28:18 pm
Hell all,

Lazarus provide a sample program for raw data printing, under the installation folder

..\Lazarus\components\printers\samples\rawmode
rawmodetest.lpi

But this sample only can send data to printer, now I want to get the response information from printer, how can I do?
I use USB cable for the printer,and the port is virtual USB port.

Can anyone help me?

Best regards,
Jonvy
Title: Re: How to read data from printer?
Post by: superc on August 19, 2022, 02:31:30 pm
Hello, could you tell the printer model?
Title: Re: How to read data from printer?
Post by: rvk on August 19, 2022, 02:39:12 pm
Can you also explain what kind of data you want from the printer and why you don't go through the normal printer driver for this?
Title: Re: How to read data from printer?
Post by: Jonvy on August 19, 2022, 03:23:01 pm
Hello, could you tell the printer model?
It's Zebra printer.
Title: Re: How to read data from printer?
Post by: Jonvy on August 19, 2022, 03:33:06 pm
Can you also explain what kind of data you want from the printer and why you don't go through the normal printer driver for this?
I want to get text data from the printer.
Because it's Zebra barcode printer, it's often needed to get feedback from printer such as configuration, media, carbon,label length, alert information etc, some times I need upload grahp file from the printer.
Title: Re: How to read data from printer?
Post by: rvk on August 19, 2022, 03:51:58 pm
You would need to communicate directly with the printer via USB.

I'm not sure if it will work but you can begin here:
https://wiki.freepascal.org/Hardware_Access#USB
https://forum.lazarus.freepascal.org/index.php/topic,11435.0.html

Title: Re: How to read data from printer?
Post by: dje on August 19, 2022, 05:28:01 pm
Some ideas: It looks like Zebra release a Core Scanner SDK which looks like what you are after.
https://techdocs.zebra.com/dcs/scanners/sdk-linux/about/
Included in the SDK is a COM interface. There is a mention of it here (being used with Delphi).
https://developer.zebra.com/thread/4471

I'm not on a Windows machine ATM, but I would install the SDK, import the COM ("CoreScanner.exe") into Lazarus. This should generate a file similar to the Delphi's CoreScanner_TLB.pas.

From there I'd read though the SDK API to try to make sence of its structure. There is some Delphi code here, but not the CoreScanner_TLB.pas file.
http://git.hisco.co.kr/comternet/esb_agent/blob/master/ZebraCtrlUnit.pas

From what I can tell, the API should be the same as offered by Zebra's "supported languages".  It looks like there are other ways to communicate with those devices, but, I'd start with the SDK.

The worst case is, you have to use a little C#/Java/JS or C++.

Title: Re: How to read data from printer?
Post by: Jonvy on August 25, 2022, 07:21:38 am
You would need to communicate directly with the printer via USB.

I'm not sure if it will work but you can begin here:
https://wiki.freepascal.org/Hardware_Access#USB
https://forum.lazarus.freepascal.org/index.php/topic,11435.0.html

Yes, if I use USB directly, it can work, I tried before. But Lazarus use libusb, I must change windows printer driver to libuse to replace original mircrosoft's usbprint.sys.
It's not easy for user to do. Normal use don't have permission to do in windows OS.
Also USB programming is difficult.
Title: Re: How to read data from printer?
Post by: Jonvy on August 25, 2022, 07:43:23 am
Some ideas: It looks like Zebra release a Core Scanner SDK which looks like what you are after.
https://techdocs.zebra.com/dcs/scanners/sdk-linux/about/
Included in the SDK is a COM interface. There is a mention of it here (being used with Delphi).
https://developer.zebra.com/thread/4471

I'm not on a Windows machine ATM, but I would install the SDK, import the COM ("CoreScanner.exe") into Lazarus. This should generate a file similar to the Delphi's CoreScanner_TLB.pas.

From there I'd read though the SDK API to try to make sence of its structure. There is some Delphi code here, but not the CoreScanner_TLB.pas file.
http://git.hisco.co.kr/comternet/esb_agent/blob/master/ZebraCtrlUnit.pas

From what I can tell, the API should be the same as offered by Zebra's "supported languages".  It looks like there are other ways to communicate with those devices, but, I'd start with the SDK.

The worst case is, you have to use a little C#/Java/JS or C++.
I plan to communicate to Zebra printer, so I don't need SDK for scanner.

I'm already make a lazarus for COM and Ethernet interface, and it runs well for 2 years, and it can receive data from printer, for COM, I use Lazserial componment.
Now I just want to update my program, so it can support full interface, but for USB programming, it's a little difficult.
I tried to find an easy way for USB programming in Windows OS.
Title: Re: How to read data from printer?
Post by: SymbolicFrank on August 25, 2022, 09:11:32 am
USB is just a complex COM-port. Almost all barcode printers come with a virtual COM-port driver. Use that.

Windows printer driver is not the right tool for the job. Read the manual and send the ASCII codes needed to print what you want. It's not like you're printing a complex document, so that is most likely a lot easier as well.

You can treat a COM-port just like a file. StringList.SaveToFile('COM5') works.
Title: Re: How to read data from printer?
Post by: Jonvy on August 25, 2022, 12:19:03 pm
USB is just a complex COM-port. Almost all barcode printers come with a virtual COM-port driver. Use that.

Windows printer driver is not the right tool for the job. Read the manual and send the ASCII codes needed to print what you want. It's not like you're printing a complex document, so that is most likely a lot easier as well.

You can treat a COM-port just like a file. StringList.SaveToFile('COM5') works.

Actually each brand of scanner comes with virtual COM-port driver, I used it often for production line pc.
But for barcode printer, it supply with windows driver when you attach USB cable to PC. Like Zebra, it will provide ZDesigner driver, but it's one way, you can use it to send data or file to printer, but can not receive data from scanner.

What I want to do is to make program like attachment, commtools, it's very old windows software, but it can send & receive data by different ways, no need to change windows driver or install 3rd party driver, I don't know who write this program, but it's really good.
Title: Re: How to read data from printer?
Post by: MarkMLl on August 25, 2022, 12:47:16 pm
What I want to do is to make program like attachment, commtools, it's very old windows software, but it can send & receive data by different ways, no need to change windows driver or install 3rd party driver, I don't know who write this program, but it's really good.

In that case you're going to research what's known about the printer's control/status protocol, using other projects on Github etc., and roll your own software using LibUSB etc. You're also going to need to find a way to make sure that the OS doesn't claim exclusive access to it as soon as it's plugged in.

I've done that in the past for a thermal ribbon printer, and at some point will extend it to support Dymo etc. However that was pretty simple since it did just appears as a USB-connected serial device so was easy to monitor (even before the manufacturer coughed up the last few control sequences): something connected as a printer or a generic HID device would probably be more complex.

MarkMLl
Title: Re: How to read data from printer?
Post by: SymbolicFrank on August 26, 2022, 12:49:35 pm
What I want to do is to make program like attachment, commtools, it's very old windows software, but it can send & receive data by different ways, no need to change windows driver or install 3rd party driver, I don't know who write this program, but it's really good.
Looking at the communication tools screenshot, I notice where your confusion comes from. It looks like you can attach the same printer in multiple ways at the same time. Which is rarely the case, you can only select one interface at a time.

Next, they're basically all serially connections behind the screens. The hard part is first configuring that connection and then knowing which ASCII codes to send to perform a specific function. Generally, that's not something you can do from your program, it requires installing the drivers. And, of course, TCP/IP will require a socket instead of a COM-port.

If you want to make something generic, you're better off seeing if they support Epson 2 emulation mode, because a translation table isn't going to cut it. Like, some try to supply you with something alike a canvas, just like with a Windows printer, on which you can paint, while most other ones expect you to tell them to print this graph in this size and orientation at this location. Some require absolute pixel coordinates, others use relative locations. And the character sets are mostly unique, although most allow you to upload your own one.

I made a generic one once (in Delphi), but it was a lot of work and generally not worth it.
Title: Re: How to read data from printer?
Post by: MarkMLl on August 26, 2022, 12:57:12 pm
Next, they're basically all serially connections behind the screens. The hard part is first configuring that connection and then knowing which ASCII codes to send to perform a specific function. Generally, that's not something you can do from your program, it requires installing the drivers. And, of course, TCP/IP will require a socket instead of a COM-port.

https://en.wikipedia.org/wiki/Zebra_Programming_Language

MarkMLl
Title: Re: How to read data from printer?
Post by: SymbolicFrank on August 26, 2022, 01:18:36 pm
Next, they're basically all serially connections behind the screens. The hard part is first configuring that connection and then knowing which ASCII codes to send to perform a specific function. Generally, that's not something you can do from your program, it requires installing the drivers. And, of course, TCP/IP will require a socket instead of a COM-port.

https://en.wikipedia.org/wiki/Zebra_Programming_Language

MarkMLl

Yes, I know, I've used it. It's a simple page description language that tries to emulate a printer canvas. That was what the next part of the post was about.
Title: Re: How to read data from printer?
Post by: MarkMLl on August 26, 2022, 02:00:24 pm
Yes, I know, I've used it. It's a simple page description language that tries to emulate a printer canvas. That was what the next part of the post was about.

My point being that behaviour of those printers is well-understood, there's a minimum of new work or reverse engineering to be done.

Minimal Googling suggests that all you need is a simple terminal emulator (or Netcat etc., depending on the physical connection)... IOW much the same as most other devices of this type.

MarkMLl
Title: Re: How to read data from printer?
Post by: MarkMLl on September 01, 2022, 09:41:30 pm
Hello, could you tell the printer model?
It's Zebra printer.

WHAT MODEL OF ZEBRA?

...and if you say "odd-toed ungulate" I shall scream.

MarkMLl
TinyPortal © 2005-2018