CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Fri Jul 28, 2017 1:43 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Feb 09, 2016 11:02 am 
Offline

Joined: Wed Aug 12, 2015 12:16 pm
Posts: 12
Is it possible to get the address mapping (%QB0,...) of IO Devices ?


Top
   
PostPosted: Wed Feb 10, 2016 2:59 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

PLKM wrote:
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:
Code:
#
# 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)


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

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


Top
   
PostPosted: Wed Feb 10, 2016 3:15 pm 
Offline

Joined: Wed Aug 12, 2015 12:16 pm
Posts: 12
perfect, thank you :)


Top
   
PostPosted: Mon Apr 24, 2017 5:20 pm 
Offline

Joined: Mon Apr 10, 2017 7:36 pm
Posts: 2
Hi,

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

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




Best Regards
Thomas


Top
   
PostPosted: Tue Apr 25, 2017 12:03 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 202
Hi Thomas.

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

Code:
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

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

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


Top
   
PostPosted: Tue Apr 25, 2017 5:44 pm 
Offline

Joined: Mon Apr 10, 2017 7:36 pm
Posts: 2
Hi M.Keller,

The version is 3.5 SP10.

the GVL, an array of datatype BOOL which I map to %IX
Code:
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:
Quote:
Invalid variable name: 'G_axInputArray[0]' is not a valid identifier.


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


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