npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@csllc/cs-modbus-cli

v2.0.1

Published

Command line utilities based on cs-modbus

Downloads

17

Readme

cs-modbus-cli

This package provides a command line interface to @csllc/cs-modbus to implement a MODBUS master.

The mb utility provided by this package is known to work with NodeJS versions 10.22.1 and 12.18.3. Newer verions may or may not work due to package dependencies, and older versions may work without support for native CAN adapters (PCAN, Kvaser).

To install the package globally, use npm install -g @csllc/cs-modbus-cli.

To upgrade this package, assuming it was installed using the above command, use npm upgrade -g @csllc/cs-modbus-cli.

The mb ... command will then be available on your path.

For development purposes, clone or download the repository, and use npm install to install the dependencies. In this case the correct command to run the utility is node mb ...

Usage

mb -h displays the online help including the options.

In order to have a successful MODBUS connection, you need to correctly configure the master. The configuration items can be specified on the command line, stored in environment variables, or stored in a 'defaults' file. The command line switches take the highest precedence, and the defaults file is lowest.

To save the current configuration to the defaults file, append --save to any command. To view the configuration, use the --show command line switch.

Configuration

Connection

The connection represents the physical connection to the MODBUS slave(s).

  • Command line: --connection
  • Environment variable: MODBUS_CONNECTION

Examples:

  • --connection=serial to use a serial (COM) port
  • --connection=can-usb-com to use a CAN-USB-COM CANBUS adapter
  • --connection=can to use the universal CAN library with CAN-USB-COM, Peak-System PCAN-USB, or Kvaser USB devices. port must be configured when using this option.
Baud Rate

For serial connections, a baud rate may be specified: Command line: --baudrate Environment variable: MODBUS_BAUDRATE

Port

The port is a channel or physical port associated with some connection types. The acceptable values for the --port option depend on which --connection is used.

  • Command line: --port
  • Environment variable: MODBUS_PORT

Examples:

  • --port=/dev/tty.usbserial-A601UDGL to use a USB serial port (CAN-USB-COM) on macOS, in conjunction with --connection=can-usb-com
  • --port=canlib_0 to use channel 0 of a Kvaser Leaf Light v2 adapter, which is used in conjunction with --connection=can
  • --port=pcan-usb_81 to use a PCAN-USB adapter with a handle of 81, which is used in conjunction with --connection=can

Transport

The transport determines how the MODBUS PDUs are packaged when sent over the Connection.

  • Command line: --transport
  • Environment variable: MODBUS_TRANSPORT

Examples:

  • --transport=rtu for the MODBUS-RTU transport (eg. over a 'serial' connection)
  • --transport=j1939 for MODBUS over J1939 CANBUS connection

Unit

Determines the slave ID to which the commands will be targeted

  • Command line: --unit
  • Environment variable: MODBUS_SLAVE

CANBUS Rate

For CANBUS connections, the bus speed can be specified like:

  • Command line: --canrate
  • Environment variable: MODBUS_CANRATE

CANBUS ID

For CANBUS connections, the bus ID used by the master can be specified using

  • Command line: --canid
  • Environment variable: MODBUS_CANID

Examples

List all serial ports available on the system, including CAN-USB-COM devices:

mb -l --connection=serial

List all CAN-USB-COM devices available on the system:

mb -l --connection=can-usb-com

List all available CAN ports available on the system, including CAN-USB-COM devices:

mb -l --connection=can

Read the ID information from a slave using MODBUS-RTU over serial port:

mb read slave --connection=serial --transport=rtu --baudrate=9600 --slave=10

Adding the --save option allows you to omit the configuration for later commands:

mb read slave --connection=serial --transport=rtu --baudrate=9600 --slave=10 --save

Read a block of memory from the slave using stored configuration:

mb read memory 0x0000 16

Read a block of memory from a slave using CAN-USB-COM and save settings:

mb read memory --connection=can-usb-com --transport=j1939 --canrate=250000 --slave=10 --save

Read a block of memory from a slave using PCAN-USB with handle 81 (0x51) and save settings:

mb read memory --connection=can --port=pcan-usb_81 --transport=j1939 --canrate=250000 --slave=10 --save

Read a block of memory from a slave using channel 0 of a Kvaser CAN adapter and save settings:

mb read memory --connection=can --port=canlib_0 --transport=j1939 --canrate=250000 --slave=10 --save

Read an object from the same device:

mb read object 1

Write 2 bytes of memory (note that values prefixed by 0x are interpreted as hex):

mb write memory 0x400 0x55 0xAA