UPDATE: After seeing the feature set of the more expensive Epson printer, I do think that anyone who wishes to have receipts printed, should use a feature rich printer. Some even have color printing capabilities.
As usual, a quick google search landed me on some Delphi code and most of the code were for those expensive printers. Mostly, Epson. Then I found a link to this page sending-a-bit-image-to-an-epson-tm-t88iii-receipt-printer-using-c-and-escpos which is a dead end now. Luckily, I searched using a piece of code from SFO and it landed me here. printing-utf-8-encoded-text-in-epson-tm-t88iv-thermal-printer
But still, I didn’t quite understand how to send POS commands to the printer. Then, after a while I found this page (Epson FX Printer Codes). Which is for EPSON FX printers but some of these codes worked for my printer too as it supported ESC/POS commands. I also found this PDF which has some details about the codes.
As an example, Say, I want to print large text, then I have to send 27 87 48 as separate one byte commands in sequence. Then, whatever I print next, will be printed as large text, until I send the command to reset to normal text.
After a lot of trial and error (and wasted paper), I managed to print an Okay-looking receipt using that cheap printer. Below is the code. You also need the code in the following gist. https://gist.github.com/dirnthelord/19cfa44056f641421247
If you have a cheap printer like I have, which is USB powered, then chances are it is already detected but you have to setup a printer in the Devices & Printers control panel section. Until you do this, you won’t be able to connect it using the code. (I tried)
So follow these steps to setup the printer,
- Go to Devices & Printers (Control Panel\All Control Panel Items\Devices and Printers)
- On the top menu, there is “Add a Printer”. (Windows 8.1)
- Select “The printer I want isn’t listed” => Next
- “Add a local printer with manual settings” => Next
- “Use an Existing Port” and select “USB001 (Virtual Printer Port For USB)” => Next
- Select “Generic” from Manufacturer, “Generic / Text Only” from Printers => Next
- If it asked, which version you want, keep recommended option and => Next
- Give a Printer Name, E.g.: “POS58” => Next
- “Do not share” but if you want, share it.
- Turn on your printer and click on “Print a test page”. It should print a long text.
- Click Finish and you are ready to use the printer in your code.
I don't even understand most of this code and I don't really care. If it works, why break it? I highly doubt that an interviewer will ask how to send EPOS/POS commands to a thermal printer. but if they do, Refer this Sending a bit image to an Epson TM-T88III receipt printer using C# and ESC/POS by Nicholas Piasecki on December 9th, 2009