Skip to content

PyramidTechnologies/JavaThermalTalk

Repository files navigation

JavaThermalTalk

This repo is an implementation of the ThermalTalk printer protocol in for Android devices. It utilizes FTDI's FT312 USB bridge chip to communicate over RS232 with the printer.

Usage

To use this library, add ThermalTalk as a dependency in your Android project. You can then refer to the example code in the 'example' directory for guidance on how to initialize the printer object and send print commands. This library supports both Reliance and Phoenix printers, and which you specify by initializing the appropriate printer class (ReliancePrinter or PhoenixPrinter).

Resources

This library enables the use of ESC/POS commands for interacting with the printers. Below is a link to a list of valid ESC/POS commands https://escpos.readthedocs.io/en/latest/commands.html

Document

The ThermalTalk library implements a document-based approach to printing. You can create a Document object and add various elements to it. When you are ready to print, use the PrintDocument(IDocument doc) and FormFeed() commands to send the document to the printer.

Document Elements

Document elements include:

  • StandardSection: A section of the document that can contain text.
  • BarcodeSection: A section of the document that can contain a barcode.
  • ImageSection: A section of the document that can contain an image.
  • Placeholder: A placeholder element that can be used to reserve space in the document

Document Formatting

Tools for formatting the document include:

  • Justification: You can set the justification for each section of the document (left, center, right, use previous).
  • Font Scalar: You can set the font scalar for each section of the document to adjust the size of the text.
  • Font Effects: You can set font effects such as bold, underline, and inverse for each section of the document.
  • Font Type: You can set the font type for each section of the document to choose between different font styles.

Printer Status Commands

Status commands access information stored within a printer. Use the GetStatus(StatusType statusType) command to retrieve the desired status information. The following status types are supported:

  • PrinterStatus: Verify that the printer is running and connected.
  • OfflineStatus: Get the physical status of the printer.
  • ErrorStatus: Get any error messages stored on the printer. Not supported on Phoenix
  • PaperStatus: Get the current paper status of the printer.
  • MovementStatus: Get the status of the printer's motors. Not supported on Phoenix
  • FullStatus: Get all of the above status information in one command.

Logging

There is a simple logging interface (ILogger) to decouple from any external logging framework.

Imaging

The library provides a collection of image manipulation algorithms and functions. The primary features are:

  • Image Dithering
  • Quick Bitmap to buffer and buffer to Bitmap conversions
  • Lossless Resize
  • Generate packet-ready data streams for serial transmission

Examples

All examples require the following import statements:

import com.thermaltalk.Imaging.*;

Dithering

Dithering is the process of converting a high-resolution image into a low-res image without loosing too much fidelity. There are a number of algorithms available and they each provide different balances between quality and performance.

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test_image);
IDitherer parser = DitherFactory.GetDitherer(Algorithms.JarvisJudiceNinke);
Bitmap ditheredBitmap = parser.GenerateDithered(bitmap);

Converting a buffer into a bitmap

Sometimes we want to manipulate a bitmap in memory or visualize a buffer as a bitmap.

byte[] myBuffer = new byte[] {....}; // Your data
int width = 200;
int height = 200;
Bitmap bitmap = ImageExt.ToBitmap(myBuffer, width, height, Bitmap.Config.ARGB_8888);

Implementation Details and Pitfalls

  • The library uses the Android USB Manager API to communicate with the printer. Make sure that the android.hardware.usb.accessory feature is enabled in your app
  • The FT312 chip requires a config message to be sent that includes communication parameters such as baud rate, data bits, stop bits, and parity. Once configured, these settings cannot be changed without power cycling the chip. If you are using multiple printers with different settings, you will need to disconnect the chip from the Android device before sending the config message for the next printer.

About

Java version of the ThermalTalk Library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors