5 releases

0.9.7 Nov 7, 2024
0.9.6 Oct 14, 2024
0.9.5 Jun 14, 2023
0.9.4 Jun 14, 2023
0.9.2 Jun 12, 2023

#294 in Network programming

Download history 4/week @ 2024-07-29 11/week @ 2024-09-23 182/week @ 2024-10-14 136/week @ 2024-11-04 9/week @ 2024-11-11

153 downloads per month

MIT license

21KB
376 lines

ADS proxy

build-main

This is a Beckhoff ADS proxy that could resolve multiple tcp connections with same ip address issues.

Usage

Download binary from github release page or cargo install ads-proxy, then run ads-proxy.

ADS proxy utility

Usage: ads-proxy [OPTIONS] <PLC_ADDR>

Arguments:
  <PLC_ADDR>  PLC address, e.g. 172.18.0.10:48898

Options:
  -d, --debug
          Debug mode
  -b, --buffer-size <BUFFER_SIZE>
          Buffer size (maximum size of a AMS packet) [default: 65536]
  -q, --queue-size <QUEUE_SIZE>
          Queue size (cached packets per connection) [default: 128]
  -r, --route-ams-net-id <ROUTE_AMS_NET_ID>
          Optional ams net id route, e.g. 10.10.10.10.1.1
  -u, --username <USERNAME>
          Optional PLC username (to add route)
  -p, --password <PASSWORD>
          Optional PLC password (to add route)
      --route-host <ROUTE_HOST>
          Optional Proxy hostname (hostname or ip address, detected from PLC connection)
  -l, --listen-addr <LISTEN_ADDR>
          Proxy listen address [default: 127.0.0.1:48898]
  -h, --help
          Print help
  -V, --version
          Print version

In pyads, connect to ads-proxy. For example, client 1 and 2 (process 1 and 2) on a host:

  • plc ams_net_id=192.168.0.10.1.1
  • client 1 ams_net_id=10.10.10.10.1.1
  • client 2 ams_net_id=10.10.10.10.1.2

Might need to add route entry in shell command with -r or in PLC configuration, see default user and password

ads-proxy -r 10.10.10.10.1.1 192.168.0.10:48898

client 1 (process 1)

import pyads

# x=1 or 2, process instance should have a unique ams net id
pyads.set_local_address("10.10.10.10.1.1")

plc1 = pyads.Connection(ams_net_id="192.168.0.10.1.1", ams_net_port=851, ip_address="127.0.0.1")
with plc1:
    ...

client 2 (process 2)

import pyads

# x=1 or 2, process instance should have a unique ams net id
pyads.set_local_address("10.10.10.10.1.2")

# app can create multiple ADS connections
# the packets will be sent in ONE tcp connection in a process instance
plc2 = pyads.Connection(ams_net_id="192.168.0.10.1.1", ams_net_port=851, ip_address="127.0.0.1")
with plc2:
    ...

How it works

client 1        --|
10.10.10.10.1.1   |
                  | multi-connections            one connection
client 2        ---------------------> ads-proxy --------------> PLC
10.10.10.10.1.2   |                    a.b.c.d          route 10.10.10.10.1.1
                  |                                            a.b.c.d
client n        --|   
10.10.10.10.x.y

License

MIT

Dependencies

~6–15MB
~172K SLoC