Cross-platform Node.js binding for controlling GPIOs on Silicon Labs CP2102N.
npm install --save cp2102n
This package shiped with prebuilt Node.js native addon for following platforms:
linux | darwin | win32 | |
---|---|---|---|
x64 | ✓ | ✓ | TODO |
arm | ✓ | n/a | n/a |
arm64 | ✓ | TODO |
npm install --save cp2102n --build-from-source
Additional build dependencies are required on different platforms:
sudo apt install -y build-essential cmake ninja-build pkg-config libusb-1.0-0-dev
brew install cmake ninja pkg-config libusb
sudo apt install -y libusb-1.0-0
brew install libusb
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);
}
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.
state
-{ [pin: number]: boolean }
- Returns:
Promise<{ [pin: number]: boolean }>
Set state of pins to high (true
) or low (false
). Returns the latest state.
- Returns:
Promise<{ [pin: number]: boolean }>
Get state of all PINs.
state
-number
mask
-number
- Returns:
Promise<number>
Set state of masked pins in bits. Returns the latest state bits.
- Returns:
Promise<number>
Get state of pins in bits.
Close interface.