Input/Output Address Mapping of DeviceObjects

PLKM
2016-02-09
2021-01-21
  • PLKM - 2016-02-09

    Is it possible to get the address mapping (%QB0,...) of IO Devices ?

     
  • Anonymous - 2016-02-10

    Originally created by: M.Schaber

    Hi,

    PLKM hat geschrieben:
    Is it possible to get the address mapping (%QB0,...) of IO Devices ?

    This is possible since V3.5 SP8.

    Here's a small toy script:

    \#
    \# Methods
    \#
    def printDevParams(parmSet):
       for param in parmSet:
          print("param id={} name={}".format(param.id, param.name))
          printData(param, "")
    def printData(data, indent):
       print("{}data identifier={} value={}".format(indent, data.identifier, data.value))
       if data.is_mappable_io:
          io = data.io_mapping
          print("{}IO variable={}".format(indent, io.variable))
          if io.default_variable != None:
             print("{}IO default_variable={}".format(indent, io.default_variable))
       if data.has_sub_elements:
          for subData in data:
             printData(subData, indent + "--")
    \#
    \# Main program
    \#
    proj = projects.primary
    found = proj.find("In1", True)
    assert(len(found) == 1, "more than one object found")
    dev = found[0]
    print("device found")
    parms = dev.device_parameters
    if len(parms) > 0:
       printDevParams(parms)
    for conn in dev.connectors:
       print("connector={} id={}".format(conn.interface, conn.connector_id))
       parms = conn.host_parameters
       if len(parms) > 0:
          printDevParams(parms)
    conn = dev.connectors.by_id(1)
    input = conn.host_parameters.by_id(1)
    \# Check if byte is mapped
    byte0 = input["Byte0"]
    io = byte0.io_mapping
    if io.variable == "Application.GVL.byInput0":
       print("Byte0 is mapped correctly")
    \# Map some bytes and bits
    byte = input["Byte1"]
    io = byte.io_mapping
    io.variable = "byInput1"
    print("Byte1 mapped now")
    if io.mapping_creates_variable:
       print("Mapping creates the variable")
    byte = input["Byte2"]
    io = byte.io_mapping
    io.variable = "Application.GVL.byInput2"
    print("Byte2 mapped now")
    if io.maps_to_existing_variable:
       print("Mapping to existing variable")
    byte = input["Byte3"]
    bit = byte["Bit0"]
    io = bit.io_mapping
    io.variable = "Application.GVL.xBit0"
    print("Byte3.Bit0 mapped now")
    bit = byte["Bit1"]
    io = bit.io_mapping
    io.variable = "Application.GVL.xBit1"
    print("Byte3.Bit1 mapped now")
    \# Check for automatic and manual IEC addressing
    io = byte0.io_mapping
    if io.automatic_iec_address:
       print("IEC address is automatically set to " + io.manual_iec_address)
       io.manual_iec_address = "%IB10"
       if not io.automatic_iec_address:
          print("IEC address was switch to manual addressing")
          if io.manual_iec_address == "%IB10":
             print("IEC address was set correctly to " + io.manual_iec_address)
       io.manual_iec_address = None
       if io.automatic_iec_address:
          print("IEC address was switch back to automatic addressing")
    else:
       print("IEC address is manually set to " + io.manual_iec_address)
    
     
  • PLKM - 2016-02-10

    perfect, thank you

     
  • ThKa - 2017-04-24

    Hi,

    Is it a known limitation that you cannot map to an element of an array?

    for i in input:                           #ScriptValueDataElement
       i.io_mapping.variable = 'Application.GVL.G_xTest[0]'
    

    Best Regards
    Thomas

     
  • mkeller - 2017-04-25

    Hi Thomas.

    ThKa hat geschrieben:
    Is it a known limitation that you cannot map to an element of an array?

    for i in input:                           #ScriptValueDataElement
       i.io_mapping.variable = 'Application.GVL.G_xTest[0]'
    

    Have you tried it manually in the device editor?

    To reproduce the problem I need some additional information. What data type has the array in the GVL and the input in the IO mapping? Which version of CODESYS did you use?

    BR
    MArtin

     
  • ThKa - 2017-04-25

    Hi M.Keller,

    The version is 3.5 SP10.

    the GVL, an array of datatype BOOL which I map to %IX

    VAR_GLOBAL
       G_axInputArray : ARRAY[0..3] OF BOOL;
    END_VAR
    

    (...The Python code works if I don't use an array)

    The output from the interpreter using an array:

    Zitat:
    Invalid variable name: 'G_axInputArray[0]' is not a valid identifier.

     
  • jaka - 2021-01-21

    I tryed the scrip but it did not work. It shows an error at line with "byte0 = input["Byte0"]"

    It says "Operation not allowed on simple types"

     

Log in to post a comment.