Skip to content

eBUS Camera Nodes for Node-RED ​

@rosepetal/node-red-contrib-camera-ebus provides 3 nodes for Node-RED that receive the frames of GigE Vision cameras through the Pleora eBUS SDK, send them software triggers and change their parameters.

The package is in alpha. Its releases so far are alpha versions (the first one is v1.0.0-alpha.1), and it has been validated with one real device: the Pleora iPORT NTx-GigE, the image transmitter of the Omron V275 print inspector, a line-scan device that streams Mono8. What that device cannot exercise is marked on these pages as not tested yet.

Installation ​

Install the released package in the Node-RED user directory:

bash
cd ~/.node-red
npm install @rosepetal/node-red-contrib-camera-ebus

The package is not on the public npm registry. Its releases are published to Rosepetal's private npm registry, so npm needs that registry configured for the @rosepetal scope, with credentials for it. Restart Node-RED after the installation.

The cameras are driven by two services that run as Docker containers, from two images, ebus-camera-discovery and ebus-camera-publisher, tagged with the version of the package. When Start eBUS is pressed in a node's dialog, the images that are not on the host yet are pulled from Rosepetal's private container registry, so Docker on the host must be logged in to it.

After an upgrade of the package, press Stop eBUS and then Start eBUS: an existing discovery container is reused as it is, so the containers are only created from the images of the new version once they have been removed.

From a clone of the repository ​

A clone is meant for working on the package. The repository is private, so cloning it needs access to it. It keeps the eBUS SDK package, ebus-driver/eBUS_SDK_Ubuntu-22.04-x86_64-6.3.0-6343.deb, in Git LFS: clone it with Git LFS installed, or run git lfs pull after cloning. Then, on the host that runs Node-RED, as a user that can run docker:

bash
./install.sh

The script prints a warning when it does not run as root, and goes on. It:

  1. Extracts the eBUS SDK package into ebus-driver/eBUS_SDK/ with dpkg-deb -x. The package is not installed with dpkg, so its install scripts (a kernel module, network and udev changes) never run: the SDK works over the plain socket transport. The step is skipped when the SDK is already extracted, and stops when the .deb is still a Git LFS pointer.
  2. Builds the Docker images of the discovery service and of the camera publisher, tagged latest. It first removes the ebus-discovery container, the containers created from a previous latest publisher image and the images of a previous build.
  3. Runs npm install in node-red/, which installs the nats client and also the development dependencies that the tests use (Node-RED, mocha and the Node-RED test helper).
  4. Installs node-red/ with npm install into the first of these directories that exists: ~/.node-red, ~/node-red, /usr/local/lib/node_modules/node-red, /usr/lib/node_modules/node-red. When none exists, it prints the npm install command to run in the Node-RED user directory.

./install.sh --node-red-only runs only steps 3 and 4. Restart Node-RED afterwards.

The services do not start from a clone installed this way. The version in node-red/package.json of a clone is 0.0.0: the nodes look for the two images tagged 0.0.0, try to pull them when they are missing, and start the discovery container so that it runs the publishers from the publisher image tagged 0.0.0. No image is published with that tag, and the script builds them tagged latest. Give the two images it built the tag 0.0.0 as well before pressing Start eBUS:

bash
docker images | grep ebus-camera    # the full names of the two images
docker tag <discovery-image>:latest <discovery-image>:0.0.0
docker tag <publisher-image>:latest <publisher-image>:0.0.0

where <discovery-image> and <publisher-image> are the names, without the tag, that docker images lists.

