This repository provides TypeScript/JavaScript examples for interacting with Synapticon's Motion Master server application to configure and control SOMANET devices.
Clone this repository and install its dependencies:
git clone https://github.com/synapticon/motion-master-client-examples.git
cd motion-master-client-examples
npm installTo transpile from TypeScript to JavaScript, use the following command:
npm run buildThe resulting JavaScript files will be located in the dist folder.
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:
- Create a
.envfile in the repository root withMOTION_MASTER_HOSTNAME=192.168.1.112. - 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=trueAlternatively, you can run TypeScript files directly without transpiling using ts-node:
npx ts-node ./src/request/get-devices.rx.tsAll 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 commandHere is an example of how to read the drive temperature:
npx ts-node ./src/request/upload.ts --device-ref=1 0x2031 0x01To 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.csvTo watch .ts files for changes and automatically transpile, use:
npm run watch