Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

xingrz/node-cp2102n

Repository files navigation

licenseissuesstarscommits

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:

linuxdarwinwin32
x64TODO
armn/an/a
arm64TODO

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{constdevice=awaitopenInterface('/dev/cu.usbserial-1140');awaitdevice.set({[0]:true,[6]:true});device.close();}catch(e){console.error(e);}

APIs

openInterface(path)

  • path -string
  • Returns:Promise<CP2102N>

Open an interface withpath (i.e./dev/cu.usbserialXXX on macOS,/dev/ttyUSBX on Linux). Throws ifpath 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


[8]ページ先頭

©2009-2025 Movatter.jp