canfestival/config_utils.py
changeset 1911 c1298e7ffe3a
parent 1581 2295fdc5c271
child 1722 89824afffef2
equal deleted inserted replaced
1910:a375e31bf312 1911:c1298e7ffe3a
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 #This file is part of Beremiz, a Integrated Development Environment for
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 #programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     8 #
     8 #
     9 #See COPYING file for copyrights details.
     9 # See COPYING file for copyrights details.
    10 #
    10 #
    11 #This library is free software; you can redistribute it and/or
    11 # This program is free software; you can redistribute it and/or
    12 #modify it under the terms of the GNU General Public
    12 # modify it under the terms of the GNU General Public License
    13 #License as published by the Free Software Foundation; either
    13 # as published by the Free Software Foundation; either version 2
    14 #version 2.1 of the License, or (at your option) any later version.
    14 # of the License, or (at your option) any later version.
    15 #
    15 #
    16 #This library is distributed in the hope that it will be useful,
    16 # This program is distributed in the hope that it will be useful,
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19 #General Public License for more details.
    19 # GNU General Public License for more details.
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 # You should have received a copy of the GNU General Public License
    22 #License along with this library; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 from types import *
    25 from types import *
    26 
    26 
    27 # Translation between IEC types and Can Open types
    27 # Translation between IEC types and Can Open types
    28 IECToCOType = {"BOOL":0x01, "SINT":0x02, "INT":0x03,"DINT":0x04,"LINT":0x10,
    28 IECToCOType = {"BOOL":0x01, "SINT":0x02, "INT":0x03,"DINT":0x04,"LINT":0x10,
   350                 # Extract and check nodeid
   350                 # Extract and check nodeid
   351                 nodeid, index, subindex = loc[:3]
   351                 nodeid, index, subindex = loc[:3]
   352                 
   352                 
   353                 # Check Id is in slave node list
   353                 # Check Id is in slave node list
   354                 if nodeid not in self.NodeList.SlaveNodes.keys():
   354                 if nodeid not in self.NodeList.SlaveNodes.keys():
   355                     raise PDOmappingException, _("Non existing node ID : %d (variable %s)") % (nodeid,name)
   355                     raise PDOmappingException, _("Non existing node ID : {a1} (variable {a2})").format(a1 = nodeid, a2 = name)
   356                 
   356                 
   357                 # Get the model for this node (made from EDS)
   357                 # Get the model for this node (made from EDS)
   358                 node = self.NodeList.SlaveNodes[nodeid]["Node"]
   358                 node = self.NodeList.SlaveNodes[nodeid]["Node"]
   359                 
   359                 
   360                 # Extract and check index and subindex
   360                 # Extract and check index and subindex
   361                 if not node.IsEntry(index, subindex):
   361                 if not node.IsEntry(index, subindex):
   362                     raise PDOmappingException, _("No such index/subindex (%x,%x) in ID : %d (variable %s)") % (index,subindex,nodeid,name)
   362                     msg = _("No such index/subindex ({a1},{a2}) in ID : {a3} (variable {a4})").\
       
   363                           format(a1 = "%x" % index, a2 ="%x" % subindex, a3 = nodeid, a4 = name)
       
   364                     raise PDOmappingException, msg
   363                 
   365                 
   364                 # Get the entry info
   366                 # Get the entry info
   365                 subentry_infos = node.GetSubentryInfos(index, subindex)
   367                 subentry_infos = node.GetSubentryInfos(index, subindex)
   366                 
   368                 
   367                 # If a PDO mappable
   369                 # If a PDO mappable
   368                 if subentry_infos and subentry_infos["pdo"]:
   370                 if subentry_infos and subentry_infos["pdo"]:
   369                     if sizelocation == "X" and len(loc) > 3:
   371                     if sizelocation == "X" and len(loc) > 3:
   370                         numbit = loc[3]
   372                         numbit = loc[3]
   371                     elif sizelocation != "X" and len(loc) > 3:
   373                     elif sizelocation != "X" and len(loc) > 3:
   372                         raise PDOmappingException, _("Cannot set bit offset for non bool '%s' variable (ID:%d,Idx:%x,sIdx:%x))") % (name,nodeid,index,subindex)
   374                         msg = _("Cannot set bit offset for non bool '{a1}' variable (ID:{a2},Idx:{a3},sIdx:{a4}))").\
       
   375                               format(a1 = name, a2 = nodeid, a3 = "%x" % index, a4 = "%x" % subindex)
       
   376                         raise PDOmappingException, msg
   373                     else:
   377                     else:
   374                         numbit = None
   378                         numbit = None
   375                     
   379                     
   376                     if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype:
   380                     if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype:
   377                         raise PDOmappingException, _("Invalid type \"%s\"-> %d != %d  for location\"%s\"") % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name)
   381                         raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3}  for location\"{a4}\"").\
       
   382                             format(a1 = location["IEC_TYPE"], a2 = COlocationtype, a3 = subentry_infos["type"] , a4 = name)
   378                     
   383                     
   379                     typeinfos = node.GetEntryInfos(COlocationtype)
   384                     typeinfos = node.GetEntryInfos(COlocationtype)
   380                     self.IECLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction],
   385                     self.IECLocations[name] = {"type":COlocationtype, "pdotype":SlavePDOType[direction],
   381                                                 "nodeid": nodeid, "index": index,"subindex": subindex,
   386                                                 "nodeid": nodeid, "index": index,"subindex": subindex,
   382                                                 "bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation}
   387                                                 "bit": numbit, "size": typeinfos["size"], "sizelocation": sizelocation}
   383                 else:
   388                 else:
   384                     raise PDOmappingException, _("Not PDO mappable variable : '%s' (ID:%d,Idx:%x,sIdx:%x))") % (name,nodeid,index,subindex)
   389                     raise PDOmappingException, _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))").\
       
   390                         format(a1 = name, a2 = nodeid, a3 = "%x" % index, a4 = "%x" % subindex)
   385         
   391         
   386         #-------------------------------------------------------------------------------
   392         #-------------------------------------------------------------------------------
   387         #                         Search for locations already mapped
   393         #                         Search for locations already mapped
   388         #-------------------------------------------------------------------------------
   394         #-------------------------------------------------------------------------------
   389         
   395         
   628             # Extract and check nodeid
   634             # Extract and check nodeid
   629             index, subindex = loc[:2]
   635             index, subindex = loc[:2]
   630             
   636             
   631             # Extract and check index and subindex
   637             # Extract and check index and subindex
   632             if not slave.IsEntry(index, subindex):
   638             if not slave.IsEntry(index, subindex):
   633                 raise PDOmappingException, _("No such index/subindex (%x,%x) (variable %s)") % (index, subindex, name)
   639                 raise PDOmappingException, _("No such index/subindex ({a1},{a2}) (variable {a3})").\
       
   640                     format(a1 = "%x" % index, a2 = "%x" % subindex, a3 = name)
   634             
   641             
   635             # Get the entry info
   642             # Get the entry info
   636             subentry_infos = slave.GetSubentryInfos(index, subindex)    
   643             subentry_infos = slave.GetSubentryInfos(index, subindex)    
   637             if subentry_infos["type"] != COlocationtype:
   644             if subentry_infos["type"] != COlocationtype:
   638                 raise PDOmappingException, _("Invalid type \"%s\"-> %d != %d  for location\"%s\"") % (location["IEC_TYPE"], COlocationtype, subentry_infos["type"] , name)
   645                 raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\
       
   646                     format( a1 = location["IEC_TYPE"], a2 = COlocationtype, a3 = subentry_infos["type"] , a4 = name)
   639             
   647             
   640             IECLocations[name] = COlocationtype
   648             IECLocations[name] = COlocationtype
   641             pointers[(index, subindex)] = name
   649             pointers[(index, subindex)] = name
   642     return pointers
   650     return pointers
   643         
   651