This repository provides TypeScript/JavaScript examples for interacting with Synapticon's Motion Master server application to configure and control SOMANET devices.
To commission SOMANET Circulo actuators and run 48-hour endurance tests, with the client library or in Python with the HTTP API, see src/actuator/README.md.
If npx is not found, Node is probably installed through nvm, which is only available once its
init script has been sourced. Once per terminal session:
source ~/.nvm/nvm.sh && nvm use --ltsTo have it loaded automatically, add nvm's init lines to your shell profile:
echo 'export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.zshrcRunning the examples in Docker (see below) sidesteps this entirely — the image brings its own Node.
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: 1 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.csvdocker-compose.yml defines a long-lived container named motion-master-client with this
repository mounted into it, so you edit files on your machine and run them inside the
container. It supersedes running docker build / docker run by hand — Compose still builds
from the Dockerfile, it just wires up the mounts and the hostname for you.
Note that this container is only the client. Motion Master itself needs the EtherCAT NIC
and runs outside the container. With Docker Desktop or OrbStack on macOS it has to run natively
on the Mac: a container there lives inside a Linux VM and cannot see the Mac's network
interfaces at all, not even with --privileged --network host.
Run all of the following from the repository root.
Start it, building the image on first use:
docker compose up -dRun a script inside it:
docker compose exec client npx ts-node src/request/get-devices.promise.tsCompiled JavaScript is faster to start. The repository mount hides the dist/ folder built into
the image, so build once inside the container first (and again after changing the sources). The
output lands in your working tree:
docker compose exec client npm run builddocker compose exec client node dist/request/get-devices.promise.jsOpen an interactive shell:
docker compose exec client shStop and resume the container. Both preserve everything — the repository is a bind mount, and packages installed inside live in a named volume:
docker compose stopdocker compose startRemove the container. The node_modules volume survives this; add -v to delete that too:
docker compose downMOTION_MASTER_HOSTNAME defaults to host.docker.internal, which resolves to the machine
running Docker. Never use localhost here — inside a container that is the container itself.
Compose takes the value from your shell or from the .env file in the repository root, the
same file the scripts read on the host. If your .env says localhost for running scripts on
the host, override it for the container, or point it at another machine:
MOTION_MASTER_HOSTNAME=192.168.1.112 docker compose up -dThe value is fixed when the container is created, and inside the container it wins over
.env. After changing it, run docker compose up -d again, which recreates the container;
docker compose start and restart keep the old value. ROARR_LOG is passed through the same
way, and only when it is set.
| State | Where it lives | Survives stop/start |
Survives down |
|---|---|---|---|
Your source files, dist/ and any output a script writes |
bind mount, i.e. your working tree | yes | yes |
| Packages installed inside the container | named volume node_modules |
yes | yes, unless down -v |
| Anything else in the container filesystem | container layer | yes | no |
Because the repository is mounted, files a script writes (recorded CSVs, generated plots) appear directly in your working tree rather than disappearing with the container.
node_modules is deliberately kept out of the mount: the host's copy is built for the host's
platform, and letting it shadow the image's Linux dependencies breaks any native module.
The node_modules volume is filled from the image only when it is first created. After a
change to package.json, for example a newer motion-master-client, rebuilding the image does
not update it. Install the new packages inside the container:
docker compose exec client npm installor start over with fresh packages:
docker compose down -v && docker compose up -d --buildTo watch .ts files for changes and automatically transpile, use:
npm run watch