Skip to content

Commit

Permalink
Fine tune package
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceK33z committed Oct 4, 2018
1 parent bc31829 commit 4c68ed3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 63 deletions.
71 changes: 22 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,46 @@
# React Native Honeywell Scanner
# React Native Honeywell Printer

This package works with Honeywell devices that have an integrated barcode scanner, like the Honeywell Dolphin CT50. This package was fully tested with a CT50, since the SDK is not specific to the CT50 other devices will likely work as well but this is not guaranteed.
This package works with Honeywell devices that use the Intermec PB50 printer. It may also work on other Intermec printers, but this is not guaranteed.

TODO:
Note that this is an experimental package.

- Find out how printerprofiles.json works
- Properly rotate text on PB50 printer
- Make sure printer is stable
- Cleanup printerprofiles
- Write documentation
Tested to work with React Native 0.56 and 0.57. Only works on Android.

## Installation

```
yarn add react-native-honeywell-scanner
yarn add react-native-honeywell-printer
```

To install the native dependencies:

```
react-native link react-native-honeywell-scanner
react-native link react-native-honeywell-printer
```

## Usage

First you'll want to check whether the device is a Honeywell scanner:
First you need to copy `printerprofiles.json` from this repository to `android/app/src/main/assets/printerprofiles.json` in your project. You can modify this file to change the styling of the print document.

```js
import HoneywellPrinter from 'react-native-honeywell-scanner';
import honeywellPrinter from 'react-native-honeywell-printer';

HoneywellPrinter.isCompatible // true or false
async function print() {
const devices = await BluetoothSerial.list();
// Search for Intermec PB50 devices; this is the only tested printer at the moment.
const device = devices.find(device => device.name.includes('PB50'));
if (device) {
// This is the profile name defined in android/app/src/main/assets/printerprofiles.json
const profileName = 'PB32_Fingerprint';
await honeywellPrinter.print(profileName, device.id, 'My variable to print');
}
}
```

The barcode reader needs to be "claimed" by your application; meanwhile no other application can use it. You can do that like this:

```js
HoneywellPrinter.startReader().then((claimed) => {
console.log(claimed ? 'Barcode reader is claimed' : 'Barcode reader is busy');
});
```

To free the claim and stop the reader, also freeing up resources:

```js
HoneywellPrinter.stopReader().then(() => {
console.log('Freedom!');
});
```

To get events from the barcode scanner:

```js
HoneywellPrinter.on('barcodeReadSuccess', event => {
console.log('Received data', event);
});

HoneywellPrinter.on('barcodeReadFail', () => {
console.log('Barcode read failed');
});
```

To stop receiving events:

```js
function barcodeReadFail = () => console.log('Barcode read failed');
HoneywellPrinter.off('barcodeReadFail', handler);
```

## TODO

## Inspiration
- There is no progress indication
- There is no indication whether printing succeeded or failed

The [react-native-bluetooth-serial](https://github.com/rusel1989/react-native-bluetooth-serial) project was used as inspiration. [cordova-honeywell](https://github.com/icsfl/cordova-honeywell) also served as some inspiration.
We probably won't have time to build this since we'll only have a Intermec printer for a limited time.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void onPreExecute()
//
}

