From 4c68ed38a099812a9999af94d53f0ae7c018ce1a Mon Sep 17 00:00:00 2001 From: Kees Kluskens Date: Thu, 4 Oct 2018 15:12:09 +0200 Subject: [PATCH] Fine tune package --- README.md | 71 ++++++------------ .../HoneywellPrinterModule.java | 14 ++-- index.js | 2 - package.json | 7 +- printerprofiles.json | 73 +++++++++++++++++++ 5 files changed, 104 insertions(+), 63 deletions(-) create mode 100644 printerprofiles.json diff --git a/README.md b/README.md index f841d86..8c19f6a 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +We probably won't have time to build this since we'll only have a Intermec printer for a limited time. \ No newline at end of file diff --git a/android/src/main/java/nl/volst/HoneywellPrinter/HoneywellPrinterModule.java b/android/src/main/java/nl/volst/HoneywellPrinter/HoneywellPrinterModule.java index 5b43184..ad13b47 100755 --- a/android/src/main/java/nl/volst/HoneywellPrinter/HoneywellPrinterModule.java +++ b/android/src/main/java/nl/volst/HoneywellPrinter/HoneywellPrinterModule.java @@ -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 @@ -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(); @@ -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( @@ -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); @@ -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; diff --git a/index.js b/index.js index 0bb1645..f65d5c5 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/package.json b/package.json index 7adba85..73c092b 100644 --- a/package.json +++ b/package.json @@ -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 ", "repository": "Volst/react-native-honeywell-printer", "keywords": [ "honeywell", - "barcode", - "scanner" + "intermec", + "pb50", + "printer" ], "engines": { "node": ">=4.0" diff --git a/printerprofiles.json b/printerprofiles.json new file mode 100644 index 0000000..b612c1e --- /dev/null +++ b/printerprofiles.json @@ -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 } + ] + } + ] + } + } + } + } + \ No newline at end of file