scan network

hhz
2016-08-19
2016-08-31
  • hhz - 2016-08-19

    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

     
  • mkeller - 2016-08-31

    Hi hhz.

    hhz hat geschrieben:
    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:

    \# 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

     

Log in to post a comment.