# Factory Proxy Serial Port Access

Factory Proxy is a bridge between your devices, which need certificates, and PKI services, which generate the certificates. The devices in a factory may communicate in various ways. This article focuses on one of them, i.e. serial port connection, and presents how to enable this communication.

# How it works

Usually, serial devices communication work by binding a given device from the host to the module using Docker --device flag. However, that's not the case with Docker Swarm. In this case, socat may be used to redirect device communication via a pseudo-TTY device, which can be accessed by Factory Proxy modules using Docker volume binding.

Limitations

The presented solution has the limitation of being "static". You have to specify the list of devices upfront. You cannot hot plug/hot swap the devices.

# Before the installation

Before you execute the abb-factory-proxy-setup command (see the installation process here), you need to modify /var/ability/factoryproxy/factoryproxy.env (the file you already modified during the configuration).

Find the variable PREPARE_SERIAL_PERIPHERAL_DEVICES and list the serial devices that you want to access from your modules. Here's an example of configuration:

PREPARE_SERIAL_PERIPHERAL_DEVICES="ttyUSB0"

The example above shows the configuration of one serial device, i.e. /dev/ttyUSB0 (make sure your device is available in the /dev/ directory). If there are more devices that you want to use, provide them with space separation like this:

PREPARE_SERIAL_PERIPHERAL_DEVICES="ttyUSB0,cs8,parodd=1,stop=1,b9600,raw,echo=0 ttyUSB1,cs8,parodd=1,stop=1,b1200,raw,echo=0 ttyUSB1,cs8,parodd=1,stop=1,b9600,raw,echo=0 ttyUSB1,cs8,parodd=1,stop=1,b1200,raw,echo=0"

In the example above, three devices are configured to be accessible for the Factory Proxy module: /dev/ttyUSB0, /dev/ttyUSB1 and /dev/ttyUSB2.

# After the installation

After running the abb-factory-proxy-setup command, you should see information about systemd service installation:

Created symlink /etc/systemd/system/multi-user/target/wants/abb-factory-proxy-serial-peripheral-realy@...

You should now be able to see the files created by socat in /var/ability/factoryproxy/tty. These are the files that your module should bind to (via configuration). Here's an example of such configuration:

{
  ...
  "modules": {
    "my-module": {
      "docker": {
        ...
        "volumes": {
          "paths": [
            {
              "dockerPath": "/var/ability/factoryproxy/tty/",
              "hostPath": "/var/ability/factoryproxy/tty/"
            },
            {
              "dockerPath": "/dev/",
              "hostPath": "/dev/"
            }
          ]
        }
      }
    }
  }
}

Your module would access the serial port devices via the /var/ability/factoryproxy/tty/ path. For example, accessing the /var/ability/factoryproxy/tty/ttyUSB0 file will "redirect" you to the actual device file (/dev/ttyUSB0) by socat (assuming that that's one of the devices you have configured in the factoryproxy.env and it's connected).

Note that you should also add one more path binding - from host's /dev/ to container's /dev/. That is required for the solution to work properly.

More on configuration

You can find all of the configuration options available to you in the Configuration Schema section. The way to apply such a configuration is outlined in Onboarding.

With all that, you should be able to continue with the standard installation. When you run the systemctl enable --now abb-factory-proxy, your modules would come up. They should now be able to use the serial communication protocol to reach your devices connected to the host machine.

Author: Marcin Jahn
Last updated: 8/24/2022, 8:00:22 AM
Feedback