Code Monkey home page Code Monkey logo

node-cp2102n's Introduction

node-cp2102n build

license issues stars commits

Cross-platform Node.js binding for controlling GPIOs on Silicon Labs CP2102N.

Installation

npm install --save cp2102n

Prebuilt addon

This package shiped with prebuilt Node.js native addon for following platforms:

linux darwin win32
x64 TODO
arm n/a n/a
arm64 TODO

Build from source

npm install --save cp2102n --build-from-source

Additional build dependencies are required on different platforms:

Debian/Ubuntu

sudo apt install -y build-essential cmake ninja-build pkg-config libusb-1.0-0-dev

macOS

brew install cmake ninja pkg-config libusb

Runtime depencencies

Debian/Ubuntu

sudo apt install -y libusb-1.0-0

macOS

brew install libusb

Usage

import { openInterface } from 'cp2102n';

try {
  const device = await openInterface('/dev/cu.usbserial-1140');
  await device.set({ [0]: true, [6]: true });
  device.close();
} catch (e) {
  console.error(e);
}

APIs

openInterface(path)

  • path - string
  • Returns: Promise<CP2102N>

Open an interface with path (i.e. /dev/cu.usbserialXXX on macOS, /dev/ttyUSBX on Linux). Throws if path is not a valid CP2102N device.

Class: CP2102N

cp2102n.set(state)

  • state - { [pin: number]: boolean }
  • Returns: Promise<{ [pin: number]: boolean }>

Set state of pins to high (true) or low (false). Returns the latest state.

cp2102n.get()

  • Returns: Promise<{ [pin: number]: boolean }>

Get state of all PINs.

cp2102n.setRaw(state, mask)

  • state - number
  • mask - number
  • Returns: Promise<number>

Set state of masked pins in bits. Returns the latest state bits.

cp2102n.getRaw()

  • Returns: Promise<number>

Get state of pins in bits.

cp2102n.close()

Close interface.

License

MIT License

node-cp2102n's People

Contributors

xingrz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.