Requirements ​

  • Linux x86-64 host with Docker Engine. The user that runs Node-RED must be allowed to run docker: the nodes call the Docker command line. The images carry the eBUS SDK 6.3.0-6343 for Ubuntu 22.04 x86-64.

  • A network interface of the host on the subnet of the cameras and on the same switch. Every container runs with the host network: GigE Vision discovery is UDP broadcast, and the stream comes back to a port that the SDK negotiates. A camera without a gateway, such as the iPORT NTx, only answers hosts of its own subnet.

  • A NATS server that listens on port 4222 of that host. The nodes connect to nats://127.0.0.1:4222, or to the URL in the NATS_URL environment variable of the Node-RED process; the discovery service connects to nats://localhost:4222 and the publishers to nats://127.0.0.1:4222, because the containers are started without NATS_URL.

  • Node-RED on the same host, with the host's /dev/shm visible to it: ebus-collector reads the frames from there. The publisher runs as root in its container and creates the segments with mode 0660, which the umask can only narrow, so they are readable only by root and the root group: run Node-RED as root or as a member of that group.

  • Node.js 20 or later, the version the tests run on.

  • A socket receive buffer large enough for the stream. The stream arrives as UDP packets at a high rate, and the receiver of the SDK caps its buffer at net.core.rmem_max: a small value shows up as lost packets and dropped frames, not as an error. The SDK ships a script for it, set_socket_buffer_size.sh in the bin folder of the extracted SDK, which must run as root and by default writes 10 MiB (10485760) to both net.core.rmem_max and net.core.wmem_max. A persistent setting, with a larger buffer for a host that runs several publishers (25 MiB is an example value):

    conf
    # /etc/sysctl.d/60-ebus.conf
    net.core.rmem_max = 26214400
    net.core.rmem_default = 26214400

    Jumbo frames (MTU 9000 on the interface and the switch) are optional. The publisher negotiates the packet size with the camera and falls back to 1476 bytes when the negotiation fails. On the iPORT NTx, which links at 100 Mb/s, the negotiation settles on 1476 bytes whatever the MTU, so jumbo frames have not been tested with a camera yet; with the SDK's software device and MTU 9000 the negotiation settled on 8976 bytes. install.sh changes none of these host settings.

  • GigE Vision devices that the eBUS SDK finds on a network interface of the host. The discovery service lists every GigE Vision device it finds, of any vendor; USB3 Vision devices are not listed. With Pleora hardware, such as the iPORT NTx, streaming needs no paid licence; GigE Vision cameras of other vendors need an eBUS licence for streaming.

Nodes ​

The three nodes appear under the RP eBUS category in the editor.

NodePurpose
ebus-collectorStart and stop the services and the cameras from its dialog, and emit every frame of the selected cameras as a raw image
ebus-triggerSend a software trigger to the selected cameras for each incoming message
ebus-configSet GenICam parameters of the selected cameras (region of interest, pixel format, acquisition mode, trigger settings or any other feature) from constants, the message or the context

How it works ​

The nodes do not open the cameras: two services that run as Docker containers on the same host do. The discovery service (container ebus-discovery) lists the GigE Vision devices with the eBUS SDK and starts or stops one publisher container per camera (ebus-<MAC>, with the MAC address in upper case and hyphens). Each publisher takes the control channel of its camera, receives its stream, writes each frame to shared memory (/dev/shm) and announces it through the NATS server. ebus-collector copies each announced frame from shared memory into a message, and ebus-trigger and ebus-config send their requests to the publisher through NATS.

Frames in Mono8 are passed through as they are, with one channel; frames in any other pixel format are converted to BGR8 by the publisher. The conversion has not been tested with a camera yet: the devices the package has been tested with stream Mono8.

The services and the nodes talk on these NATS subjects, where <MAC> is the MAC address in upper case with hyphens:

SubjectFrom → toContent
ebus/camerasdiscovery → nodes{cameras: [...], total}: the devices found, with their MAC, access state, interface, IP configuration, model, licence flag, whether their publisher runs, and the limits of their image size, exposure and gain
ebus/broadcastnodes → discovery{}: list the devices again and publish ebus/cameras
ebus/upnodes → discovery{mac, ninterface}: start the publisher of a camera on that interface
ebus/downnodes → discovery{mac}: stop and remove the publisher of a camera
ebus/fixnodes → discovery{mac}: give the device a new IP address (Fix IP)
ebus/<MAC>/notificationpublisher → collector{mac, frameId, timestamp, width, height, channels, pixelFormat, segment, size, blockId}: one per frame written to shared memory
ebus/<MAC>/statuspublisher → collector{mac, status, interface, timestamp, timestampMs}, and detail when there is a reason or a reply; status is connected, reconnecting, no_access or disconnected
ebus/<MAC>/triggertrigger → publisher{}
ebus/<MAC>/configconfig → publisher{params: {name: value}}

Any NATS client subscribed to ebus/<MAC>/status sees the replies of a publisher to triggers and parameters, which ebus-collector does not show.

Quick start ​

[ebus-collector] → [debug]

[inject] → [ebus-config]
  1. Start the NATS server before Node-RED.
  2. Add an ebus-collector node and open it. Press Start eBUS and wait for the panel to show Running: after some seconds the devices found on the network are listed under Available Cameras.
  3. Press Start on a camera whose status is Free. A camera in No access because its IP address does not fit the interface needs a new address first: Fix IP gives it one, but has not been tested on a real camera yet. The status changes to Controlled (this host) once the publisher container of the camera holds it.
  4. Tick the Select checkbox of the camera, close the dialog and deploy. The node shows <mac>: connected once the publisher has opened the camera, and emits one message per frame, with the image in msg.payload. A line-scan device sends frames only while the material moves under it.
  5. To change a parameter, add an ebus-config node, select the same camera in its dialog, add a row with the parameter and its value, and send the node a message from an inject node.

