CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Fri Jun 23, 2017 4:28 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
 Post subject: scan network
PostPosted: Fri Aug 19, 2016 12:41 pm 
Offline

Joined: Wed Apr 13, 2016 10:27 am
Posts: 13
Hello,

I have a question: How can i scan the network by Python? Because the project can not be login after network scanned . (CoDeSys version: SP9)

Thanks!

HHZ


Top
   
 Post subject: Re: scan network
PostPosted: Wed Aug 31, 2016 8:30 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 199
Hi hhz.

hhz wrote:
I have a question: How can i scan the network by Python? Because the project can not be login after network scanned . (CoDeSys version: SP9)

The API for managing gateways and scanning the network was introduced with CODESYS V3.5 SP8.

Here some example code:
Code:
# Find device object
found = projects.primary.find('Device', False)
assert(found and len(found) == 1, 'No or more than one device found')
dev = found[0]

# Find gateway
gw = online.gateways['Gateway-1']

# Scan network
targets = gw.perform_network_scan()

# Find the target in the result list
matchingTarget = None
for target in targets:
   print("Name: {} Addr: {}".format(target.device_name, target.address))
   if target.device_name == 'KELLERMANB':
      matchingTarget = target;
      break

# Set comm. path of the device
if matchingTarget:
   print('Set communication path of device')
   dev.set_gateway_and_device_name(gw, target.device_name)
   # or
   # dev.set_gateway_and_address(gw, target.address)
else:
   print('No matching target found')

Look for IScriptGateway, IScriptGateways and IScriptScanTargetDescription in the ScriptEngine API documentation.

BR
Martin

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited