objdictgen/node.py
changeset 299 506f9700b9fb
parent 284 24bf3d692993
child 304 32d93e0c6e64
equal deleted inserted replaced
298:dba062c5c3c1 299:506f9700b9fb
   143                 [{"name" : "Emergency COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]},
   143                 [{"name" : "Emergency COB ID", "type" : 0x07, "access" : 'rw', "pdo" : False}]},
   144     0x1015 : {"name" : "Inhibit Time Emergency", "struct" : var, "need" : False, "values" :
   144     0x1015 : {"name" : "Inhibit Time Emergency", "struct" : var, "need" : False, "values" :
   145                 [{"name" : "Inhibit Time Emergency", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
   145                 [{"name" : "Inhibit Time Emergency", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
   146     0x1016 : {"name" : "Consumer Heartbeat Time", "struct" : rec, "need" : False, "values" :
   146     0x1016 : {"name" : "Consumer Heartbeat Time", "struct" : rec, "need" : False, "values" :
   147                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
   147                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
   148                  {"name" : "Consumer Heartbeat Time", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7F}]},
   148                  {"name" : "Consumer Heartbeat Time", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmin" : 1, "nbmax" : 0x7F}]},
   149     0x1017 : {"name" : "Producer Heartbeat Time", "struct" : var, "need" : False, "callback" : True, "values" :
   149     0x1017 : {"name" : "Producer Heartbeat Time", "struct" : var, "need" : False, "callback" : True, "values" :
   150                 [{"name" : "Producer Heartbeat Time", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
   150                 [{"name" : "Producer Heartbeat Time", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
   151     0x1018 : {"name" : "Identity", "struct" : array, "need" : True, "values" :
   151     0x1018 : {"name" : "Identity", "struct" : array, "need" : True, "values" :
   152                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
   152                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
   153                  {"name" : "Vendor ID", "type" : 0x07, "access" : 'ro', "pdo" : False},
   153                  {"name" : "Vendor ID", "type" : 0x07, "access" : 'ro', "pdo" : False},
   179                  {"name" : "StdIn", "type" : 0x05, "access" : 'wo', "pdo" : True},
   179                  {"name" : "StdIn", "type" : 0x05, "access" : 'wo', "pdo" : True},
   180                  {"name" : "StdOut", "type" : 0x05, "access" : 'ro', "pdo" : True},
   180                  {"name" : "StdOut", "type" : 0x05, "access" : 'ro', "pdo" : True},
   181                  {"name" : "StdErr", "type" : 0x05, "access" : 'ro', "pdo" : True}]},
   181                  {"name" : "StdErr", "type" : 0x05, "access" : 'ro', "pdo" : True}]},
   182     0x1027 : {"name" : "Module List", "struct" : rec, "need" : False, "values" :
   182     0x1027 : {"name" : "Module List", "struct" : rec, "need" : False, "values" :
   183                 [{"name" : "Number of Connected Modules", "type" : 0x05, "access" : 'ro', "pdo" : False},
   183                 [{"name" : "Number of Connected Modules", "type" : 0x05, "access" : 'ro', "pdo" : False},
   184                  {"name" : "Module %d[(sub)]", "type" : 0x06, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]},
   184                  {"name" : "Module %d[(sub)]", "type" : 0x06, "access" : 'ro', "pdo" : False, "nbmin" : 1, "nbmax" : 0xFE}]},
   185     0x1028 : {"name" : "Emergency Consumer", "struct" : rec, "need" : False, "values" :
   185     0x1028 : {"name" : "Emergency Consumer", "struct" : rec, "need" : False, "values" :
   186                 [{"name" : "Number of Consumed Emergency Objects", "type" : 0x05, "access" : 'ro', "pdo" : False},
   186                 [{"name" : "Number of Consumed Emergency Objects", "type" : 0x05, "access" : 'ro', "pdo" : False},
   187                  {"name" : "Emergency Consumer", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x7E}]},
   187                  {"name" : "Emergency Consumer", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmin" : 1, "nbmax" : 0x7E}]},
   188     0x1029 : {"name" : "Error Behavior", "struct" : array, "need" : False, "values" :
   188     0x1029 : {"name" : "Error Behavior", "struct" : array, "need" : False, "values" :
   189                 [{"name" : "Number of Error Classes", "type" : 0x05, "access" : 'ro', "pdo" : False},
   189                 [{"name" : "Number of Error Classes", "type" : 0x05, "access" : 'ro', "pdo" : False},
   190                  {"name" : "Communication Error", "type" : 0x05, "access" : 'rw', "pdo" : False},
   190                  {"name" : "Communication Error", "type" : 0x05, "access" : 'rw', "pdo" : False},
   191                  {"name" : "Device Profile", "type" : 0x05, "access" : 'rw', "pdo" : False, "nbmax" : 0xFE}]},
   191                  {"name" : "Device Profile", "type" : 0x05, "access" : 'rw', "pdo" : False, "nbmax" : 0xFE}]},
   192     0x1200 : {"name" : "Server SDO Parameter", "struct" : array, "need" : False, "values" :
   192     0x1200 : {"name" : "Server SDO Parameter", "struct" : array, "need" : False, "values" :
   193                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
   193                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
   194                  {"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False},
   194                  {"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False, "default" : "\"$NODEID+0x600\""},
   195                  {"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False}]},
   195                  {"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False, "default" : "\"$NODEID+0x580\""}]},
   196     0x1201 : {"name" : "Additional Server SDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x7F, "need" : False, "values" :
   196     0x1201 : {"name" : "Additional Server SDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x7F, "need" : False, "values" :
   197                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
   197                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'ro', "pdo" : False},
   198                  {"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False},
   198                  {"name" : "COB ID Client to Server (Receive SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False},
   199                  {"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False},
   199                  {"name" : "COB ID Server to Client (Transmit SDO)", "type" : 0x07, "access" : 'ro', "pdo" : False},
   200                  {"name" : "Node ID of the SDO Client", "type" : 0x05, "access" : 'ro', "pdo" : False}]},
   200                  {"name" : "Node ID of the SDO Client", "type" : 0x05, "access" : 'ro', "pdo" : False}]},
   203                  {"name" : "COB ID Client to Server (Transmit SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False},
   203                  {"name" : "COB ID Client to Server (Transmit SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False},
   204                  {"name" : "COB ID Server to Client (Receive SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False},
   204                  {"name" : "COB ID Server to Client (Receive SDO)", "type" : 0x07, "access" : 'rw', "pdo" : False},
   205                  {"name" : "Node ID of the SDO Server", "type" : 0x05, "access" : 'rw', "pdo" : False}]},
   205                  {"name" : "Node ID of the SDO Server", "type" : 0x05, "access" : 'rw', "pdo" : False}]},
   206     0x1400 : {"name" : "Receive PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
   206     0x1400 : {"name" : "Receive PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
   207                 [{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False},
   207                 [{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False},
   208                  {"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:self.ID+(base+2)*0x100,False:0}[base<4]"},
   208                  {"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:\"$NODEID+0x%X00\"%(base+2),False:0}[base<4]"},
   209                  {"name" : "Transmission Type", "type" : 0x05, "access" : 'rw', "pdo" : False},
   209                  {"name" : "Transmission Type", "type" : 0x05, "access" : 'rw', "pdo" : False},
   210                  {"name" : "Inhibit Time", "type" : 0x06, "access" : 'rw', "pdo" : False},
   210                  {"name" : "Inhibit Time", "type" : 0x06, "access" : 'rw', "pdo" : False},
   211                  {"name" : "Compatibility Entry", "type" : 0x05, "access" : 'rw', "pdo" : False},
   211                  {"name" : "Compatibility Entry", "type" : 0x05, "access" : 'rw', "pdo" : False},
   212                  {"name" : "Event Timer", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
   212                  {"name" : "Event Timer", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
   213     0x1600 : {"name" : "Receive PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
   213     0x1600 : {"name" : "Receive PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
   214                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'rw', "pdo" : False},
   214                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'rw', "pdo" : False},
   215                  {"name" : "PDO %d Mapping for an application object %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x40}]},
   215                  {"name" : "PDO %d Mapping for an application object %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmin" : 0, "nbmax" : 0x40}]},
   216     0x1800 : {"name" : "Transmit PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "callback" : True, "values" :
   216     0x1800 : {"name" : "Transmit PDO %d Parameter[(idx)]", "struct" : pluriarray, "incr" : 1, "nbmax" : 0x200, "need" : False, "callback" : True, "values" :
   217                 [{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False},
   217                 [{"name" : "Highest SubIndex Supported", "type" : 0x05, "access" : 'ro', "pdo" : False},
   218                  {"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:self.ID+(base+1)*0x100+0x80,False:0}[base<4]"},
   218                  {"name" : "COB ID used by PDO", "type" : 0x07, "access" : 'rw', "pdo" : False, "default" : "{True:\"$NODEID+0x%X80\"%(base+1),False:0}[base<4]"},
   219                  {"name" : "Transmission Type", "type" : 0x05, "access" : 'rw', "pdo" : False},
   219                  {"name" : "Transmission Type", "type" : 0x05, "access" : 'rw', "pdo" : False},
   220                  {"name" : "Inhibit Time", "type" : 0x06, "access" : 'rw', "pdo" : False},
   220                  {"name" : "Inhibit Time", "type" : 0x06, "access" : 'rw', "pdo" : False},
   221                  {"name" : "Compatibility Entry", "type" : 0x05, "access" : 'rw', "pdo" : False},
   221                  {"name" : "Compatibility Entry", "type" : 0x05, "access" : 'rw', "pdo" : False},
   222                  {"name" : "Event Timer", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
   222                  {"name" : "Event Timer", "type" : 0x06, "access" : 'rw', "pdo" : False}]},
   223     0x1A00 : {"name" : "Transmit PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
   223     0x1A00 : {"name" : "Transmit PDO %d Mapping[(idx)]", "struct" : plurirec, "incr" : 1, "nbmax" : 0x200, "need" : False, "values" :
   224                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'rw', "pdo" : False},
   224                 [{"name" : "Number of Entries", "type" : 0x05, "access" : 'rw', "pdo" : False},
   225                  {"name" : "PDO %d Mapping for a process data variable %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmax" : 0x40}]},
   225                  {"name" : "PDO %d Mapping for a process data variable %d[(idx,sub)]", "type" : 0x07, "access" : 'rw', "pdo" : False, "nbmin" : 0, "nbmax" : 0x40}]},
   226 }
   226 }
   227 
   227 
   228 #-------------------------------------------------------------------------------
   228 #-------------------------------------------------------------------------------
   229 #                         Search in a Mapping Dictionary
   229 #                         Search in a Mapping Dictionary
   230 #-------------------------------------------------------------------------------
   230 #-------------------------------------------------------------------------------
   528                 self.Dictionary[index] = value
   528                 self.Dictionary[index] = value
   529                 return True
   529                 return True
   530             elif subIndex == 1:
   530             elif subIndex == 1:
   531                 self.Dictionary[index] = [value]
   531                 self.Dictionary[index] = [value]
   532                 return True
   532                 return True
   533         elif subIndex > 1 and type(self.Dictionary[index]) == ListType and subIndex == len(self.Dictionary[index]) + 1:
   533         elif subIndex > 0 and type(self.Dictionary[index]) == ListType and subIndex == len(self.Dictionary[index]) + 1:
   534             self.Dictionary[index].append(value)
   534             self.Dictionary[index].append(value)
   535             return True
   535             return True
   536         return False
   536         return False
   537 
   537 
   538     """
   538     """
   614     
   614     
   615     """
   615     """
   616     Returns the value of the entry asked. If the entry has the value "count", it
   616     Returns the value of the entry asked. If the entry has the value "count", it
   617     returns the number of subIndex in the entry except the first.
   617     returns the number of subIndex in the entry except the first.
   618     """
   618     """
   619     def GetEntry(self, index, subIndex = None):
   619     def GetEntry(self, index, subIndex = None, compute = True):
   620         if index in self.Dictionary:
   620         if index in self.Dictionary:
   621             if subIndex == None:
   621             if subIndex == None:
   622                 if type(self.Dictionary[index]) == ListType:
   622                 if type(self.Dictionary[index]) == ListType:
   623                     values = [len(self.Dictionary[index])]
   623                     values = [len(self.Dictionary[index])]
   624                     for value in self.Dictionary[index]:
   624                     for value in self.Dictionary[index]:
   625                         values.append(self.CompileValue(value, index))
   625                         values.append(self.CompileValue(value, index, compute))
   626                     return values
   626                     return values
   627                 else:
   627                 else:
   628                     return self.CompileValue(self.Dictionary[index], index)
   628                     return self.CompileValue(self.Dictionary[index], index, compute)
   629             elif subIndex == 0:
   629             elif subIndex == 0:
   630                 if type(self.Dictionary[index]) == ListType:
   630                 if type(self.Dictionary[index]) == ListType:
   631                     return len(self.Dictionary[index])
   631                     return len(self.Dictionary[index])
   632                 else:
   632                 else:
   633                     return self.CompileValue(self.Dictionary[index], index)
   633                     return self.CompileValue(self.Dictionary[index], index, compute)
   634             elif type(self.Dictionary[index]) == ListType and 0 < subIndex <= len(self.Dictionary[index]):
   634             elif type(self.Dictionary[index]) == ListType and 0 < subIndex <= len(self.Dictionary[index]):
   635                 return self.CompileValue(self.Dictionary[index][subIndex - 1], index)
   635                 return self.CompileValue(self.Dictionary[index][subIndex - 1], index, compute)
   636         return None
   636         return None
   637 
   637 
   638     """
   638     """
   639     Returns the value of the entry asked. If the entry has the value "count", it
   639     Returns the value of the entry asked. If the entry has the value "count", it
   640     returns the number of subIndex in the entry except the first.
   640     returns the number of subIndex in the entry except the first.
   765     def RemoveMapVariable(self, index, subIndex = None):
   765     def RemoveMapVariable(self, index, subIndex = None):
   766         model = index << 16
   766         model = index << 16
   767         mask = 0xFFFF << 16
   767         mask = 0xFFFF << 16
   768         if subIndex:
   768         if subIndex:
   769             model += subIndex << 8
   769             model += subIndex << 8
   770             mask = 0xFF << 8
   770             mask += 0xFF << 8
   771         for i in self.Dictionary.iterkeys():
   771         for i in self.Dictionary.iterkeys():
   772             if 0x1600 <= i <= 0x17FF or 0x1A00 <= i <= 0x1BFF:
   772             if 0x1600 <= i <= 0x17FF or 0x1A00 <= i <= 0x1BFF:
   773                 for j,value in enumerate(self.Dictionary[i]):
   773                 for j,value in enumerate(self.Dictionary[i]):
   774                     if (value & mask) == model:
   774                     if (value & mask) == model:
   775                         self.Dictionary[i][j] = 0
   775                         self.Dictionary[i][j] = 0
   855                 if isinstance(values, IntType):
   855                 if isinstance(values, IntType):
   856                     values = "%X"%values
   856                     values = "%X"%values
   857                 result += "%04X (%s): %s\n"%(index, name, values)
   857                 result += "%04X (%s): %s\n"%(index, name, values)
   858         return result
   858         return result
   859             
   859             
   860     def CompileValue(self, value, index):
   860     def CompileValue(self, value, index, compute = True):
   861         if type(value) == StringType and value.find("self.ID") != -1:
   861         if type(value) == StringType:
   862             base = self.GetBaseIndex(index)
   862             base = self.GetBaseIndex(index)
   863             try:
   863             try:
   864                 return eval(value)
   864                 raw = eval(value)
       
   865                 if compute:
       
   866                     return eval(raw.replace("$NODEID","self.ID"))
       
   867                 return raw
   865             except:
   868             except:
   866                 return 0
   869                 return 0
   867         else:
   870         else:
   868             return value
   871             return value
   869 
   872