npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cutos/devices

v3.2.6

Published

CUTOS Devices API is a JavaScript library that provides a unified interface for accessing and controlling hardware devices. Developers can use this interface to send and receive data, configure device parameters, and handle device events.

Downloads

60

Readme

Introduction

CUTOS Devices API is a JavaScript library that provides a unified interface for accessing and controlling hardware devices. Developers can use this interface to send and receive data, configure device parameters, and handle device events.

Devices and drivers communicate for data transmission, command reception, and status updates. Heartbeat monitoring is implemented for drivers to ensure continuous communication.

Table of Contents

  1. Printer

  2. IDCardReader

  3. Fingerprint

  4. NFC

Printer API

Installation

npm install @cutos/core

npm install @cutos/devices

Import dependencies

import {CoreAPI} from '@cutos/core';
import {DevicePrinter, PrinterCMD} from '@cutos/devices';

DevicePrinter

Constructor, create a printer instance

let devPrinter = new DevicePrinter();

DevicePrinter.init

Printer initialization

devPrinter.init(callback)

callback: callback function

Example:
devPrinter.init((result, error) => {
  if (error) {
    console.log(error)
    return;
  }
  console.log(result)
})
  • Return result example:
"Driver device-printer loaded"

DevicePrinter.readDeviceInfo

Read printer information

DevicePrinter.readDeviceInfo(callback)

callback: callback function

Example:
DevicePrinter.readDeviceInfo(data => {
  console.log(data)
})
  • Return result example:
{
  "name": "w80",
  "shareName": "w80",
  "portName": "USB001",
  "driverName": "MSW Printer Driver",
  "printProcessor": "winprint",
  "datatype": "RAW",
  "status": [],
  "statusNumber": 0,
  "attributes": [
    "DO-COMPLETE-FIRST",
    "LOCAL"
  ],
  "priority": 1,
  "defaultPriority": 0,
  "averagePPM": 0
}

DevicePrinter.onData

Get printer data

devPrinter.onData(callback)
  • callback: callback function
Example:
DevicePrinter.onData(function (data) {
  let resp = data.response;
  if (!resp.status) {
    console.warn('err:', resp.msg);
    return;
  }
  switch (data.cmd) {
    case 'print-test': //DevicePrinter.printTestPage(printer);
      break
    case 'print-pdf-url': //DevicePrinter.printPdfUrl(pdfUrl, printer);
      break
  }
});

DevicePrinter.printTestPage

Print test page

devPrinter.printTestPage(printer);
  • printer: printer name; when this parameter is not passed, the default printer is used for printing.

DevicePrinter.printPdfUrl

Print specified pdf file

devPrinter.printPdfUrl(pdfUrl, printer);
  • pdfUrl: URL address. For example: 'https://oss.cut-os.com/resources/developer/examples/printer/print-sample.pdf'
  • printer: printer name; when this parameter is not passed, the default printer is used for printing.

IDCardReader API

Installation

npm install @cutos/core

npm install @cutos/devices

Import dependencies

import {CoreAPI} from '@cutos/core';
import {DeviceIDCardReader} from '@cutos/devices';

DeviceIDCardReader

Constructor, create ID card instance

var devIDCardReader = new DeviceIDCardReader();

DeviceIDCardReader.init

ID card reader initialization

devIDCardReader.init(callback);
  • callback: callback function
Example:
devIDCardReader.init((result, error) => {
  if (!error) {
    console.log('onDeviceCreate', result)
  } else {
    console.log(error)
  }
});
  • Return result example:
Driver device-id-card-reader loaded

DeviceIDCardReader.connect

Connect ID card reader

devIDCardReader.connect(callback);
  • callback: callback function
Example:
devIDCardReader.connect((result) => {
  if (result.status) {
    console.log('connect success:', result)
  } else {
    console.log('connect failed:', result.msg)
  }
});

DeviceIDCardReader.disconnect

Disconnect ID card reader

devIDCardReader.disconnect();

DeviceIDCardReader.startRead

The card reader starts searching for the card

devIDCardReader.startRead([image], callback);
  • image: optional parameter, whether to read the ID card photo, the default is false. true means read, false means not read.
  • callback: callback function
Example:
devIDCardReader.startRead(result => console.log(result))
  • Return result example:
{
  "status": true,
  "msg": "reading"
}

DeviceIDCardReader.readDeviceInfo

Read ID card reader device information

devIDCardReader.readDeviceInfo(callback);
  • callback: callback function
Example:
devIDCardReader.readDeviceInfo(result => {
  console.log('device info:', result)
})
  • Return result example:
{
  "status": true,
  "msg": {
    "SAMID": "5-3-20220810-11478877-3979136230"
  }
}

DeviceIDCardReader.onData

