pylogix icon indicating copy to clipboard operation
pylogix copied to clipboard

How to discover devices in all Vlans?

Open KaloyanR opened this issue 4 years ago • 12 comments

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

KaloyanR avatar Mar 10 '20 00:03 KaloyanR

There was a related discussion going on in issue #93

dmroeder avatar Mar 10 '20 00:03 dmroeder

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.

KaloyanR avatar Mar 10 '20 01:03 KaloyanR

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 avatar Mar 10 '20 02:03 dmroeder

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)

dmroeder avatar Mar 10 '20 02:03 dmroeder

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

KaloyanR avatar Mar 10 '20 02:03 KaloyanR

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

dmroeder avatar Mar 10 '20 02:03 dmroeder

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

KaloyanR avatar Mar 10 '20 03:03 KaloyanR

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

import pylogix
pylogix.__version__

dmroeder avatar Mar 10 '20 03:03 dmroeder

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.

KaloyanR avatar Mar 10 '20 04:03 KaloyanR

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

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

TheFern2 avatar Mar 10 '20 12:03 TheFern2

yes, 'except: pass' works, thanks.

KaloyanR avatar Mar 11 '20 02:03 KaloyanR

@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.

TheFern2 avatar Mar 11 '20 20:03 TheFern2