deviceStartComm being called twice when adding device

Posted on
Thu Mar 10, 2016 3:59 pm
zurich offline
Posts: 103
Joined: Aug 11, 2014

deviceStartComm being called twice when adding device

Greetings,

The following code is part of my deviceStartComm, by adding the "dev.replacePluginPropsOnServer(newProps)", deviceStartComm runs twice meaning it adds, removes, then adds the device again. I know this is due to the "dev.replacePluginPropsOnServer(newProps)" because if I remove the code it only adds the device once normally. Is there a way to add the port number to the "address" column on the ui without causing this problem?

Code: Select all
def deviceStart(self, dev):
      
      self.plugin.debugLog(u"deviceStart called.  Adding device %s." % dev.name)

      if dev.deviceTypeId == "xUSBserver":
         dev.updateStateOnServer("onOffState", value=True, uiValue="on")

         #get the xUSBserver port number
         self.getPort(dev)

         # writes the xUSBserver port number to the address column for the kUSBserver
         newProps = dev.pluginProps
         newProps['address'] = self.port
         dev.replacePluginPropsOnServer(newProps)
         
         if dev.deviceTypeId not in self.serverList:
            self.serverList.append(dev.deviceTypeId)


kind regards,

Z

Posted on
Thu Mar 10, 2016 5:57 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: deviceStartComm being called twice when adding device

Look at the didDeviceCommPropertyChange method in the plugin.py docs. That method is called by the server every time a device's props are changed so it will know whether to call deviceStopComm/deviceStartComm. Override that method to only return True when connection related properties change (that would require the device to be stopped the restarted).

The default implementation is to return true if any properties are changed - but clearly you don't want that behavior.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: brettlid and 7 guests

cron