Menu

命令行工具


id: guide-cli
title: Command Line Tools

(These cli tools were formerly part of the serialport package and have now been moved to their own packages for ease of use.)

All cli tools can be run via npx or installed globally.

For Example:
$ npx @serialport/list
/dev/tty.Bluetooth-Incoming-Port
/dev/tty.usbmodem1421 Arduino (www.arduino.cc)

or

$ npm install -g @serialport/list
$ serialport-list
/dev/tty.Bluetooth-Incoming-Port
/dev/tty.usbmodem1421 Arduino (www.arduino.cc)

SerialPort List

$ npx @serialport/list [options]
# or
$ npm install -g @serialport/list
$ serialport-list [options]

The package @serialport/list will install the serialport-list cli tool which lists all available serial ports in different formats.

:::note
In @serialport/list@8 we renamed comName to path.
:::

$ serialport-list -h

  Usage: serialport-list [options]

  List available serial ports

  Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -f, --format <type>  Format the output as text, json, or jsonline. default: text

$ serialport-list
/dev/tty.Bluetooth-Incoming-Port
/dev/tty.usbmodem1421    Arduino (www.arduino.cc)

$ serialport-list -f json
[{"path":"/dev/tty.Bluetooth-Incoming-Port"},{"path":"/dev/tty.usbmodem1421","manufacturer":"Arduino (www.arduino.cc)","serialNumber":"752303138333518011C1","locationId":"14200000","vendorId":"2341","productId":"0043"}]

$ serialport-list -f jsonline
{"path":"/dev/tty.Bluetooth-Incoming-Port"}
{"path":"/dev/tty.usbmodem1421","manufacturer":"Arduino (www.arduino.cc)","serialNumber":"752303138333518011C1","locationId":"14200000","vendorId":"2341","productId":"0043"}

SerialPort Repl

$ npx @serialport/repl <port>
# or
$ npm install -g @serialport/repl
$ serialport-repl <port>

The package @serialport/repl will install the serialport-repl cli tool which provides a nodejs repl for working with serialport. This is valuable when debugging.

:::note
In @serialport/repl@8 we renamed comName to path.
:::

You can make use of the serialport-repl command with;

$ serialport-repl # to auto detect an arduino
$ serialport-repl /dev/tty.usbmodem1421 # to connect to a specific port

It will load a serialport object with debugging turned on.

$ serialport-repl
  serialport:binding:auto-detect loading DarwinBinding +0ms
port = SerialPort("/dev/tty.usbmodem1421", { autoOpen: false })
globals { SerialPort, portName, port }
> SerialPort.list()
  serialport:main .list +6s
[ { path: '/dev/tty.usbmodem1421',
    manufacturer: 'Arduino (www.arduino.cc)',
    serialNumber: '752303138333518011C1',
    pnpId: undefined,
    locationId: '14200000',
    vendorId: '2341',
    productId: '0043' } ]
> port.write('Calling all Autobots!')
true
> port.read()
  serialport:main _read queueing _read for after open +1m
null
> port.open()
  serialport:main opening path: /dev/tty.usbmodem1421 +30s
  serialport:bindings open +1ms

SerialPort Terminal

$ npx @serialport/terminal  -p <port> [options]
# or
$ npm install -g @serialport/terminal
$ serialport-terminal  -p <port> [options]

The package @serialport/terminal will install the serialport-terminal cli tool which provides a basic terminal interface for communicating over a serial port. ctrl+c will exit.

:::note
In @serialport/terminal@8 we renamed echo to no-echo and changed the default behavior to locally print what you type to the terminal by default.
:::


$ serialport-terminal -h

  Usage: serialport-terminal -p <path> [options]

  A basic terminal interface for communicating over a serial port. Pressing ctrl+c exits.

  Options:
  -l --list              List available ports then exit
  -p, --path <path>      Path of the serial port
  -b, --baud <baudrate>  Baud rate default: 9600 (default: 9600)
  --databits <databits>  Data bits default: 8 (default: 8)
  --parity <parity>      Parity default: none (default: "none")
  --stopbits <bits>      Stop bits default: 1 (default: 1)
  --no-echo              Don't print characters as you type them.
  -V, --version          output the version n
上一篇 下一篇
讨论数量: 0

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
刻意练习,每日精进。
~
点赞
215
浏览
0
讨论