5.0.24 • Published 3 months ago

@captureid/capacitor-cidprint v5.0.24

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

appcenterbanner

Ionic Capacitor 5 Plugin for Mobile Print

This plugin enables you to use the CaptureID Printer Library and to easily integrate Bluetooth printing into your app(s).

Release Notes

version 5.0.1

new:

switch to capacitor 5

version 0.0.94

new:

Device class changed vendorname and printermodel to optional values

Font change for SATO MB200i

character spacing for PW208NX removed

version 0.0.93

new:

  discoverDevices(options: {timeout: number});

timout parameter added to discover method

connect result:

connecteddevice now contains vendor name and printer model

enums and methods to extract vendor and model from result.

version 0.0.92

fixed:

setupMediaSize does not return result for SATO printers

version 0.0.91

new:

  getPrinterInformation(): Promise<CIDPrinterInformation>;

retrieve detailed information of the printer


version 0.0.90

new:

  enableClipping(options: {enable: boolean}): void;

enable/disable clipping (prevents Honeywell/Intermec printer from displaying "Field out of Label" messages)


version 0.0.89

new:

enableBluetoothAdapter(options {enable: boolean}): Promise<PrinterLibraryEvent>;

enable/disable Bluetooth adapter


enableCalibration(options: {enable: boolean}): void

trigger sensor calibration (Honeywell/Intermec printers)


getMediaSize(): Promise<MediaSize>;

request the media size currently set


isBluetoothAdapterEnabled(): Promise<{result: boolean}>;

check if bluetoothadapter is enabled


sendFormFeed(): void;

send a Formfeed request to the printer


Requirements

