Hello,
I'm working on a PLCBUS plug-in. Like X10, PLCBUS has an interface and devices. Orders are sent to devices through the interface via a serial conection.
If I put some code to manage a serial connection to the interface within the plugin.py, Indigo try to open a serial connection for each device created. So, what is the best way to manage this ? Add some code to check if a serial connection is already opened for another device, and finally open a connection to the interface for the first device only ? Or something else ?
Julien
Manage a serial connection with one interface and devices
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: Manage a serial connection with one interface and device
There are a bunch of different ways to handle it. I think I'd have the plugin manage the connection to the interface outside of the device specific code. So, for instance, have the plugin's config dialog ask for the serial port, etc. When the plugin starts (say, in the startup() method) you'd read the pluginPrefs, get the serial port, and open the connection.
I don't know what the API looks like to the serial interface - but one idea would be to maintain a queue of outbound messages (actions from Indigo on your devices). In your runConcurrentThread() method you could run through the queue of outgoing commands and actually send them to the interface. If the PLCBUS devices are two way, then at the same time you'd probably want to get all of the messages the interface has received since the last poll and update any device states as necessary.
But, the bottom line here is that each device wouldn't have it's own serial connection - the plugin would manage the serial connection and all the messaging. Your actions would queue up commands to the interface and any incoming state changes from the interface would update device states.
I don't know what the API looks like to the serial interface - but one idea would be to maintain a queue of outbound messages (actions from Indigo on your devices). In your runConcurrentThread() method you could run through the queue of outgoing commands and actually send them to the interface. If the PLCBUS devices are two way, then at the same time you'd probably want to get all of the messages the interface has received since the last poll and update any device states as necessary.
But, the bottom line here is that each device wouldn't have it's own serial connection - the plugin would manage the serial connection and all the messaging. Your actions would queue up commands to the interface and any incoming state changes from the interface would update device states.
Re: Manage a serial connection with one interface and device
Thanks for your help Jay.
I'm not familiar with your API yet ! But I work to well understand it ...!
I'm not familiar with your API yet ! But I work to well understand it ...!