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.
npm install @orders.co/epson-tm-epos-sdk --save
# or
yarn add @orders.co/epson-tm-epos-sdk
- 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" />
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);
- 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
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
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
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
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
MIT