ottowayi / pycomm3

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

[FEATURE] - Remote address for CIPDriver.discover #291

Closed tlf30 closed 1 year ago

tlf30 commented 1 year ago

Hello Ian, Thanks for all the help recently with the radix support. I have some interns this summer and I have them working on a project to take a full system inventory of our PCN using python. This was an issue that came up when trying to find devices on our other subnets.

Type of Feature Request

Feature Description Ability to send the identity broadcast to a remote address. This address could be a single IP or a broadcast address of a remote subnet.

Possible Solution The CIPDriver.discover could have an optional argument that specifies the remove broadcast address.

Additional context This is useful when a PCN consists of multiple subnets and trying to identify devices on a subnet that the engineering workstation is not on. RSLinx handles this just fine by simply sending the broadcast to the target subnet.

Thank you, Trevor

tlf30 commented 1 year ago

I'll open a PR in a bit, I'm getting on a plane in an hour. My interns just tested a small change to the code that works great. https://github.com/ottowayi/pycomm3/blob/91ca09c2c00a98de877e66157981d895832de753/pycomm3/cip_driver.py#L193

def discover(cls) -> List[Dict[str, Any]]: can be changed to def discover(cls, broadcast_address = "255.255.255.255") -> List[Dict[str, Any]]:

https://github.com/ottowayi/pycomm3/blob/91ca09c2c00a98de877e66157981d895832de753/pycomm3/cip_driver.py#L228C17-L228C17

def _broadcast_discover(cls, ip, message, request): can be changed to def _broadcast_discover(cls, ip, message, request, broadcast_address="255.255.255.255"):

And the calling of broadcast_discover on lines 212 and 218 just need the additional broadcast_address parameter added. This will preserve backwards compatibility.

Thoughts?

ottowayi commented 1 year ago

thanks for this, I've merged it and bumped the version to 1.2.13