Is it possible to get the address mapping (%QB0,...) of IO Devices ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
\#
defprintDevParams(parmSet):
  forparaminparmSet:
    print("param id={} name={}".format(param.id, param.name))
    printData(param, "")defprintData(data, indent):
  print("{}data identifier={} value={}".format(indent, data.identifier, data.value))
  ifdata.is_mappable_io:
    io=data.io_mapping
    print("{}IO variable={}".format(indent, io.variable))
    ifio.default_variable!=None:
      print("{}IO default_variable={}".format(indent, io.default_variable))
  ifdata.has_sub_elements:
    forsubDataindata:
      printData(subData, indent+"--")
\#
\# Mainprogram
\#
proj=projects.primaryfound=proj.find("In1", True)assert(len(found)==1, "more than one object found")dev=found[0]
print("device found")parms=dev.device_parametersiflen(parms)>0:
  printDevParams(parms)forconnindev.connectors:
  print("connector={} id={}".format(conn.interface, conn.connector_id))
  parms=conn.host_parameters
  iflen(parms)>0:
    printDevParams(parms)conn=dev.connectors.by_id(1)input=conn.host_parameters.by_id(1)
\# Checkifbyteismappedbyte0=input["Byte0"]
io=byte0.io_mappingifio.variable=="Application.GVL.byInput0":
  print("Byte0 is mapped correctly")
\# Mapsomebytesandbitsbyte=input["Byte1"]
io=byte.io_mappingio.variable="byInput1"print("Byte1 mapped now")ifio.mapping_creates_variable:
  print("Mapping creates the variable")byte=input["Byte2"]
io=byte.io_mappingio.variable="Application.GVL.byInput2"print("Byte2 mapped now")ifio.maps_to_existing_variable:
  print("Mapping to existing variable")byte=input["Byte3"]
bit=byte["Bit0"]
io=bit.io_mappingio.variable="Application.GVL.xBit0"print("Byte3.Bit0 mapped now")bit=byte["Bit1"]
io=bit.io_mappingio.variable="Application.GVL.xBit1"print("Byte3.Bit1 mapped now")
\# CheckforautomaticandmanualIECaddressingio=byte0.io_mappingifio.automatic_iec_address:
  print("IEC address is automatically set to "+io.manual_iec_address)
  io.manual_iec_address="%IB10"
  ifnotio.automatic_iec_address:
    print("IEC address was switch to manual addressing")
    ifio.manual_iec_address=="%IB10":
      print("IEC address was set correctly to "+io.manual_iec_address)
  io.manual_iec_address=None
  ifio.automatic_iec_address:
    print("IEC address was switch back to automatic addressing")else:
  print("IEC address is manually set to "+io.manual_iec_address)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ThKa hat geschrieben:
Is it a known limitation that you cannot map to an element of an array?
foriininput:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is it possible to get the address mapping (%QB0,...) of IO Devices ?
Originally created by: M.Schaber
Hi,
This is possible since V3.5 SP8.
Here's a small toy script:
perfect, thank you
Hi,
Is it a known limitation that you cannot map to an element of an array?
Best Regards
Thomas
Hi Thomas.
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
Hi M.Keller,
The version is 3.5 SP10.
the GVL, an array of datatype BOOL which I map to %IX
(...The Python code works if I don't use an array)
The output from the interpreter using an array:
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"