When it opens a camera, the publisher sets AcquisitionMode to Continuous, unless ebus-config has set a value for it. It does not change the trigger settings of the camera: use ebus-config to change them.

Line-scan devices ​

A line-scan device produces frames only while the material moves: with the press or the conveyor stopped, no frame arrives, and that is the normal state. The publisher waits up to 1 second at a time for a frame and does not count a wait without a frame as an error, so the camera stays connected and ebus-collector emits nothing.

The iPORT NTx of the Omron V275 delivers blocks of 2640 × 48 pixels in Mono8, 126 720 bytes each. When the head is mounted so that its lines come out reversed, as on the V275 the package was validated with, the Mirror horizontally option of ebus-collector flips them back.

To get frames from the iPORT NTx while nothing is printed, set its TestPattern feature to iPORTTestPattern with ebus-config: it then emits synthetic 2640 × 48 Mono8 blocks at about 100 per second, each row a 0, 1, 2, … ramp, through the whole chain (stream, shared memory, NATS, collector). Set it back to Off afterwards: the pattern replaces the image.

Access to a camera ​

GigE Vision control is exclusive: one application at a time holds the control channel of a camera. The publisher takes it in control mode, not in exclusive mode, so another application can still read the camera.

When another application controls the camera, the publisher reports no_access, with the IP address of that application when the camera gives it, and tries again until the camera is free. An application that disconnects without releasing the camera leaves it controlled until the heartbeat timeout of the camera runs out (its GevHeartbeatTimeout, which the controlling application sets; 5 seconds were measured on the iPORT NTx); the publisher then connects by itself.

On the Omron V275, the V275's own software holds the control channel of its iPORT NTx while it runs: stop that software while the nodes capture. The behaviour with the V275 software holding the camera has not been tested on hardware yet.

Restarts and reconnection ​

The containers are created with the restart policy unless-stopped: the discovery service and the publishers of the cameras that were started come back when Docker or the host restarts, without opening a dialog again.

A publisher whose camera cannot be opened keeps running and tries again, after 1 second and then after waits that double up to 5 seconds; meanwhile it reports reconnecting, or no_access when another application holds the camera. A publisher that loses its camera (the SDK reports the link lost, or 10 receive errors come in a row) reports reconnecting and opens the camera again. Once the camera is back it applies again the parameters it had received from ebus-config and resumes the acquisition. This was measured on the iPORT NTx by blocking its traffic for 15 seconds: the publisher reported the link lost after 5 seconds, and was connected again, with its parameters applied, 5 seconds after the traffic came back. Unplugging the cable has not been tested yet. The publisher does not repair the IP address of a camera by itself: when it reports that the IP configuration is not valid, use Fix IP.

The nodes share one connection to NATS per Node-RED process. Once it is open, the client reconnects by itself whenever the NATS server comes back; the services do the same.

Image format ​

msg.payload of ebus-collector is a raw image object:

javascript
{
  data: Buffer,         // Raw pixel data, 8 bits per channel, rows without padding
  width: number,        // Image width in pixels
  height: number,       // Image height in pixels
  channels: 1 | 3,      // 1 for Mono8, 3 for every other pixel format
  colorSpace: "GRAY" | "BGR",
  dtype: "uint8"
}

A Mono8 frame keeps its single channel (GRAY): a 2640 × 48 block of the iPORT NTx takes exactly 126 720 bytes. A frame in any other pixel format arrives as BGR8, 3 channels in B, G, R order; that conversion has not been tested with a camera yet.

It has the shape of the raw image object that the nodes of @rosepetal/node-red-contrib-image-tools pass between them; wiring it into those nodes has not been tested yet.

Diagnostics ​

The discovery image carries two command line tools; run them with the host network. <discovery-image> stands for the discovery image of the installed version, as docker images lists it.

bash
# GigE Vision devices seen by the eBUS SDK, one JSON object per line (--interfaces adds the network adapters)
docker run --rm --network host <discovery-image> /app/ebus_list --interfaces --timeout-ms 3000

# the camera list of the discovery service, printed once, without NATS and without starting anything
docker run --rm --network host <discovery-image> /app/camera_discovery --once

# logs of the services
docker logs -f ebus-discovery
docker logs -f ebus-<MAC>

# the shared memory segments of the publishers
ls -l /dev/shm/ebus_*

A device can answer the discovery on more than one interface of the host. ebus_list shows one line per interface on which it answered, each with its own configValid; the discovery service keeps one entry per MAC address, on the interface where the IP configuration of the device is valid when there is one. Use ebus_list when a camera shows No access.