Giter VIP home page Giter VIP logo

node-picmd's Introduction

node-picmd

The node-picmd is a client library for picmd.

Overview

The node-picmd is a client library for picmd, a command handler framework with serial communication for Raspberry PI.

It abstracts the communication specification of picmd and makes it easy to use.

Example

The sample code for sending the "0x01" command and receiving the response is as follows.

const { PiCmd } = require('@ushiboy/picmd');

(async function() {
  const pic = PiCmd.connect('/dev/ttyUSB0');

  const r = await pic.request(0x01);
  console.log(r.value.toString('utf-8'));

}());

API

PiCmd class

The picmd client class.

PiCmd.connect(port: string): PiCmd

Create an instance of PiCmd by passing the serial port path.

  • parameters
    • port
      • The serial port path.
      • type: string
  • return
    • The instance of PiCmd.
    • type: PiCmd

waitReady(retry?: number): Promise<void>

Wait until there is a PING response.

  • optional parameters
    • retry
      • Number of times to repeat the PING command.
      • type: number
      • default: 20

ping(timeout?: number): Promise<void>

Send a ping command.

  • optional parameters
    • timeout
      • Timeout waiting for a ping command response.
      • type: number
      • default: 2000 ms

request(command: number, data?: Buffer, timeout?: number): Promise<CommandResponse>

Send a command and return a response.

  • parameters
    • command
      • The command to send.
      • type: number
  • optional parameters
    • data
      • The data of the command to be sent.
      • type: Buffer
    • timeout
      • Timeout waiting for a command response.
      • type: number
      • default: 60000 ms
  • return
    • The result of the execution of the command.
    • type: CommandResponse

CommandResponse type

The result of the execution of the command.

  • properties
    • status
      • The status of the command execution result.
      • type: number
    • size
      • The response data size of command execution result.
      • type: number
    • value
      • The response data of command execution result.
      • type: Buffer
    • parity
      • The parity value for checking
      • type: number

Change Log

0.1.1

Fix example code.

0.1.0

Initial release.

License

MIT

node-picmd's People

Contributors

ushiboy avatar

Watchers

James Cloos 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.