EtherNet/IP#
EtherNet/IP config files declare an Allen-Bradley PLC endpoint, an optional local backplane route,
and the scalar tags Nominal reads or writes. The client lives under instro.ethernetip
and is provided by the instro-ethernetip package, installable via the instro[ethernetip]
extra (also included in instro[all]).
from instro.ethernetip import EtherNetIPDevice
connection = {
"host": "192.168.1.10",
"port": 44818,
"route_path": {"hops": [{"type": "backplane", "slot": 0}]},
}
plc = EtherNetIPDevice("compactlogix.json", connection=connection, autostart=True)
plc.read_tag("line_speed")
plc.write_tag("line_speed", 1200.0)
plc.close()
Current scope#
Area |
Supported today |
|---|---|
Tested PLC |
Allen-Bradley CompactLogix 5332E 1769-L32E |
Transport |
EtherNet/IP explicit messaging over TCP |
Route paths |
Direct connection or local backplane slot hops only |
Polling |
Automatic batched reads for |
Streaming values |
Boolean and numeric scalar tags |
Manual native operations |
Single-tag reads, batched reads, and writes |
Unsigned integer validation |
|
Tag discovery |
Not supported |
UDTs |
Not supported in the config-driven API |
Arrays |
Not supported in the config-driven API |
JSON config reference#
Connection#
Provide the connection in the config or pass it to the EtherNetIPDevice constructor. The constructor
parameter takes precedence, so one tag map can target multiple environments.
plc = EtherNetIPDevice(
"compactlogix.json",
connection={
"host": "192.168.1.10",
"port": 44818,
"route_path": {"hops": [{"type": "backplane", "slot": 0}]},
},
)
{
"connection": {
"host": "192.168.1.10",
"port": 44818,
"route_path": {
"hops": [
{"type": "backplane", "slot": 0}
]
}
}
}
Field |
Type |
Default |
Description |
|---|---|---|---|
|
string |
required |
PLC IP address or hostname |
|
int |
|
EtherNet/IP TCP port |
|
object |
|
Optional local backplane route path |
Route paths accept local backplane hops only:
Field |
Type |
Default |
Description |
|---|---|---|---|
|
list |
|
Ordered local backplane hops |
|
string |
required |
Must be |
|
int |
required |
Backplane slot number, 0-255 |
Network hops to another PLC, remote chassis, or IP address are not supported. The schema accepts multiple local backplane hops, but current testing has covered one backplane hop.
Timing#
The timing section controls background polling:
{
"timing": {
"poll_interval": 1.0
}
}
Field |
Type |
Default |
Description |
|---|---|---|---|
|
float |
required |
Seconds between polling cycles (0.01-10.0) |
When polling is running, EtherNetIPDevice reads every poll: true tag in one batched native
request at the configured interval. A per-tag failure skips that tag for the current measurement;
successful values from the same batch are still published.
Native batched reads#
instro.ethernetip._ethernetip.EtherNetIpSession.read_tags() reads several PLC tags in one native
request and preserves input order:
from instro.ethernetip._ethernetip import EtherNetIpBatchError, EtherNetIpSession
with EtherNetIpSession("192.168.1.10:44818", route_path_slots=[0]) as session:
for name, result in session.read_tags(["MotorRunning", "LineSpeed"]):
if isinstance(result, EtherNetIpBatchError):
print(name, result)
continue
print(name, result.kind, result.value)
The call raises EtherNetIpError when the whole batch cannot be dispatched or parsed. Individual
tag failures are returned as typed EtherNetIpBatchError instances, including TagNotFoundError,
DataTypeMismatchError, NetworkBatchError, CipError, TagPathError, SerializationError,
BatchTimeoutError, and OtherBatchError.
Write limits#
Reject writes outside the configured range before they reach the PLC:
{
"alias": "line_speed",
"tag_name": "LineSpeed",
"data_type": "real",
"write_min": 0.0,
"write_max": 2500.0
}
plc.write_tag("line_speed", 1200.0) # OK
plc.write_tag("line_speed", 9999.0) # raises ValueError: above write_max (2500.0)
EtherNetIPDevice checks limits before sending the write to the PLC.
Validation rules#
protocolmust be"ethernetip".Tag aliases must be unique.
Every tag must declare
data_type.write_minandwrite_maxare only valid for numeric tags.write_minmust be less than or equal towrite_max.Integer write limits must fit in the configured PLC integer type.
Route path hops must use
type: "backplane"withslotfrom 0 to 255.Tag discovery, UDTs, and arrays are not supported.
API reference#
EtherNetIPDevice#
EtherNet/IP device with config-driven tag access. |
Configuration types#
Complete EtherNet/IP instrument configuration. |
|
Timing configuration for EtherNet/IP polling. |
|
EtherNet/IP TCP endpoint configuration. |
|
Ordered EtherNet/IP route path supported by the native backend. |
|
One supported EtherNet/IP backplane route hop. |
|
Definition of one EtherNet/IP tag exposed as an instrument channel. |