dmroeder / pylogix

Read/Write data from Allen Bradley Compact/Control Logix PLC's
Apache License 2.0
594 stars 182 forks source link

How to discover devices in all Vlans? #111

Open KaloyanR opened 4 years ago

KaloyanR commented 4 years ago

Is there a way to discover devices in differents subnets? or with a list of addresses not broadcaast msg?

dmroeder commented 4 years ago

There was a related discussion going on in issue #93

KaloyanR commented 4 years ago

ok, thanks maybe broadcast msg is not good idea, but can I ask all devices one by one with a list of my IPs something like for loop to present themselves: IP, Product Name + Product Id + Vendor/Device ID ect.

dmroeder commented 4 years ago

I recently added GetDeviceProperties() that will get the properties of a device a particular IP address:

from pylogix import PLC

with PLC('192.168.1.10') as comm:
    ret = comm.GetDeviceProperties().Value
    print(ret.ProductName)

It differs from GetModuleProperties() in that requesting module properties requires a slot (for getting properties of I/O modules in a chassis) and device properties will allow you to target things like PowerFlex drives or servo drives.

dmroeder commented 4 years ago

Or for a list of addresses, you might have to do something like this:

from pylogix import PLC

addresses = ['192.168.1.10',
             '192.168.1.11']

for address in addresses:
    with PLC(address) as comm:
        ret = comm.GetDeviceProperties().Value
        print(ret.ProductName)
KaloyanR commented 4 years ago

OK, Thanks I will try it.

Traceback (most recent call last): File "C:\MotorService\testpylogix.py", line 14, in getDevices() File "C:\MotorService\testpylogix.py", line 9, in getDevices with PLC(address) as comm: TypeError: init() takes 1 positional argument but 2 were given

dmroeder commented 4 years ago

I'm guessing address in your code is a list. If you want help with your code, post it.

KaloyanR commented 4 years ago

OK It works. My fault in installation and venv settings.

================== RESTART: C:\MotorService\testpylogix.py ================== PowerFlex 525 3P 600V 1.0HP PowerFlex 525 3P 600V 1.0HP

dmroeder commented 4 years ago

Okay, cool. Out of curiosity, what version of python and pylogix are you using?

import pylogix
pylogix.__version__
KaloyanR commented 4 years ago

Pytnon 3.7 pylogix 0.6.2 Now the code works. But there is new problem, in given IP with no device ... error timeout and that stop code execution! How I can pass and continue to next IP, cause i need kind of network inventory/discovery. The idea is to make WinService code (auto execution) with for loop for All Vlans (subnets) one time per week and put all valid data to SQL.. Product code, Name, IPs ect. After that in SCADA I can periodicaly check Drives (select all PoweFlex 525 for example) saved in my SQL table for state, display and archive the faults. For communication with simple CIP device I use cpppo lib. //check all parameters directly from drive PF525. Is the pylogix can do that? Get Attribute Single/All - class/instance/attribute.

TheFern2 commented 4 years ago

@KaloyanR In regards to the timeout use a try catch.

https://docs.python.org/3/tutorial/errors.html

KaloyanR commented 4 years ago

yes, 'except: pass' works, thanks.

TheFern2 commented 4 years ago

@KaloyanR np. Normally you'd want to handle the exception. Print to the console or log, or something else. I guess if the IP doesn't exist, there's nothing to do hence why pass might be acceptable in your case.