Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Gateway config issue

etamgul
2016-01-15
2016-06-08
  • etamgul - 2016-01-15

    I have (assumably) 2 identical setups of CDS 3.5 SP7.
    Previously I was configuring the gateway on the first machine with the following code:

            gateway_guid = '3261a15d-434d-4868-9e1f-1bfa38e92408'; # HARDCODED_VALUE, gateway_guid = self.device.get_gateway()
            gateway_dev_addr = device_address   # HARDCODED_VALUE
       
            log.debug('Gateway {} set with GUID: {}'.format(str(gateway_guid),str(gateway_dev_addr)));
            self.device.set_gateway_and_address(gateway_guid, gateway_dev_addr);
    

    Now that I have a 2nd machine, I wanted to check if it is still working and I got the error:

    ValueError: Gateway 3261a15d-434d-4868-9e1f-1bfa38e92408 not found.
    

    I thought the GUID has changed so I modified to code to use the get_gateway method and suprisingly that gave the exact same GUID,
    and along with it, the result is also the same.
    No matter whether I use the harcoded or the 'dynamic' way, on my 2nd machine I get the above exception.

    Any idea what could be wrong?

     
  • mkeller - 2016-01-18

    Hi etamgul.

    Getting the gatewayPath in codesys.

    With CODESYS V3.5 SP8 we introducted a much better API for handling gateways and addresses. You can add, configure, find and remove gateways and also scan the network for available devices.

    BR
    Martin

     
  • etamgul - 2016-01-21

    Oh it works now (I tried what you suggested but by itself setting once the gateway is not enough).

    I had to set the project file to save the network settings, save the project and then the gateway guid I got previously turned to be valid.

    So until one checks that save parameter option in a project and configures the gateway at least once,
    no matter whether the gateway guid is valid, codesys scripting will throw this exception

     
  • Enchillada - 2016-06-01

    Could some please post an example about how to set the gateway with new API available in CODESYS V3.5.8.0.

    I have seen in the online help that there are some interface (IScriptGateways & IScriptGateway) available.
    But I do not know how to use them.

    Thanks.

     
  • Anonymous - 2016-06-08

    Originally created by: M.Schaber

    Hi,

    Here are some snippets using the new functions:
    Configuring a device via gateway name and device IP addres:

    proj = projects.open(path)
    dev = proj.find("Device")[0]
    dev.set_gateway_and_ip_address("Gateway-1", "127.0.0.1")
    

    printing all available gateway drivers:

    def printGatewayDriver(drv):
       print("BEGIN")
       print("GW driver: {} Guid={}".format(drv.name, drv.guid))
       for param in drv.gateway_parameters:
          print("Id={} Name={} Desc.={} ParamType={} DefaultValue={}".format(param.id, param.name, param.description, param.parameter_type, param.default_value))
       print("END")
       
    print("------ Available gateway drivers -----")
    for drv in online.gateway_drivers:
       printGatewayDriver(drv)
    

    print all gateway parameters for the TCP/IP driver:

    Zitat:
    tcpDriver = online.gateway_drivers["TCP/IP"]
    tcpParams = tcpDriver.gateway_parameters
    for param in tcpParams:
    print("id: %s, name: %s, description: %s" % (param.id, param.name, param.description))

    Adding a new gateway:

    secondGWName = "Gateway-QS"
    params = { 0: "serverqs", 1: "1217"}
    tcpDriver = online.gateway_drivers["TCP/IP"]
    newGw = online.gateways.add_new_gateway(secondGwName, params, tcpdriver)
    

    HTH,
    Markus

     

Log in to post a comment.