plugger.py
changeset 683 57aa9da845d5
parent 677 607731b33026
child 686 e4e1da75d411
equal deleted inserted replaced
682:9d20df7c144a 683:57aa9da845d5
   464         # warn user he has two left hands
   464         # warn user he has two left hands
   465         if DesiredName != res:
   465         if DesiredName != res:
   466             self.GetPlugRoot().logger.write_warning(_("A child names \"%s\" already exist -> \"%s\"\n")%(DesiredName,res))
   466             self.GetPlugRoot().logger.write_warning(_("A child names \"%s\" already exist -> \"%s\"\n")%(DesiredName,res))
   467         return res
   467         return res
   468 
   468 
       
   469     def GetAllChannels(self):
       
   470         AllChannels=[]
       
   471         for PlugInstance in self.PlugParent.IterChilds():
       
   472             if PlugInstance != self:
       
   473                 AllChannels.append(PlugInstance.BaseParams.getIEC_Channel())
       
   474         AllChannels.sort()
       
   475         return AllChannels
       
   476 
   469     def FindNewIEC_Channel(self, DesiredChannel):
   477     def FindNewIEC_Channel(self, DesiredChannel):
   470         """
   478         """
   471         Changes IEC Channel number to DesiredChannel if available, nearest available if not.
   479         Changes IEC Channel number to DesiredChannel if available, nearest available if not.
   472         @param DesiredChannel: The desired IEC channel (int)
   480         @param DesiredChannel: The desired IEC channel (int)
   473         """
   481         """
   474         # Get Current IEC channel
   482         # Get Current IEC channel
   475         CurrentChannel = self.BaseParams.getIEC_Channel()
   483         CurrentChannel = self.BaseParams.getIEC_Channel()
   476         # Do nothing if no change
   484         # Do nothing if no change
   477         #if CurrentChannel == DesiredChannel: return CurrentChannel
   485         #if CurrentChannel == DesiredChannel: return CurrentChannel
   478         # Build a list of used Channels out of parent's PluggedChilds
   486         # Build a list of used Channels out of parent's PluggedChilds
   479         AllChannels=[]
   487         AllChannels = self.GetAllChannels()
   480         for PlugInstance in self.PlugParent.IterChilds():
   488         
   481             if PlugInstance != self:
       
   482                 AllChannels.append(PlugInstance.BaseParams.getIEC_Channel())
       
   483         AllChannels.sort()
       
   484 
       
   485         # Now, try to guess the nearest available channel
   489         # Now, try to guess the nearest available channel
   486         res = DesiredChannel
   490         res = DesiredChannel
   487         while res in AllChannels: # While channel not free
   491         while res in AllChannels: # While channel not free
   488             if res < CurrentChannel: # Want to go down ?
   492             if res < CurrentChannel: # Want to go down ?
   489                 res -=  1 # Test for n-1
   493                 res -=  1 # Test for n-1