Giter VIP home page Giter VIP 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

node-cp2102n's Issues

Can't build missing libusb

23:54:56 ~ λ nix-shell --extra-experimental-features flakes -p cmake libusb    
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring

[nix-shell:~]# npm install --save cp2102n
npm ERR! code 1
npm ERR! path /root/node_modules/cp2102n
npm ERR! command failed
npm ERR! command sh -c node scripts/check-prebuild.cjs || npm run build:addon
npm ERR! > [email protected] build:addon
npm ERR! > cmake-js compile
npm ERR! 
npm ERR! Not searching for unused variables given on the command line.
npm ERR! -- The C compiler identification is GNU 13.2.0
npm ERR! -- The CXX compiler identification is GNU 13.2.0
npm ERR! -- Detecting C compiler ABI info
npm ERR! -- Detecting C compiler ABI info - done
npm ERR! -- Check for working C compiler: /nix/store/49nb1m1ysq0vx31qp94alpmi6ccsq9l3-gcc-wrapper-13.2.0/bin/gcc - skipped
npm ERR! -- Detecting C compile features
npm ERR! -- Detecting C compile features - done
npm ERR! -- Detecting CXX compiler ABI info
npm ERR! -- Detecting CXX compiler ABI info - done
npm ERR! -- Check for working CXX compiler: /nix/store/49nb1m1ysq0vx31qp94alpmi6ccsq9l3-gcc-wrapper-13.2.0/bin/g++ - skipped
npm ERR! -- Detecting CXX compile features
npm ERR! -- Detecting CXX compile features - done
npm ERR! -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
npm ERR! -- Checking for one of the modules 'libusb-1.0'
npm ERR! -- Configuring incomplete, errors occurred!
npm ERR! Not searching for unused variables given on the command line.
npm ERR! -- The C compiler identification is GNU 13.2.0
npm ERR! -- The CXX compiler identification is GNU 13.2.0
npm ERR! -- Detecting C compiler ABI info
npm ERR! -- Detecting C compiler ABI info - done
npm ERR! -- Check for working C compiler: /nix/store/49nb1m1ysq0vx31qp94alpmi6ccsq9l3-gcc-wrapper-13.2.0/bin/gcc - skipped
npm ERR! -- Detecting C compile features
npm ERR! -- Detecting C compile features - done
npm ERR! -- Detecting CXX compiler ABI info
npm ERR! -- Detecting CXX compiler ABI info - done
npm ERR! -- Check for working CXX compiler: /nix/store/49nb1m1ysq0vx31qp94alpmi6ccsq9l3-gcc-wrapper-13.2.0/bin/g++ - skipped
npm ERR! -- Detecting CXX compile features
npm ERR! -- Detecting CXX compile features - done
npm ERR! -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
npm ERR! -- Checking for one of the modules 'libusb-1.0'
npm ERR! -- Configuring incomplete, errors occurred!
npm ERR! info TOOL Using Unix Makefiles generator.
npm ERR! info CMD CONFIGURE
npm ERR! info RUN [
npm ERR! info RUN   'cmake',
npm ERR! info RUN   '/root/node_modules/cp2102n',
npm ERR! info RUN   '--no-warn-unused-cli',
npm ERR! info RUN   '-G',
npm ERR! info RUN   'Unix Makefiles',
npm ERR! info RUN   '-DCMAKE_JS_VERSION=7.3.0',
npm ERR! info RUN   '-DCMAKE_BUILD_TYPE=Release',
npm ERR! info RUN   '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/root/node_modules/cp2102n/build/Release',
npm ERR! info RUN   '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>',
npm ERR! info RUN   '-DCMAKE_JS_INC=/root/node_modules/node-api-headers/include;/root/node_modules/node-addon-api',
npm ERR! info RUN   '-DCMAKE_JS_SRC=',
npm ERR! info RUN   '-DNODE_RUNTIME=node',
npm ERR! info RUN   '-DNODE_RUNTIMEVERSION=20.11.1',
npm ERR! info RUN   '-DNODE_ARCH=arm64',
npm ERR! info RUN   '-DCMAKE_JS_LIB=',
npm ERR! info RUN   '-DCMAKE_CXX_FLAGS=-DBUILDING_NODE_EXTENSION'
npm ERR! info RUN ]
npm ERR! CMake Error at /nix/store/5ibhga0ync2yg1brk1hzlki71bq2dvb4-cmake-3.28.3/share/cmake-3.28/Modules/FindPkgConfig.cmake:906 (message):
npm ERR!   None of the required 'libusb-1.0' found
npm ERR! Call Stack (most recent call first):
npm ERR!   addon/libcp2102_usb/CMakeLists.txt:24 (pkg_search_module)
npm ERR! 
npm ERR! 
npm ERR! info REP Build has been failed, trying to do a full rebuild.
npm ERR! info CMD CLEAN
npm ERR! info RUN [
npm ERR! info RUN   'cmake',
npm ERR! info RUN   '-E',
npm ERR! info RUN   'remove_directory',
npm ERR! info RUN   '/root/node_modules/cp2102n/build'
npm ERR! info RUN ]
npm ERR! info CMD CONFIGURE
npm ERR! info RUN [
npm ERR! info RUN   'cmake',
npm ERR! info RUN   '/root/node_modules/cp2102n',
npm ERR! info RUN   '--no-warn-unused-cli',
npm ERR! info RUN   '-G',
npm ERR! info RUN   'Unix Makefiles',
npm ERR! info RUN   '-DCMAKE_JS_VERSION=7.3.0',
npm ERR! info RUN   '-DCMAKE_BUILD_TYPE=Release',
npm ERR! info RUN   '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/root/node_modules/cp2102n/build/Release',
npm ERR! info RUN   '-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>',
npm ERR! info RUN   '-DCMAKE_JS_INC=/root/node_modules/node-api-headers/include;/root/node_modules/node-addon-api',
npm ERR! info RUN   '-DCMAKE_JS_SRC=',
npm ERR! info RUN   '-DNODE_RUNTIME=node',
npm ERR! info RUN   '-DNODE_RUNTIMEVERSION=20.11.1',
npm ERR! info RUN   '-DNODE_ARCH=arm64',
npm ERR! info RUN   '-DCMAKE_JS_LIB=',
npm ERR! info RUN   '-DCMAKE_CXX_FLAGS=-DBUILDING_NODE_EXTENSION'
npm ERR! info RUN ]
npm ERR! CMake Error at /nix/store/5ibhga0ync2yg1brk1hzlki71bq2dvb4-cmake-3.28.3/share/cmake-3.28/Modules/FindPkgConfig.cmake:906 (message):
npm ERR!   None of the required 'libusb-1.0' found
npm ERR! Call Stack (most recent call first):
npm ERR!   addon/libcp2102_usb/CMakeLists.txt:24 (pkg_search_module)
npm ERR! 
npm ERR! 
npm ERR! ERR! OMG Process terminated: 1

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-04-19T23_55_10_395Z-debug-0.log

[nix-shell:~]# 

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.