How to: Standalone C# printing on Epson Thermal printer - c#

For the first time I've been given this Thermal printer (M325A) to use, at this stage I have ZERO idea of how to code my desktop application to print "ANYTHING". But my present requirement will be to print just 4 lines of information:-
Pre-mentioned Static Banner (Big text),
User supplied numeric value (Non-Decimals),
Serial Number (Progressive),
Current Date & Time.
Kindly help me start.

While there are printing libraries out there, you can as well directly connect to the printer, over serial, USB, or, ethernet, and send it the commands to print. ESC/POS capable printers interpret escape sequences, which are very well documented. You must, however, get to know how you can send binary data (i.e. 8-bit bytes) directly to the printer.

Related

Zebra ZPL print job fails intermittently

I am generating ZPL labels in a C# windows service. The service is simple in srtucture... it uses the System.IO.FileSystemWatcher to detect when a new file is created by our ERP, it then parses the file, gets a chunk of data from SQL about thie job and formats this into validated ZPL.
It then uses the StreamWriter and TcpClient classes to create a connection to a Zebra label printer and sends the ZPL to port 9100. This is a technique we have used in the past without issue.
We use exclusively Zebra GK420D printers.
Here is the weird bit. Sometimes, when the job is sent to the printer, the LED just flashes - no label is printed. If you look at the configuration page in the web interface for that printer, it reports it is busy processing a job. the job appears in the job log absolutely fine, but the printer is seized up. You can't print a config label (as you would usually by holding down the feed button for a few seconds). You can reboot the printer, resubmit the job, and it will print... but this is not guaranteed. Frequently it will just flash again. You can send the same ZPL to another printer and it will print fine.
The ZPL being produced is around 4000 - 4500 bytes long. We have validated the ZPL using online tools to reproduce the label we want to print, and they all appear to be fine.
Has anyone seen anything like this before? It is baffling us here...
Check the firmware on the printer to make sure it's the most current. It sounds like you're doing the right things, even with the pause. I know if you send more data than it has available the printer will stall until it's power cycled.

Printing text and images on an LPT port

I'm working on c#.net application that already use serial port to print ticket with text and a little image as logo by thermal printer.
Now i need to migrate the implementation to allow application to print through Parallel Port because the hardware is changed...
For serial port (COM1...COMN) i used ESC/POS command..
is it possible continue to use ESC/POS and redirect the print to parrallel?..
exist documentation?..
i found many doc to print text only .
what i have to do to print image?
thanks
.NET abstracts printing from the printer, so the code is the same regardless of whether the printer is serial, on the network, connected via parallel port, or connected via bluetooth. To print an image, you would use the DrawImage method of the Graphics object--more detail can be found on MSDN.
Whether the printer is on parallel port or serial port is a function of how the printer is defined in Windows, and is not important to .NET.
However, if you are resorting to sending raw escape sequences and bypassing the use of a printer driver (such as referenced by ESC/POS), then you are making a whole world of extra work for yourself, and you'll need to refer to the printer's technical documentation for how to do what you ask.

How to print directly to a printer connected to serial port via .net desktop application

I've been working on a desktop application built using .NET Framework 4.5 and C# as language. Requirement is that a printer will be connected on serial port, port settings will be provided by user through the application like port number, baud rate etc. etc.
When user hits a print button, it should directly print to the printer without showing a print dialogue.
I've never done printing from desktop application and i've no idea how to achieve this.
Should i have to code specific to driver of that printer?
Or is there any generic way to send print instructions to printer connected to serial port?
I can send normal string to serial port, but what if i need to do some formatting like drawing a table, how can i make a serial port printer printing a formatted table and values inside it ... for example a bill.
Any help would be greatly appreciated.
Thanks,
Amit
You will want to send ESC/POS commands. This will control the font, line height, etc. as well as the actual text being transmitted.
http://pyramidacceptors.com/cms/wp-content/uploads/2013/02/ESC_POS_Protocol_Commands_REV_B.pdf
Another userful SO question: How to use esc/pos command with c#?
Also, no need to reinvent the wheel. Check Github for a library: https://github.com/yukimizake/ThermalDotNet
As far as generating tables and other such non-text, you'll want to read up on the command set supported by your target printer. If you're printing a bill, it sounds like you are targeting a thermal printer. Image/non-text support will vary from model to model.

