@captureid/capacitor5-cidscan
TypeScript icon, indicating that this package has built-in type declarations

1.0.69 • Public • Published

appcenterbanner

Ionic Capacitor Plugin for Mobile Scan

This plugin provides the ability to use the CaptureID Scanner Library to easily integrate Camera scanning into your app(s).

Requirements

The CaptureID Sanner plugin expires after a 60 day 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 Scanner Plugin can be used in Ionic Capacitor app's to support scanning functionality with the Camera of your mobile device. It supports the most commonly used barcode symbologies.

Getting Started

Install or update the plugin into your existing project by running the command

npm install capacitor-cidscan@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

insert the line "add(CIDScan.class);" into the app's main activity file.

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
      add(CIDScan.class);
    }});
  }

Plugin Usage

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

  1. call 'initCIDScannerLib()' to initialize the plugin. This has to be done once before any other method call ech time the app starts. see Example

  2. Register Listeners to capture events from the Library. see Example

  3. Call 'activateLicense(key, customer)' with the data you have received when requesting a License. This method has to be called each time the app start's after initialization and before any other call.see Example

    To continue working with the Camera Scanner wait for the License Callback and check the result for sucessful license validation. see Example

  4. Now you can call the methods described below

API Reference

  • initCIDScannerLib(): Promise<{}>
  • closeCIDScannerLib(): Promise<{}>
  • activateLicense(options:{productkey: string, customer: string}): Promise<{}>
  • initScanner(options: {config: ScannerConfig})
  • setConfiguration(options: {config: ScannerConfig})
  • startScanner()
  • startPreview()
  • startDecode()
  • showUI(options: {show: boolean})
  • showSettings(options: {config: SannerConfig})
  • enableAllSymbologies(options: {enable: boolean})
  • enableSymbology(options: {symbology: Symbology, enable: boolean})
  • showAim(options: {style: AimStyle, color: Color, show: boolean})
  • _addListener(eventName: string, listenerFunc: (data: any) => void): PluginListenerHandle

initCIDScannerLib

initCIDScannerLib();

Version 0.1.0 Parameters:

  • none

Initialize the Library. Must be called once each time the app starts before any other method call. When app shuts down call closeCIDScannerLib. This will release resources and safely remove all used Objects.

closeCIDScannerLib

await closeCIDScannerLib();

Version 0.1.0 Parameters:

  • none

Close the Library and safely release all used resources and Objects.

activateLicense

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

Version 0.1.0 Parameters:

  • key (string) - valid Licensekey.

  • customer (string) - valid CustomerId.

Activate the library with the license key and customer ID provided. This method must be called every time the application is started before you can use other methods from the library.

Note:

A license key is valid for the period specified in your contract.

Evaluation keys are valid for a maximum of 60 days

initScanner

initScanner(config: ScannerConfig);

Parameters:

  • config ScannerConfig.

With this method you can initialize the camera/barcode Decoder with your individual config. If the config You can find a description of the configuration parameters here.

initScanner(options: {config: ScannerConfig}): void; setConfiguration(options: {config: ScannerConfig}): void; startScanner(): Promise<{value: DecoderStatusType;}>; startPreview(): Promise<{value: DecoderStatusType;}>; startDecode(): void; showUI(options: {show: boolean}): void; showSettings(options: {config: ScannerConfig}): void; enableAllSymbologies(options: {enable: boolean}): void; enableSymbology(options: {symbology: Symbology, enable: boolean}): void; showAim(options: {aim: Aim}): void;

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.

Sample Code

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.

Example

const { CIDScan } = Plugins;

addListener

licenseListener = Plugins.CIDScan.addListener(CIDScanListenerTypes.LICENSE, (result: any) => {
    let data: LicenseEvent = result.result[0];
    console.log("License Event");
    console.log(data);
  });
### activateLicense


    CIDScan.activateLicense({productkey: 'DvxZluDYBzqUVKNjA6TpfkNyI3YubdIpXquQ7OjqjgSkSuOXzi+LxjcpFn7hNQBwnbsHcLEsXwPqsO+VVSq315szU9389S/OYxJh9nbzyaD5VF0Qe9kbYB2ziQxOqZ++bQq5YChYFuKIGPBdP1idV9eyJbE9AX5NG6b3eYnH/+qpeGiR4esC/x65MNE76n/w4zG9O8knEY3wmrO1fu7ECZKPhyY5PizCLD/x6DFRx9/hAYM6xqUdl5K3UuA2/QXzggsr7MMMvCXiosG5XPpRis1BksMN8VXrAjyRQDJsgE9aI3AYkJn55pSWycX6dCpXMnnhj5RqKVjwjFNonKPxgjd+/fzJr/Th4j4xZGqA+PT0eJx63GbWX19gQCOegnBBihpIFXvbmCndn49FfrVVLA==', customer: 'P4I082220190001'});
    CIDScan.initScanner({config: config});
    CIDScan.startScanner();






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;

Configuration Description

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.691latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.691
1.0.680
1.0.670
1.0.660
1.0.650
1.0.641
1.0.630
1.0.620
1.0.610
1.0.600

Package Sidebar

Install

npm i @captureid/capacitor5-cidscan

Weekly Downloads

2

Version

1.0.69

License

MIT

Unpacked Size

72.4 MB

Total Files

126

Last publish

Collaborators

  • u-hoppe