Skip to content

TypeScript/JavaScript examples for interacting with Motion Master to configure and control SOMANET devices.

Notifications You must be signed in to change notification settings

synapticon/motion-master-client-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Motion Master Client Examples

This repository provides TypeScript/JavaScript examples for interacting with Synapticon's Motion Master server application to configure and control SOMANET devices.

Building

Clone this repository and install its dependencies:

git clone https://github.com/synapticon/motion-master-client-examples.git
cd motion-master-client-examples
npm install

To transpile from TypeScript to JavaScript, use the following command:

npm run build

The resulting JavaScript files will be located in the dist folder.

Running

Before executing any scripts, ensure to set the MOTION_MASTER_HOSTNAME environment variable. For example, if the Motion Master process runs at 192.168.1.112, you have two options:

  1. Create a .env file in the repository root with MOTION_MASTER_HOSTNAME=192.168.1.112.
  2. Run a script directly by setting the variable inline: MOTION_MASTER_HOSTNAME=192.168.1.112 node ./dist/request/get-devices.rx.js.

The advantage of using the .env file is that all scripts will consistently use the specified hostname without needing to set the variable each time.

To log all incoming and outgoing messages from Motion Master, set the ROAR_LOG=true environment variable when running your scripts.

Here's an example .env file configuration:

MOTION_MASTER_HOSTNAME=192.168.1.112
ROARR_LOG=true

Alternatively, you can run TypeScript files directly without transpiling using ts-node:

npx ts-node ./src/request/get-devices.rx.ts

Command line arguments

All commands associated with a specific device require the --device-ref option, along with other specific arguments. To view detailed help documentation for any command, use the --help option. For example:

npx ts-node ./src/request/upload.ts --help
Usage: upload [options] <index> <subindex> [loadFromCache]

Arguments:
  index                          object index in hexadecimal notation
  subindex                       object subindex in hexadecimal notation
  loadFromCache                  load parameter values from the Motion Master cache (choices: "true", "false", default: false)

Options:
  -d, --device-ref <value>       position, address, or serial number (default: 0 position represents the first device in a network chain)
  -t, --request-timeout <value>  after sending a request, how long will the client wait for Motion Master to send the status message back
  -m, --message-id <value>       the message ID, which uniquely identifies the request, will be generated by the client library if not specified
  -h, --help                     display help for command

Here is an example of how to read the drive temperature:

npx ts-node ./src/request/upload.ts --device-ref=1 0x2031 0x01

Monitoring

To monitor output data and save it to both stdout and a file (data.csv), use:

node ./dist/start-monitoring.js --device-ref=1 | tee data.csv

Developing

To watch .ts files for changes and automatically transpile, use:

npm run watch

About

TypeScript/JavaScript examples for interacting with Motion Master to configure and control SOMANET devices.

Topics

Resources

Stars

Watchers

Forks