The CaptureID Printer plugin expires after a 3 month evaluation period. After this period you must request a valid license key. This license must be purchased separatly and is not included in this package. For additional Information of the CaptureID Licensing and how to get access to a valid license Key visit our Website under (https://www.captureid.de).

How does it work?

The CaptureID Printer Plugin can be used in Ionic Capacitor app's to support label printing on SATO mobile Printers (i.e. MB200i, PW208nx), SATO Desktop Printers (i.e. CT4LX), Honeywell Printers that supports Fingerprint Language and a wide range of ZEBRA Printers (mobile and Desktop Models). It enables you to easily scan for Bluetooth Printers, connect to an selected printer or the last connected printer.

Getting Started

Install the plugin into your existing project by running the command

npm install @captureid/capacitor3-cidprint@latest

run the build command to integrate the plugin code and it's libraries into your android project and to open the project in Android Studio

ionic capacitor run android

Note: In case of an error during the build process stating cidprintlibrary and/or supportv1 can't be found you have to add the following entry into your apps build.gradle file to ensure the required files can be found.

repositories { mavenLocal() maven { url("$rootDir/../node_modules/@captureid/capacitor3-cidprint/android") } }

Plugin Usage

With the CaptureID Printer plugin installed and configured, the only thing left is to add the necessary code to your app.

  1. Call the provided functions and add the callbacks.

  2. Call initCIDPrinterLib to initialize the Library. This method returns a PrinterLibraryEvent as result. If the initialization of the PrinterLibrary is successful and the required Permissions are granted the fields of the PrinterLibraryEvent structure are set with the values In case of the app is missing some permissions the EventType of the struct is set to NOTIFY and the data field is a type of InitResult class, which contains the required permissions in an array of strings.

  3. Register the LibraryListener with addListener(CIDPrinterListenerTypes.PRINTER_LIBRARY, (event: PrinterLibraryEvent) => {}). The Listener Method receives all event fired by the PrinterLibrary.

  4. The method "discoverDevices" calls the Discover Listener, You can register the listener by adding the Listener Callback method with the Plugins.CIDPrint.addListener(ListenerTypes.DISCOVER, (result: any) => { let data: PrinterEvent = result.result0;}); command

  5. the result contains Result Type of PrinterEvent. The PrinterEvent structure consist of the following fields:

    • type: PrinterEventType;
    • status: PrinterStatusType;
    • message: string;
    • error: number;
    • device: Device;
    • devices: Device[];
    • action: PrinterActionType;

API Reference

  • initCIDPrinterLib(): Promise<{event: PrinterLibraryEvent}>;
  • closeCIDPrinterLib(): void;
  • activateLicense(options: { productKey: string; }): void;
  • enableBluetoothPrinting(options: { enable: boolean; }): void;
  • getPairedDevices(): Promise<{}>;
  • discoverDevices(): void;
  • connectToPreferredPrinter(options: { mac: string; }): void;
  • printData(options: { data: string; }): void;
  • printLabelWithData(options: { label: string; data: string[]; }): void;
  • printLabel(options: { label: string; }): void;

activateLicense(...)

activateLicense(options: { licenseKey: string; customerID: string; }) => Promise<PrinterLibraryEvent>
ParamType
options{ licenseKey: string; customerID: string; }

Returns: Promise<PrinterLibraryEvent>


closeCIDPrinterLib()

closeCIDPrinterLib() => void

connectToPreferredPrinter(...)

connectToPreferredPrinter(options: { mac: string; }) => void
ParamType
options{ mac: string; }

connectToPreferredPrinter(...)

connectToPreferredPrinter(options: { mac: string; autoreconnect: boolean; timeout: number; }) => void
ParamType
options{ mac: string; autoreconnect: boolean; timeout: number; }

connectToPrinter(...)

connectToPrinter(options: { address: string; }) => void
ParamType
options{ address: string; }

connectToPrinter(...)

connectToPrinter(options: { address: string; autoreconnect: boolean; timeout: number; }) => void
ParamType
options{ address: string; autoreconnect: boolean; timeout: number; }

connectToPrinter(...)

connectToPrinter(options: { address: string; port: number; }) => void
ParamType
options{ address: string; port: number; }

convert(...)

convert(options: { label: string; }) => void
ParamType
options{ label: string; }

disconnectFromPrinter(...)

disconnectFromPrinter(options: { mac: string; }) => void
ParamType
options{ mac: string; }

discoverDevices(...)

discoverDevices(options: { timeout: number; }) => void
ParamType
options{ timeout: number; }

enableBluetoothAdapter(...)

enableBluetoothAdapter(options: { enable: boolean; }) => Promise<PrinterLibraryEvent>
ParamType
options{ enable: boolean; }

Returns: Promise<PrinterLibraryEvent>


enableBluetoothPrinting(...)

enableBluetoothPrinting(options: { enable: boolean; }) => void
ParamType
options{ enable: boolean; }

enableCalibration(...)

enableCalibration(options: { enable: boolean; }) => void
ParamType
options{ enable: boolean; }

enableClipping(...)

enableClipping(options: { enable: boolean; }) => void
ParamType
options{ enable: boolean; }

enableDebugToFile(...)

enableDebugToFile(options: { enable: boolean; }) => void
ParamType
options{ enable: boolean; }

enableDispendingMode(...)

enableDispendingMode(options: { enable: boolean; }) => void
ParamType
options{ enable: boolean; }

enableNetworkPrinting(...)

enableNetworkPrinting(options: { enable: boolean; }) => void
ParamType
options{ enable: boolean; }

getLatestConnectState()

getLatestConnectState() => Promise<PrinterLibraryEvent>

Returns: Promise<PrinterLibraryEvent>


getMediaSize()

getMediaSize() => Promise<MediaSize>

Returns: Promise<MediaSize>


getPairedDevices()

getPairedDevices() => void

getPrinterInformation()

getPrinterInformation() => Promise<CIDPrinterInformation>

Returns: Promise<CIDPrinterInformation>


getPrinterLibraryVersion()

getPrinterLibraryVersion() => Promise<string>

Returns: Promise<string>


getPrinterStatus()

getPrinterStatus() => void

initCIDPrinterLib()

initCIDPrinterLib() => Promise<PrinterLibraryEvent>

Returns: Promise<PrinterLibraryEvent>


isBluetoothAdapterEnabled()

isBluetoothAdapterEnabled() => Promise<{ result: boolean; }>

Returns: Promise<{ result: boolean; }>


isLibraryInitialized()

isLibraryInitialized() => Promise<{ result: boolean; }>

Returns: Promise<{ result: boolean; }>


printData(...)

printData(options: { data: string; }) => void
ParamType
options{ data: string; }

printLabel(...)

printLabel(options: { label: string; }) => void
ParamType
options{ label: string; }

printLabelWithData(...)

printLabelWithData(options: { label: string; data: string[]; }) => void
ParamType
options{ label: string; data: string[]; }

printLabelWithObject(...)

printLabelWithObject(options: { label: string; data: TicketData; }) => void
ParamType
options{ label: string; data: TicketData; }

printNativeData(...)

printNativeData(options: { data: string; }) => void
ParamType
options{ data: string; }

printReferenceLabel(...)

printReferenceLabel(options: { labeltype: ReferenceTicketType; }) => void
ParamType
options{ labeltype: ReferenceTicketType; }

requestPermission(...)

requestPermission(options: { permission: string; }) => Promise<{ result: boolean; }>
ParamType
options{ permission: string; }

Returns: Promise<{ result: boolean; }>


requestAllPermissions(...)

requestAllPermissions(options: { permissions: string[]; }) => Promise<{ result: boolean; }>
ParamType
options{ permissions: string[]; }

Returns: Promise<{ result: boolean; }>


sendFormFeed()

sendFormFeed() => void

setAutoReconnect(...)

setAutoReconnect(options: { autoreconnect: boolean; }) => void
ParamType
options{ autoreconnect: boolean; }

setConfiguration(...)

setConfiguration(options: { config: PrinterConfiguration; }) => void
ParamType
options{ config: PrinterConfiguration; }

setTimeouts(...)

setTimeouts(options: { gap: number; timeout: number; status: number; information: number; formfeed: number; detect: number; }) => void
ParamType
options{ gap: number; timeout: number; status: number; information: number; formfeed: number; detect: number; }

setupMediaSize(...)

setupMediaSize(options: { width: number; height: number; }) => void
ParamType
options{ width: number; height: number; }

showNavigationBar(...)

showNavigationBar(options: { show: boolean; }) => void
ParamType
options{ show: boolean; }

showSettings(...)

showSettings(options: { show: boolean; }) => void
ParamType
options{ show: boolean; }

showUI(...)

showUI(options: { show: boolean; }) => void
ParamType
options{ show: boolean; }

uploadFile(...)

uploadFile(options: { file: string; filetype: number; }) => void
ParamType
options{ file: string; filetype: number; }

addListener(string, ...)

addListener(eventName: string, listenerFunc: (data: PrinterLibraryEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventNamestring
listenerFunc(data: PrinterLibraryEvent) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


removeAllListeners()

removeAllListeners() => void

Interfaces

PrinterLibraryEvent

PropType
senderstring
typeEventType
messagestring
errornumber
dataResultClass
actionPrinterLibraryActionType

ResultClass

MediaSize

PropType
widthnumber
heightnumber

CIDPrinterInformation

PropType
firmwareFirmware
main_firmwareFirmware
module_firmwareFirmware
sensor_boot_firmwareFirmware
sensor_firmwareFirmware
mediaMedia
batteryBattery
modeltypenumber
modelnamestring
dpinumber
dots_mmnumber
dotsnumber
lanaddressstring
wlanaddressstring
btaddressstring
headcountstring
lifecountstring
cutcountstring
dispensecountstring
thermotransferboolean

Firmware

PropType
versionstring
datestring
checksumstring

Media

PropType
labelwidthnumber
labelheightnumber

Battery

PropType
cyclecountnumber
chargestatnumber
healthnumber
remainnumber

TicketData

PropType
variablesTicketVariable

TicketVariable

PrinterConfiguration

PropType
disconnectonpauseboolean
connectonresumeboolean
lowbatterythresholdnumber
mediaCIDMedia

CIDMedia

PropType
sizeMediaSize
typeMediaType

PluginListenerHandle

PropType
remove() => Promise<void>

Enums

EventType

MembersValue
SUCCESS0
NOTIFY1
FAILED2

PrinterLibraryActionType

MembersValue
NONE0
INITIALIZE1
BLUETOOTH_INITIALIZE2
BLUETOOTH_ENABLE3
BLUETOOTH_DISABLE4
DISCOVER_START5
DISCOVER_DETECT6
DISCOVER_FINISH7
CONNECT8
DISCONNECT9
PRINT10
STATUS11
CONFIGURE12
BLUETOOTH_TURNED_OFF13
BLUETOOTH_TURNED_ON14
LICENSE_ACTIVATION15
FILEUPLOAD16
EXCEPTION17

ReferenceTicketType

MembersValue
DOT_MATRIX0

MediaType

MembersValue
GAP0
IMARK1

initCIDPrinterLib(): Promise<{event: PrinterLibraryEvent}>

await initCIDPrinterLib();

Version 0.1.0 Parameters: - none

code sample

closeCIDPrinterLib()

await closeCIDPrinterLib();

Version 0.1.0 Parameters: - none

activateLicense

await activateLicense(key: string, customer: string);

Version 0.1.0 Parameters:

  • key (string) - valid Licensekey.
  • customer (string) - valid CustomerId.

enableBluetoothPrinting

await enableBluetoothPrinting(enable: boolean);

Version 1.0.0 Parameters:

  • enable (boolean) - Enables/disables the Printing via Bluetooth.

getPairedDevices

getPairedDevices();

Version 0.1.0

Parameters:- none

discoverDevices

discoverDevices();

Version 0.1.0

Parameters:- none

printData

printData(data: string);

Version 0.1.0

Parameters:

  • data (string) - data to be printed.

printLabelWithData

printLabelWithData(label: string, data: string[]);

Version 0.1.0

Parameters:

  • label: path and filename of the label template file relative to the android project assets folder.
  • data[]: array of strings representing a value for each placeholder (count and length of the array and the contained strings must match the variables in the label template)

printLabel

printLabel(label: String);

Version 0.1.0

Parameters:

  • label: path and filename of the label template file relative to the android project assets folder.

connectToPreferredPrinter

connectToPreferredPrinter(mac: string);

Version 0.1.0

Parameters:

  • mac: Bluetooth Mac Address of the printer to connect or an empty string. If an empty string is provided a connection to the last connected printer is established.

Examples

initCIDPrint

let event: PrinterLibraryEvent = await CIDPrint.initCIDPrinterLib();
if(event.type === EventType.NOTIFY) {
  if(event.action === PrinterLibraryActionType.INITIALIZE) {
    let data: InitResult = event.data as InitResult;
    for(let i = 0; i < data.permissions.length; i++) {
      // list the required permissions.
    }
  }
}

Discover printers

For the sample code to work it is required to call initCIDPrinter and enableBlutoothPrinting.

Register the callback method for the discover procedure

  discoverListener = Plugins.CIDPrint.addListener(ListenerTypes.DISCOVER, (result: any) => {
    let data: PrinterEvent = result.result[0];
    if(data.action === PrinterActionType.LIST_PRINTER) {
      this.setState({ devmac: data.device.devicemac, devname: data.device.devicename });
    } else if(data.action === PrinterActionType.LIST_PRINTERS) {
      this.setState({ devices: data.devices });
    }
  });
  
  discover() {
    CIDPrint.discoverDevices();
  }

call discover to start the Blutooth Discover procedure.

if a mobile SATO Bluetooth printer is detected the listener is invoked with a PrinterActionType of LIST_PRINTER and the Printers Mac Address and Device Name in the device field of the PrinterEvent Structure.

On finish Discover process the callback method is invoked with a LIST_PRINTERS PrinterActionType and a list of all dicovered SATO Printers is available in the devices field of the PrinterEvent Structure.

complete source code

Examples

import { IonButton, IonContent, IonHeader, IonItem, IonList, IonPage, IonText, IonTitle, IonToolbar } from '@ionic/react';
import { Plugins } from '@capacitor/core';
import React, { Component } from 'react';
import ExploreContainer from '../components/ExploreContainer';
import './Home.css';
import 'capacitor-cidprint';
import { Device, ListenerTypes, PrinterActionType, PrinterEvent } from 'capacitor-cidprint';
import { useLocation } from 'react-router';
import { convertCompilerOptionsFromJson } from 'typescript';

const { CIDPrint } = Plugins;

export class Home extends Component {
  state = {
    enabled: false,
    connected: false,
    devname: '',
    devmac: '',
    devices: Array<Device>()
  }
  constructor(props: any) {
    super(props);
    this.state = { enabled: false, connected: false, devname: '', devmac: '', devices: [] };
  }

  discoverListener = Plugins.CIDPrint.addListener(ListenerTypes.DISCOVER, (result: any) => {
    let data: PrinterEvent = result.result[0];
    if(data.action === PrinterActionType.LIST_PRINTER) {
      this.setState({ devmac: data.device.devicemac, devname: data.device.devicename });
    } else if(data.action === PrinterActionType.LIST_PRINTERS) {
      this.setState({ devices: data.devices });
    }
  });

  printListener = Plugins.CIDPrint.addListener(ListenerTypes.PRINT, (result: any) => {
    let data: PrinterEvent = result.result[0];
    if(data.action === PrinterActionType.LIST_PRINTER) {
      this.setState({ devmac: data.device.devicemac, devname: data.device.devicename });
    } else if(data.action === PrinterActionType.LIST_PRINTERS) {
      if(data.devices.length > 0) {
        this.setState({ devmac: data.devices[0].devicemac, devname: data.devices[0].devicename });
      }
    }
  });

  async init() {
    await CIDPrint.initCIDPrinterLib();
  }

  async enableBluetooth() {
    this.setState({ enabled: await CIDPrint.enableBluetoothPrinting({enable: true})})
  }

  discover() {
    CIDPrint.discoverDevices();
  }

  async connect(printer: Device) {
    this.setState({connected: await CIDPrint.connectToPreferredPrinter({mac: printer.devicemac })})
  }

  async print(label: String, data: String[]) {
    console.log('vorher');
    await CIDPrint.printLabel({label: 'label41.dat'})
    console.log('nachher');
  }

  render() {
    return (
      <IonPage>
        <IonHeader>
          <IonToolbar>
            <IonTitle>Bluetooth Print</IonTitle>
          </IonToolbar>
        </IonHeader>
        <IonContent fullscreen>
          <IonButton onClick={() => this.init()}>Initialize Plugin</IonButton>
          <IonButton onClick={() => this.enableBluetooth()}>Enable Bluetooth</IonButton>
          <IonButton disabled={!this.state.enabled} onClick={() => this.discover()}>Discover Bluetooth Printer</IonButton>
          <IonButton disabled={!this.state.connected} onClick={() => this.print('', ['', ''])}>Print Label</IonButton>
          <IonList>
             {this.state.devices.map((item) => (
              <IonItem onClick={() => this.connect(item)}><IonText>{ item.devicename } -- { item.devicemac }</IonText></IonItem>
            ))}
           </IonList>
         </IonContent>
      </IonPage>
    );
  }
}

export default Home;
5.0.21

4 months ago

5.0.22

4 months ago

5.0.23

3 months ago

5.0.24

3 months ago

5.0.20

6 months ago

5.0.19

7 months ago

5.0.16

7 months ago

5.0.17

7 months ago

5.0.18

7 months ago

5.0.14

7 months ago

5.0.15

7 months ago

5.0.13

7 months ago

5.0.12

7 months ago

5.0.11

7 months ago

5.0.10

7 months ago

5.0.9

7 months ago

5.0.8

8 months ago

5.0.7

8 months ago

5.0.6

11 months ago

5.0.5

11 months ago

5.0.4

1 year ago

5.0.3

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

0.2.63

3 years ago

0.2.62

3 years ago

0.2.61

3 years ago

0.2.60

3 years ago

0.2.65

3 years ago

0.2.64

3 years ago

0.2.59

3 years ago

0.2.58

3 years ago

0.2.57

3 years ago

0.2.49

3 years ago

0.2.48

3 years ago

0.2.47

3 years ago

0.2.45

3 years ago

0.2.44

3 years ago

0.2.52

3 years ago

0.2.51

3 years ago

0.2.50

3 years ago

0.2.56

3 years ago

0.2.55

3 years ago

0.2.54

3 years ago

0.2.53

3 years ago

0.2.43

3 years ago

0.2.42

3 years ago

0.2.41

3 years ago

0.2.40

3 years ago

0.2.39

3 years ago

0.2.38

3 years ago

0.2.37

3 years ago

0.2.36

3 years ago

0.2.35

3 years ago

0.2.34

3 years ago

0.2.33

3 years ago

0.2.30

3 years ago

0.2.32

3 years ago

0.2.31

3 years ago

0.2.29

3 years ago

0.2.28

3 years ago

0.2.27

3 years ago

0.2.26

3 years ago

0.2.25

3 years ago

0.2.24

3 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.19

4 years ago

0.2.20

4 years ago

0.2.18

4 years ago