How to send a Font File to a Zebra Printer (MZ 220) via .Net SDK?

I have to send custom Font Files to a Zebra MZ 220 Printer via C# and the Zebra .Net SDK. That SDK provides a SendFile() Method and it works with template Files percectly but whenever I send a Font File the printer starts printing out the File while receiving it.
The Zebra Software Label Vista has a Menu option Send Font but I have to do ist programmatically.
Does anyone know how to send Font Files to the Printer?
Thank you very much
twickl
You will need to wrap the file in a special download command in order for the printer to store the file.
The command is detailed in the ZPL Guide under "CISDFCRC16".
Basic format for the command -
! CISDFCRC16
<crc> // 4 digit hex CRC. Enter 0000 to turn off CRC check.
<filename> // file name with extension. 8.3 filenames only.
<size> // eight digit hex file size in bytes.
<checksum> // four digit hex checksum. Enter 0000 to turn off checksum validation.
<data> // Binary data to store
This will allow you to store a file on the printer's file system.
Note: The printer will not understand a typical .ttf file. You will need to convert the font to a .CPF file using Label Vista, and then send it down using this command.
I've worked with LP 2824 to automatically print labels with EPL and used the RawPrinterHelper class from Microsoft, with the bug fix from here. The class has a SendFileToPrinter method which might be worth a try (I haven't used it, so I don't know if it works for fonts)
I would like to add to James's answer. He is indeed correct the '! CISDFCRC16' call does work.
I initially was having a lot of trouble getting it to work however because I implementing my own CRC and Checksum logic.
When uploading the file to the printer I was always getting a 'Checksum failed' message come out of the printer. Even after implementing the CRC/Checksum logic given to us in the CPCL programming manual.
The only way I managed to get this to work was by using Zebra's CpclCrcHeader class to calculate the CRC using the CpclCrcHeader.getCRC16ForCertificateFilesOnly(byteArray).toUpperCase() and the Checksum using the CpclCrcHeader.getWCheckSum(byteArray).toUpperCase()
Hope that helps anyone else wanting to manage all the files on their Zebra printers.

How to get "printer ready bytes" from a source in c#?

I'm in a bit of trouble here, hoping you can help a fellow programmer out.
I have an application that receives a pointer to raw bytes (plus length and stuff) and sends said raw data to a printer. This is important, I have no choice but to use this method to get any printing done.
If I send a raw string, it will print with no problem. However, I need to be able to print formatted text, images, etc. So the thing is... I would like to be able to get printer ready bytes from a given source (maybe a pdf, or html, does not matter as long as it contains formatted text and/or images). It would be like "splitting" the print command like so:
a) Open file and read data
b) Load printer data into memory
c) Send bytes to printer
Obviously, I've got a) and c) covered, it's b) the one that's breaking my head.
Any thoughts?
Thanks in advance for your help.
What you need is the printer processor to receive your print command and create formatted data. You wouldn't want to do this yourself, I hope (formatting to printer-ready data, even if you know PS, AFP, PCL or what it is nowadays, by heart, is very hard and months work). Instead, the printer processor of Windows should be used.
If you're on Windows (I assume, because you use C#, but perhaps you use Mono), you can send any printer command to a file (simply use the FILE: port). To create the formatted data, use any PDF library you have, or use RTF, which is supported by the .NET Framework, and send it to the selected printer (which should match the same printer that's on the other end of your application), which is configured on port FILE:.
The raw print data is then on disk, which you can simply read in as a byte array and send to your actual printer using the application you already got.

Categories