This project is read-only.

Toolbox.NETMF.Hardware.ThermalPrinter

Toolbox.NETMF.Hardware.ThermalPrinter(SerialPort = "COM1", BaudRate = 19200)
  • SerialPort The serial port the printer is connected to
  • BaudRate The speed of the printer

Methods

  • Dispose() Disposes the object and frees the serial port pins
  • LineFeed() Will feed a line on the printer
  • Print(Data) Sends data to the printer
  • PrintBarcode(Value, Format, BarWidth, BarHeight, PrintValueAbove, bool PrintValueBelow) Prints a barcode in a specific format
  • PrintBitmap(Width, Height, Bitmap, Mode) Prints a bitmap (see note below)
  • PrintLine(Text) Prints a line with text
  • SetAlignment(Value) Changes the text alignment
  • SetLeftSpacing(Value) Defines the amount of spacing at the left of a line
  • SetLineSpacing(Value) Defines the amount of spacing at the top of a line

Properties

  • DoubleHeight When true, the font will be higher
  • DoubleWidth When true, the font will be wider
  • HeatingInterval Heating interval of the printer
  • HeatingTime Heating time of the printer
  • Inverted When true, prints will be inverted (white on black)
  • MaxPrintingDots Maximum of printing dots
  • SmallText When true, the font will be smaller
  • StrikeThrough When true, text will be striked through
  • Underlined When true, text will be underlined
  • UpsideDown When true, the printer will print upside-down

Events

  • OnStatusChange When the printer status changes, this event will be triggered

Bitmaps note

To convert an image file to a bitmap, or to generate a QR Code, please visit http://www.netmftoolbox.com/tools/img_to_bin.php

How to connect

Toolbox.NETMF.Hardware.ThermalPrinter2.jpg

Sample code in C#

ThermalPrinter Printer = new ThermalPrinter();

// Use this to make the prints of better quality
// It will slow down the printer, and perhaps shorten the lifespan of the printer too
Printer.HeatingTime = 255;
Printer.HeatingInterval = 255;

// Font demo
Printer.SmallText = true; Printer.PrintLine("Small text"); Printer.SmallText = false;
Printer.Inverted = true; Printer.PrintLine("Inverted text"); Printer.Inverted = false;
Printer.UpsideDown = true; Printer.PrintLine("Upside down"); Printer.UpsideDown = false;
Printer.DoubleHeight = true; Printer.PrintLine("Doubled text height"); Printer.DoubleHeight = false;
Printer.DoubleWidth = true; Printer.PrintLine("Doubled text width"); Printer.DoubleWidth = false;
Printer.StrikeThrough = true; Printer.PrintLine("Striked through text"); Printer.StrikeThrough = false;
Printer.PrintLine("Normal text");

// Alignment demo
Printer.SetAlignment(ThermalPrinter.Alignment.AlignRight); Printer.PrintLine("Right aligned");
Printer.SetAlignment(ThermalPrinter.Alignment.AlignCenter); Printer.PrintLine("Centered");
Printer.SetAlignment(ThermalPrinter.Alignment.AlignLeft); Printer.PrintLine("Left aligned");

// Spacing demo
Printer.SetLeftSpacing(8); Printer.PrintLine("8 spaces at the left");
Printer.SetLeftSpacing(4); Printer.PrintLine("4 spaces at the left");
Printer.SetLeftSpacing(0); Printer.PrintLine("0 spaces at the left");
Printer.SetLineSpacing(50); Printer.PrintLine("Line spacing: 50");
Printer.SetLineSpacing(40); Printer.PrintLine("Line spacing: 40");
Printer.SetLineSpacing(30); Printer.PrintLine("Line spacing: 30");

// Barcode demo
Printer.PrintLine("UPC_A:"); Printer.PrintBarcode("858115002002", ThermalPrinter.BarCodeSystem.UPC_A);
Printer.PrintLine("EAN13:"); Printer.PrintBarcode("9781449302450", ThermalPrinter.BarCodeSystem.EAN13);
Printer.PrintLine("CODE128:"); Printer.PrintBarcode("netduino.com", ThermalPrinter.BarCodeSystem.CODE128, 2);