/**
/**
* This method runs on a background thread. The specified parameters
* are the parameters passed to the execute method by the caller of
* this task. This method can call publishProgress to publish updates
Expand All @@ -95,7 +95,7 @@ protected String doInBackground(String... args)
stream.read(buffer);
stream.close();
} catch (IOException e) {
if (D) Log.d(TAG, "HONEYWELLPRINTER - FILE ERR " + e.getMessage());
if (D) Log.d(TAG, "Printer profile file error: " + e.getMessage());
}
String profiles = new String(buffer).trim();

Expand All @@ -104,15 +104,11 @@ protected String doInBackground(String... args)
String sPrinterID = args[0];
String sPrinterURI = "bt://" + args[1];
String sText = args[2];
if (D) Log.d(TAG, "HONEYWELLPRINTER - PRINTER ID " + sPrinterID);
if (D) Log.d(TAG, "HONEYWELLPRINTER - PRINTER URI " + sPrinterURI);
if (D) Log.d(TAG, "HONEYWELLPRINTER - PRINTER TEXT " + sText);
if (D) Log.d(TAG, "Printing to printer id " + sPrinterID + " with uri " + sPrinterURI + " and text " + sText);

LabelPrinter.ExtraSettings exSettings = new LabelPrinter.ExtraSettings();
exSettings.setContext(mReactContext);

if (D) Log.d(TAG, "HONEYWELLPRINTER - START BG THINGY");

try
{
lp = new LabelPrinter(
Expand Down Expand Up @@ -151,7 +147,7 @@ public void receivedStatus(PrintProgressEvent aEvent)

// Sets up the variable dictionary.
LabelPrinter.VarDictionary varDataDict = new LabelPrinter.VarDictionary();
varDataDict.put("ItemName", sText);
varDataDict.put("TextMsg", sText);

// Prints the ItemLabel as defined in the printer_profiles.JSON file.
lp.writeLabel("ItemLabel", varDataDict);
Expand Down Expand Up @@ -186,7 +182,7 @@ public void receivedStatus(PrintProgressEvent aEvent)
}
}

if (D) Log.d(TAG, "HONEYWELLPRINTER -" + sResult);
if (D) Log.d(TAG, sResult);
// The result string will be passed to the onPostExecute method
// for display in the the Progress and Status text box.
return sResult;
Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ const ReactNative = require('react-native');
const { NativeModules } = ReactNative;
const HoneywellPrinter = NativeModules.HoneywellPrinter || {}; // Hacky fallback for iOS

console.log('PRINTER v2');

module.exports = HoneywellPrinter;
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "react-native-honeywell-printer",
"description": "A barcode scanner for Honeywell handheld devices like Honeywell Dolphin CT50",
"description": "Print barcodes and text with a Honeywell Intermec printer with React Native",
"version": "1.0.1",
"main": "index.js",
"author": "Kees Kluskens <[email protected]>",
"repository": "Volst/react-native-honeywell-printer",
"keywords": [
"honeywell",
"barcode",
"scanner"
"intermec",
"pb50",
"printer"
],
"engines": {
"node": ">=4.0"
Expand Down
73 changes: 73 additions & 0 deletions printerprofiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"LINEPRINTERCONTROL":
{
"FormatVersion": "1.0.0.0",
"Platform": "Android",
"DEFAULTS":
{
"BoldIsFont": true, "BoldOff": "[0x1b,0x77,!]", "BoldOn": "[0x1b,0x77,0x6D]",
"CompressDotsHigh": 12, "CompressIsFont": true, "CompressOff": "[0x1b,0x77,!]",
"CompressOn": "[0x1b,0x77,0x42]", "DoubleHighDotsHigh": 32, "DoubleHighIsFont": false,
"DoubleHighMask": 16, "DoubleHighOff": "[0x1b,!,0x10]", "DoubleHighOn": "[0x1b,!,0x10]",
"DoubleWideDotsHigh": 16, "DoubleWideHighPrefix": "[0x1b,!]", "DoubleWideIsFont": false,
"DoubleWideMask": 32, "DoubleWideOff": "[0x1b,!,0x20]", "DoubleWideOn": "[0x1b,!,0x20]",
"Initialize": "[0x00,0x00,0x00,0x00,0x1b,0x40,0x00,0x00,0x00]",
"NormalFont": "[0x1b,0x77,!,0x1b,!,0x00]", "NewLine": "[0x0d]", "NormalDotsHigh": 16,
"FormFeed": "[0x0d,0x0d,0x0d,0x0d,0x0d]", "ValidateAttribOnFormFeed": true,
"PrintHeadWidth": 384, "UseDoubleHWMask": true, "ValidateAttribOnFont": true,
"ValidateAttribOnNewLn": true, "NullsBeforeClose": 0, "PreCloseDelay": 0, "EndOfGraphicsDelay": 0,
"PostGraphicsDelay": 0, "PostGraphicsLineDelay": 0, "PreGraphicsDelay": 0, "StartOfGraphicsDelay": 0,
"BtConnectRetries" : 3, "BtconnectRetryDelay" : 100, "BtWriteDataReadyTimeout" : 10000, "BtWriteIntervalTimeout" : 10000,
"BtMaxSegWrite" : 1024, "BtMaxSegRead" : 1024, "BtLinger" : 10
},

"PRINTERS":
{
"PB32_Fingerprint":
{
"DisplayName":"PB32 Bt Label Printer", "PrintHeadWidth": 576, "LABEL_01": "3in_FingerprintLabels",
"FormFeed": "[0x46,0x4F,0x52,0x4D,0x46,0x45,0x45,0x44]",
"Initialize": [], "NormalFont": [], "NullsBeforeClose": 0, "PreCloseDelay": 1000
}
},

"LABELS":
{
"3in_FingerprintLabels":
{
"ItemLabel":
{
"LabelDataStream": "PRPOS 200,0:DIR 1:AN 5:PP 180, 180:FT \"Swiss 721 Bold Condensed BT\",20:PT \"TextMsg$$\":PF\r\n",
"VarPostfix": "$$"
}
}
},
"STATUS":
{
"ESCP_StatusQueries" :
{
"QUERIES" :
[
{
"GetStatusCommand" : "[0x1b,{,S,T,?,}]",
"StatusInitTimeout" : 5000,
"StatusGapTimeout" : 500,
"StatusEndResponse" : "[}]",
"RESPONSES" :
[
{ "PrinterMsg" : "[P,:,N]", "MsgNo" : 223 },
{ "PrinterMsg" : "[B,:,V]", "MsgNo" : 226 },
{ "PrinterMsg" : "[L,:,U]", "MsgNo" : 227 },
{ "PrinterMsg" : "[H,:,T]", "MsgNo" : 228 },
{ "PrinterMsg" : "[E,:,c]", "MsgNo" : 1001 },
{ "PrinterMsg" : "[E,:,d]", "MsgNo" : 1002 },
{ "PrinterMsg" : "[E,:,f]", "MsgNo" : 1003 },
{ "PrinterMsg" : "[E,:,g]", "MsgNo" : 1004 }
]
}
]
}
}
}
}

0 comments on commit 4c68ed3

Please sign in to comment.