ottowayi / pycomm3

A Python Ethernet/IP library for communicating with Allen-Bradley PLCs.
MIT License
377 stars 88 forks source link

How to get controller state ? #310

Open tejas987 opened 5 months ago

tejas987 commented 5 months ago

I want to get in which state my controller in from following ?

States defined in CIP Spec Vol 1, chapter 5, Identity Object

STATES = { 0: "Nonexistent", 1: "Device Self Testing", 2: "Standby", 3: "Operational", 4: "Major Recoverable Fault", 5: "Major Unrecoverable Fault", **{i: "Reserved" for i in range(6, 255)}, 255: "Default for Get_Attributes_All service", }

From identity object i am able to get status(RUN, Prograam or TEST) of controller but not exact state ?

Colt-H commented 2 months ago

State is an optional parameter in the CIP spec, does your device support it? The below code snip should get you where you need to go, make sure to update your device path.

with CIPDriver("10.0.0.1") as device:
    data = device.generic_message(
            service=Services.get_attribute_single,
            class_code=ClassCode.identity_object,
            instance=b"\x01",
            attribute=8, #State attribute per CIP Spec
            data_type='USINT'
    )