Receive ID card information

devIDCardReader.onData(callback)
  • callback: callback function
Example:
devIDCardReader.onData((data) => {
  console.log('data', data)
})
  • Return result example:
{
  "code": 110111201607101234,
  "name": "Si Pu",
  "sex": "Male",
  "birthday": 20160710,
  "address": "No. 1705, Beihuan Center, No. 18 Yumin Road, Xicheng District, Beijing",
  "nation": "China",
  "department": "Xicheng District, Beijing",
  "startDate": 20160710,
  "endDate": 20260710,
  "certType": "ID card"
}

Fingerprint API

Installation

npm install @cutos/core

npm install @cutos/devices

Import dependencies

import {CoreAPI} from '@cutos/core';
import {DeviceFingerprint} from '@cutos/devices';

DeviceFingerprint

Constructor, create fingerprint device instance

let devFingerprint = new DeviceFingerprint(name);
  • name: fingerprint device name
Example:
devFingerprint = new DeviceFingerprint();

DeviceFingerprint.init

Fingerprint initialization

devFingerprint.init(callback);
  • callback: callback function
Example:
devFingerprint.init((result, error) => {
  if (!error) {
    console.log('onDeviceCreate', result)
  } else {
    console.log(error)
  }
});
  • Return result example:
Driver device-fingerprint loaded

DeviceFingerprint.connect

Connect fingerprint

DevFingerprint.connect(path, callback);
  • path: device port
  • callback: callback function
Example:
DevFingerprint.connect('/dev/ttyS1', (result) => {
  console.log(result)
});
  • Return result example:
{
  "status": true,
  "msg": "open success"
}

DeviceFingerprint.auth

Fingerprint recognition mode

DevFingerprint.auth(callback)
  • callback: callback function
Example:
DevFingerprint.auth((data) => {
  console.log('data', data)
})
  • Return result example:
{
  "status": true,
  "msg": "auth mode"
}

DeviceFingerprint.admin

Fingerprint management mode

DevFingerprint.admin(callback)
  • callback: callback function
Example:
DevFingerprint.admin((data) => {
  console.log(data)
})
  • Return result example:
{
  "status": true,
  "msg": "admin mode"
}

DeviceFingerprint.createUser1

Enter fingerprint step 1

DevFingerprint.createUser1(userID, callback)
  • userID: user ID
  • callback: callback function
Example:
DevFingerprint.createUser1(1, (data) => {
  console.log('data', data)
})
  • Return result example:
{
  "status": true
}

DeviceFingerprint.createUser2

Enter fingerprint step 2

DevFingerprint.createUser2(userID, callback)
  • userID: user ID
  • callback: Callback function
Example:
DevFingerprint.createUser2(1, (data) => {
  console.log('data', data)
})
  • Return result example:
{
  "status": true
}

DeviceFingerprint.createUser3

Enter fingerprint step 3

DevFingerprint.createUser3(userID, callback)
  • userID: user ID
  • callback: callback function
Example:
DevFingerprint.createUser3(1, (data) => {
  console.log('data', data)
})
  • Return result example:
{
  "status": true
}

DeviceFingerprint.deleteUser

Delete user

DevFingerprint.deleteUser(userID, callback)
  • userID: user ID
  • callback: callback function
Example:
DevFingerprint.deleteUser(1, (data) => {
  console.log('data', data)
})
  • Return result example:
{
  "status": true
}

DeviceFingerprint.onData

Get fingerprint data information

DevFingerprint.onData(callback)
  • callback: callback function
Example:
device.onData(data => {
  console.log(data)
})
  • Return result example:
{
  "authorized": 0
}

NFC API

Installation

npm install @cutos/core

npm install @cutos/devices

Import dependencies

import {CoreAPI} from '@cutos/core';
import {DeviceNFC} from '@cutos/devices';

DeviceNFC

Constructor, create NFC device instance

let devNFC = new DeviceNFC(name);
  • name: NFC device name
Example:
devNFC = new DeviceNFC('demo-nfc');

DeviceNFC.init

NFC device initialization

devNFC.init(callback);
  • callback: callback function
Example:
devNFC.init((result, error) => {
  if (!error) {
    console.log('onDeviceCreate', result)
  } else {
    console.log(error)
  }
});

DeviceNFC.connect

Connect NFC

devNFC.connect(callback);
  • callback: callback function
Example:
devNFC.connect((result) => {
  if (result.status) {
    console.log('connect success:', result)
  } else {
    console.log('connect failed:', result.msg)
  }
});

DeviceNFC.onData

Receive NFC information

DeviceNFC.onData(callback)
  • callback: callback function
Example:
DeviceNFC.onData((data) => {
  console.log('data', data)
})
  • Return result example:
{
  "id": "110111201"
}