anozaki / cordova-brother-label-printer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cordova Brother Label Printer Plugin

Uses the Brother Print SDK for Android...

More info can be found here, including a list of compatible printers: http://www.brother.com/product/dev/mobile/android/index.htm

Already bundled is the following version: v3.0.4 (5/18/2016) which is in the src/android/libs dir. By downloading this you agree to the Brother SDK License terms which are included in the README under the libs dir.

Installing

In your Cordova project, run the following command to install the plugin.

cordova plugin add https://github.com/gordol/cordova-brother-label-printer

And then read usage below.

TODO

  • Add the ability to change the label of the printers
  • Revisit the USB interface Printing to allow for Printer and Label Selection

Help and Support

Please do not email me for support or help with this plugin, use the issue tracker link above, so everyone will benefit from community questions and involvement, and I don't have to answer the same questions over and over for many individuals.

This is a Cordova plugin, firstly. You should be familiar with the Cordova plugin system before you try to use this plugin. Fortunately, it's pretty straight forward and easy to understand.

You can read more about Android plugin development for Cordova here. Knowledge of all of these internals is not necessary, but it doesn't hurt to be familiar either.

Read here to learn how to use Cordova Plugins.

If you still have questions, please use the issue tracker. Please look at existing issues, and if your question is not answered yet, feel free to open a new issue and I'm happy to assist.

Target mobile printers

PocketJet PJ-722, PJ-723, PJ-762, PJ-763, PJ-763MFi, PJ-773
PocketJet PJ-622, PJ-623, PJ-662, PJ-663
PocketJet PJ-520, PJ-522, PJ-523, PJ-560, PJ-562, PJ-563
MPrint MW-145MFi, MW-260MFi
MPrint MW-140BT, MW-145BT, MW-260
RJ-4030Ai, RJ-4030, RJ-4040
TD-2020, TD-2120N, TD-2130N, TD-4000, TD-4100N
QL-710W, QL-720NW
PT-E550W, PT-P750W
RJ-3050, RJ-3150
PT-E800W, PT-D800W, PT-E850TKW
PT-P900W, PT-P950NW

Tested models: QL-720NW, QL-820NWB

(if you have tried this with other models, please update this list and send a pull request)

Supported interfaces (by this plugin)

  • Wi-Fi (Infrastructure mode)
  • Bluetooth
  • USB

Usage

See here for JS interfaces to the plugin: www/printer.js

In general all failure callbacks should expect to receive an Error object back. If the Error object was spawned from the native side of the plugin it should have two fields that can be checked and compared, .code, and .namespace. Otherwise, the Error will just contain a message.

| TODO: document, and finalize error messages and error codes.

There are seven available methods...

findNetworkPrinters

Upon success, findNetworkPrinters will provide a list of printers that were discovered on the network (likely using WiFi). It is not considered an error for no printers to be found, and in this case the list will just be empty.

function findNetworkPrinters(success: (printers: Printer[]) => void, failure: (reason: Error) => void): void

pairBluetoothPrinters

(Primarily used for iOS). This function behaves differently on iOS than it does on Android. In either case the function returns immediately as there's no guaranteed way to determine if the user has paired a printer or not.

When invoked on iOS, it will spawn a pairing list that will be pre-filtered to only show devices that match the Brother Label Printer's naming.

When invoked on Android, this will take the user to the device's Bluetooth Settings page, so that the user can attempt to pair the printer manually.

function pairBluetoothPrinters(success: () => void)

findBluetoothPrinters

Upon success, findBluetoothPrinters will provide a list of printers that were discovered that have already been paired via Bluetooth. It is not considered an error for no printers to be found, and in this case the list will just be empty.

function findBluetoothPrinters(success: (printers: Printer[]) => void, failure: (reason: Error) => void): void

findPrinters

findPrinters is a convenience function that will perform the actions of both findNetworkPrinters and findBluetoothPrinters, and combine the the results into a single continuous list.

function findPrinters(success: (printers: Printer[]) => void, failure: (reason: Error) => void): void

setPrinter

must be called before printViaSDK. It takes a single object that should be one of the objects returned from findNetworkPrinters, findBluetoothPrinters, or findPrinters. Upon successfully setting the printer, the success callback will be invoked. Otherwise, the error callback will be invoked with a string for an error message.

function setPrinter(printer: Printer, success: () => void, failure: (reason: Error) => void): void

printViaSDK

takes one parameter, which is a base64 encoded bitmap image. The result should be a status code that is passed directly from the SDK. The status codes are documnted in the Brother SDK Appendix in section 4.2.2.5.Error Code. If everything works, the response should be "ERROR_NONE".

Clarification:

A bitmap image in this case can be any image with an encoding that is supported by the platform.

function printViaSDK(data: string, success: () => void, failure: (reason: Error) => void): void

sendUSBConfig

calls the Brother SDK's printFile method. The expected input is a string containing raw print commands, which is written to a temporary file in the app cache directory, and is then sent to the printFile method and deleted afterwards. You will need a device that supports USB-OTG and a USB-OTG cable. On first run the app will request USB permissions, and it should be saved after that for subsequent prints. As-is, this method is used to send raw commands in PCL (Printer Control Language) to the printer... For example, to configure the network settings of the printer, etc... You will need to reach out to Brother for documentation of the PCL commands. You can probably find them by searching for "Brother Printer Command Reference" and appending your model number. This method could be extended easily to accept other types of file input, so you could, for example, print JPG images, etc... See here for a simple way to generate a PJL file to reconfigure the network: https://github.com/gordol/PJL-Generator

function sendUSBConfig(data: string, success: () => void, failure: (reason: Error) => void): void

Interface Reference

interface Printer {
    model: string // Usually of the form 'QL_720NW' on Android
    port: 'NET' | 'BLUETOOTH'
    modelName: string // Usually of the form 'Brother QL-720NW'
    ipAddress?: string
    macAddress?: string
    serialNumber?: string
    nodeName?: string
    location?: string
}

About

License:MIT License


Languages

Language:Objective-C 69.0%Language:Java 29.8%Language:JavaScript 1.2%