// QR Code
Printer.PrintLine("QR Code:");
Printer.PrintBitmap(Bitmaps.http___www_netduino_com__qrcode.Width, Bitmaps.http___www_netduino_com__qrcode.Height, Bitmaps.http___www_netduino_com__qrcode.Data);

// Bitmap demo
Printer.PrintLine("Bitmap demo:");
Printer.PrintBitmap(Bitmaps.netduino_bmp.Width, Bitmaps.netduino_bmp.Height, Bitmaps.netduino_bmp.Data);

// Feeds so all demos are visible
Printer.LineFeed(2);

Sample code in VB

Dim Printer As ThermalPrinter = New ThermalPrinter()

' Use this to make the prints of better quality
' It will slow down the printer, and perhaps shorten the lifespan of the printer too
Printer.HeatingTime = 255
Printer.HeatingInterval = 255

' Font demo
Printer.SmallText = True : Printer.PrintLine("Small text") : Printer.SmallText = False
Printer.Inverted = True : Printer.PrintLine("Inverted text") : Printer.Inverted = False
Printer.UpsideDown = True : Printer.PrintLine("Upside down") : Printer.UpsideDown = False
Printer.DoubleHeight = True : Printer.PrintLine("Doubled text height") : Printer.DoubleHeight = False
Printer.DoubleWidth = True : Printer.PrintLine("Doubled text width") : Printer.DoubleWidth = False
Printer.StrikeThrough = True : Printer.PrintLine("Striked through text") : Printer.StrikeThrough = False
Printer.PrintLine("Normal text")

' Alignment demo
Printer.SetAlignment(ThermalPrinter.Alignment.AlignRight) : Printer.PrintLine("Right aligned")
Printer.SetAlignment(ThermalPrinter.Alignment.AlignCenter) : Printer.PrintLine("Centered")
Printer.SetAlignment(ThermalPrinter.Alignment.AlignLeft) : Printer.PrintLine("Left aligned")

' Spacing demo
Printer.SetLeftSpacing(8) : Printer.PrintLine("8 spaces at the left")
Printer.SetLeftSpacing(4) : Printer.PrintLine("4 spaces at the left")
Printer.SetLeftSpacing(0) : Printer.PrintLine("0 spaces at the left")
Printer.SetLineSpacing(50) : Printer.PrintLine("Line spacing: 50")
Printer.SetLineSpacing(40) : Printer.PrintLine("Line spacing: 40")
Printer.SetLineSpacing(30) : Printer.PrintLine("Line spacing: 30")

' Barcode demo
Printer.PrintLine("UPC_A:") : Printer.PrintBarcode("858115002002", ThermalPrinter.BarCodeSystem.UPC_A)
Printer.PrintLine("EAN13:") : Printer.PrintBarcode("9781449302450", ThermalPrinter.BarCodeSystem.EAN13)
Printer.PrintLine("CODE128:") : Printer.PrintBarcode("netduino.com", ThermalPrinter.BarCodeSystem.CODE128, 2)

' QR Code
Printer.PrintLine("QR Code:")
Printer.PrintBitmap(Bitmaps.http___www_netduino_com__qrcode.Width, Bitmaps.http___www_netduino_com__qrcode.Height, Bitmaps.http___www_netduino_com__qrcode.Data)

' Bitmap demo
Printer.PrintLine("Bitmap demo:")
Printer.PrintBitmap(Bitmaps.netduino_bmp.Width, Bitmaps.netduino_bmp.Height, Bitmaps.netduino_bmp.Data)

' Feeds so all demos are visible
Printer.LineFeed(2)

Sample result

Toolbox.NETMF.Hardware.ThermalPrinter.jpg

Related documents

Last edited Jan 1, 2013 at 9:21 PM by Garrcomm, version 6