ESC/POS Thermal Printer and Mono (or .Net)

Recently, I found small thermal printers sold online, like the Sparkfun’s one. (You may find these en eBay too.)  To communicate with these printers you will need a serial link, working at TTL levels.

I saw an Arduino lib on Blidr blog, but I’ve got a standard FTDI board and I wanted my printer to work with it.

So, I made ThermalDotNet: a .Net class to use these thermal printers.

 

First, the FTDI board to thermal printer wiring diagram (hand drawn, yay! \o/):

Printing (in C#) takes a few lines of code :

...
using System.IO.Ports;
using ThermalDotNet; //Don't forget to add the dll reference
...
// Replace /dev/tty with the name of your serial port.
// Can be COM1, COM2... on Windows, /dev/ttyUSB0 on Linux.
SerialPort printerPort = new SerialPort("/dev/tty", 9600);

// Connection to the printer
ThermalPrinter printer = new ThermalPrinter(printerPort); 

printer.WakeUp();   // Let's wake up the printer
printer.WriteLine("Hello World");
printer.LineFeed(); // Feed paper
printer.Sleep();    // Save some energy
Console.WriteLine("Printer is now offline.");
printerPort.Close();

At the moment, theses features are supported :

  • Simple text and standard text styles supported. (Bold, double size, reverse printing…)
  • Barcodes support
  • Image printing support (must be 384px wide)
  • Printer configuration support (heating time, speed, etc.)

You must have a good power supply to make this printer work properly, mine is a cheap ‘5V – 2A’ supply but its voltage falls down to 4.5V when the printing line needs a lot of black.

The workaround is to heat less dots at a time: by default 64 dots are heated up. I reduced this number to 16 in the printer configuration.

ThermalPrinter printer = new ThermalPrinter(serialPort);
printer.SetPrintingParameters(2,220,1);

or

ThermalPrinter printer = new ThermalPrinter(serialPort,2,220,1);
// (2+1*8) dots   = 24 dots heated up at a time (instead of 64)
// 220*10 µs      = 2200 µs of heating time (instead of 800 µs)
// 1*10 µs        = 10 µs of heating interval (instead of 20 µs)

In compensation, the printer is slower. If you need a fast printing, get a good 9V – 2A power supply!

More to come…

6 thoughts on “ESC/POS Thermal Printer and Mono (or .Net)

  1. Hello dear,
    I have the printer and FTDI
    download the project, still does not understand how to compile or run the code in windows
    Mono developer but I have not found says “ThermalDotNet”
    I can do.
    I am new to mono, but I program in windows and linux with ubuntu.
    Could you help me?

Leave a reply to Ciftci Cancel reply