@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
- 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')
- Add the implementation to your
android/app/build.gradle
dependencies:
dependencies {
// ...
implementation project(':epson-tm-epos-sdk')
}
- 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
);
}
- 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 SDKopenPrinter(config)
: Connect to a printerclosePrinter()
: Disconnect from the printergetPrinterStatus()
: Get current printer statussendData()
: Send print commands to the printercreateBuilder()
: Create a new print command builderaddStatusListener(callback)
: Listen for printer status changesaddBatteryStatusListener(callback)
: Listen for battery status changesremoveStatusListener(subscription)
: Remove a status listenerremoveBatteryStatusListener(subscription)
: Remove a battery status listener
Builder Class
Methods for building print commands:
initialize()
: Initialize the builderclear()
: Clear all commandsaddText(text)
: Add text to printaddTextAlign(align)
: Set text alignmentaddTextSize(width, height)
: Set text sizeaddTextFont(font)
: Set text fontaddTextSmooth(smooth)
: Enable/disable text smoothingaddFeed()
: Add paper feedaddFeedLine(line)
: Add line feedaddCut(cutType)
: Add paper cut commandaddBarcode(data, symbology, height, width, hri)
: Add barcodeaddSymbol(data, type, level, width, height)
: Add 2D codeaddImage(base64Image, x, y, width, height)
: Add imagebeginPageMode(x, y, width, height, direction)
: Begin page modeendPageMode()
: 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:
- Check if you're logged in to npm
- Prompt you to select a version bump type (patch, minor, major, or custom)
- Bump the version in package.json
- Build the package
- Publish to npm with public access
- 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