Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@orders.co/epson-tm-epos-sdk

orders-co282MIT0.1.4TypeScript support: included

React Native SDK for Epson ePOS-Print TM printers

react-native, epson, epos, printer, pos, tm, thermal, receipt

readme

@orders.co/epson-tm-epos-sdk

A React Native wrapper for the Epson ePOS-Print SDK, allowing you to interact with Epson TM series POS printers from your React Native applications.

Installation

npm install @orders.co/epson-tm-epos-sdk --save
# or
yarn add @orders.co/epson-tm-epos-sdk

Android Setup

  1. Add the following to your android/settings.gradle:
include ':epson-tm-epos-sdk'
project(':epson-tm-epos-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/@orders.co/epson-tm-epos-sdk/android')
  1. Add the implementation to your android/app/build.gradle dependencies:
dependencies {
    // ...
    implementation project(':epson-tm-epos-sdk')
}
  1. Import and add the package to your MainApplication.java:
import com.reactnative.eposprint.EposPrintPackage;

// ...

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.asList(
        new MainReactPackage(),
        new EposPrintPackage() // <-- Add this line
    );
}
  1. Add permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Usage

import EposPrintSdk, {
  DEVTYPE_TCP,
  LANG_EN,
  ALIGN_CENTER,
  FONT_A,
  CUT_FEED
} from '@orders.co/epson-tm-epos-sdk';

// Initialize the SDK
await EposPrintSdk.initialize();

// Connect to the printer
await EposPrintSdk.openPrinter({
  deviceType: DEVTYPE_TCP,
  target: '192.168.192.168', // IP address or Bluetooth MAC address
  printerModel: 'TM-m30',
  printerLanguage: LANG_EN,
  isStatusMonitor: true,
  interval: 3000
});

// Create and initialize a builder
const builder = EposPrintSdk.createBuilder();
await builder.initialize();

// Add commands to the builder
await builder.addTextAlign(ALIGN_CENTER);
await builder.addTextFont(FONT_A);
await builder.addTextSize(2, 2);
await builder.addText('Hello, ePOS Print!\n');
await builder.addFeedLine(1);
await builder.addTextSize(1, 1);
await builder.addText('This is a test receipt\n');
await builder.addFeedLine(1);
await builder.addCut(CUT_FEED);

// Send the print job to the printer
try {
  const result = await EposPrintSdk.sendData();
  console.log('Print success', result);
} catch (error) {
  console.error('Print error', error);
}

// Close the printer connection when done
await EposPrintSdk.closePrinter();

// Listen for printer status changes
const statusSubscription = EposPrintSdk.addStatusListener((event) => {
  console.log('Printer status changed:', event);
});

// Remove listener when component unmounts
EposPrintSdk.removeStatusListener(statusSubscription);

Supported Printer Models

  • TM-m30
  • TM-m30II
  • TM-m30II-H
  • TM-m30II-NT
  • TM-m30III
  • TM-m30III-H
  • TM-m50
  • TM-T20
  • TM-T20II
  • TM-T20III
  • TM-T20IIIL
  • TM-T70
  • TM-T70II
  • TM-T82
  • TM-T82II
  • TM-T82III
  • TM-T82X
  • TM-T83II
  • TM-T83III
  • TM-T88V
  • TM-T88VI
  • TM-T88VII
  • TM-U220
  • TM-U330

API Reference

EposPrintSdk

Static methods:

  • initialize(): Initialize the SDK
  • openPrinter(config): Connect to a printer
  • closePrinter(): Disconnect from the printer
  • getPrinterStatus(): Get current printer status
  • sendData(): Send print commands to the printer
  • createBuilder(): Create a new print command builder
  • addStatusListener(callback): Listen for printer status changes
  • addBatteryStatusListener(callback): Listen for battery status changes
  • removeStatusListener(subscription): Remove a status listener
  • removeBatteryStatusListener(subscription): Remove a battery status listener

Builder Class

Methods for building print commands:

  • initialize(): Initialize the builder
  • clear(): Clear all commands
  • addText(text): Add text to print
  • addTextAlign(align): Set text alignment
  • addTextSize(width, height): Set text size
  • addTextFont(font): Set text font
  • addTextSmooth(smooth): Enable/disable text smoothing
  • addFeed(): Add paper feed
  • addFeedLine(line): Add line feed
  • addCut(cutType): Add paper cut command
  • addBarcode(data, symbology, height, width, hri): Add barcode
  • addSymbol(data, type, level, width, height): Add 2D code
  • addImage(base64Image, x, y, width, height): Add image
  • beginPageMode(x, y, width, height, direction): Begin page mode
  • endPageMode(): End page mode

Development

Publishing New Versions

To publish a new version of the package:

# Use the automated publish script
npm run publish

This script will:

  1. Check if you're logged in to npm
  2. Prompt you to select a version bump type (patch, minor, major, or custom)
  3. Bump the version in package.json
  4. Build the package
  5. Publish to npm with public access
  6. Create a git tag and offer to push changes

Manual Version Bumping

You can also use npm scripts to bump the version:

# Bump patch version (0.1.0 -> 0.1.1)
npm run version:patch

# Bump minor version (0.1.0 -> 0.2.0)
npm run version:minor

# Bump major version (0.1.0 -> 1.0.0)
npm run version:major

# Test build the package
npm run build

License

MIT