0

I am trying to read from a modbus comport inside a docker IoT Edge module. I have supplied the relevant createOptions:

{ "HostConfig": { "Isolation": "Process", "Devices": [ { "PathOnHost": "class/86E0D1E0-8089-11D0-9CE4-08003E301F73", "PathInContainer": "", "CgroupPermissions": "" } ], "Binds": [ "C:/Streamwise:C:/Streamwise" ] } }

This works flawlessly on some ipcs but fails on others with a

System.IO.FileNotFoundException: Could not find file 'COM4'. File name: 'COM4'

when I try to open the serail port

This is the same error I receive if I dont specify any createOptions. So it appears that those options are not being applied. Any idea why?

Code snippet below

    public static void Connect(string portName)
    {
        Console.WriteLine(portName);
        // Configure serial port
        SerialPort port = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
        port.Open();
        master = new ModbusFactory().CreateRtuMaster(new SerialPortAdapter(port));
        master.Transport.ReadTimeout = 200;
        master.Transport.WriteTimeout = 200;
    }

Error occurs on port.open()

Additional context: for some reason on ipcs where I have to specify DNS server inside daemon.json for iotedge-moby, this problem occurs. Not sure if they are related or pure conincidence.

Jerry
  • 11

1 Answers1

0

You most probably need to map the host port to module port using PortBindings:

For example:

"createOptions": {
  "HostConfig": {
    "PortBindings": {
      "8080/tcp": [
        {
          "HostPort": "80"
        }
      ]
    }
  }
}

Reference: How to configure container create options for IoT Edge modules

asergaz
  • 996
  • 5
  • 17
  • nah thats for tcp/udp mapping, im trying to mount a hardware usb serial port – Jerry Oct 29 '21 at 07:05
  • Did you check this? https://stackoverflow.com/questions/24225647/docker-a-way-to-give-access-to-a-host-usb-or-serial-device – asergaz Oct 29 '21 at 08:48