Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to discover devices in all Vlans? #111

Open
KaloyanR opened this issue Mar 10, 2020 · 12 comments
Open

How to discover devices in all Vlans? #111

KaloyanR opened this issue Mar 10, 2020 · 12 comments

Comments

@KaloyanR
Copy link

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

@dmroeder
Copy link
Owner

There was a related discussion going on in issue #93

@KaloyanR
Copy link
Author

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
Copy link
Owner

dmroeder commented Mar 10, 2020

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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

@KaloyanR
Copy link
Author

KaloyanR commented Mar 10, 2020

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
Copy link
Owner

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

import pylogix
pylogix.__version__

@KaloyanR
Copy link
Author

KaloyanR commented Mar 10, 2020

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
Copy link
Collaborator

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

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

@KaloyanR
Copy link
Author

yes, 'except: pass' works, thanks.

@TheFern2
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants