Serial port access functions from plugin

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
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
donhoffman
Posts: 51
Joined: Thu May 26, 2011 5:25 pm
Location: Portland, OR and Livingston, MT

Serial port access functions from plugin

Post by donhoffman »

I have been going over the EasyDAQ code in preparation for my own plugin work. Still learning how to do serial port stuff in python, OS X and Indigo, so apologize if these are basic questions or I have missed something obvious.

I see some serial-related stuff that doesn't show up in the documentation as far as I can tell, but that appears to be built in to the plugin infrastructure:

In Devices.xml there is a "class" attribute of the <List/> element with value "indigo.serialPorts" that appears to provide for a menu of serial ports. This appears to construct a menu in the device config UI consisting of the partial names of all the serial devices on the machine modulo a filter spec (minus the "/dev/tty." full port name prefix). Assume it is ok to use this element in my own <ConfigUI/>? Are there any other useful filters in addition to the Bluetooth one? Does the full port name (with "/dev/tty." prefix) get saved in the device properties if I use this? I assume the "/dev/tty." is left out of the UI for readability?

In EasyDAQ, the serial device is actually opened with a call to self.plugin.openSerial(). I assume this is inherited from indigo.PluginBase? How does this relate to the PySerial stuff? Is the object returned an initialized serial.Serial object that follows the PySerial interface, including all the methods supported by a serial.Serial object and any associated exceptions?

Finally, can I assume that these functions are used for convenience only and I can just directly use PySerial instead if I wish? I would like to support use of RFC2217 remote serial access where I would offer the user the option of using a URL for the serial port identifier rather than a local device name and will probably use serial.serial_for_url() to open the ports in that case.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Serial port access functions from plugin

Post by jay (support) »

donhoffman wrote:In Devices.xml there is a "class" attribute of the <List/> element with value "indigo.serialPorts" that appears to provide for a menu of serial ports. This appears to construct a menu in the device config UI consisting of the partial names of all the serial devices on the machine modulo a filter spec (minus the "/dev/tty." full port name prefix). Assume it is ok to use this element in my own <ConfigUI/>? Are there any other useful filters in addition to the Bluetooth one? Does the full port name (with "/dev/tty." prefix) get saved in the device properties if I use this? I assume the "/dev/tty." is left out of the UI for readability?
Correct - must have missed adding that one but it's there now.
donhoffman wrote:In EasyDAQ, the serial device is actually opened with a call to self.plugin.openSerial(). I assume this is inherited from indigo.PluginBase? How does this relate to the PySerial stuff? Is the object returned an initialized serial.Serial object that follows the PySerial interface, including all the methods supported by a serial.Serial object and any associated exceptions?
It simply calls through to PySerial and returns a serial.Serial object - it's got some nice error logging into the event log. It won't raise any exceptions but will just return None if the serial.Serial object couldn't be created.
donhoffman wrote:Finally, can I assume that these functions are used for convenience only and I can just directly use PySerial instead if I wish? I would like to support use of RFC2217 remote serial access where I would offer the user the option of using a URL for the serial port identifier rather than a local device name and will probably use serial.serial_for_url() to open the ports in that case.
Sure, no problem at all.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Serial port access functions from plugin

Post by matt (support) »

Note you can see the base class implementation of plugin here:

Code: Select all

/Library/Application Support/Perceptive Automation/Indigo 5/IndigoPluginHost.app/Contents/PlugIns/plugin_base.py
You'll see that openSerial() as Jay mentioned just calls through to pySerial but handles the common error cases with plugin-friendly error logging. Note you can see some of the internals of how the plugin host parses XML along with some internal methods in there. Methods that aren't documented in the dev docs are not guaranteed to change name/argument signature/etc., but if you need access to an unpublished API then let us know and we can look at formalizing it.

Please let me know how the pySerial's RFC2217 / serial_for_url() works for you. I haven't tried it yet, but if it works then it will probably make sense to either extend the plugin's openSerial() method to handle it or add a new API for the plugin to open from the URL.

It might also make since to provide an option in the config UI XML for a control that lists both local serial ports and has an option for the user to enter an URL, but that likely won't happen in the v5 time frame.
Image
asw24b
Posts: 222
Joined: Sun Dec 30, 2007 7:45 pm
Location: Los Altos Hills, CA

Re: Serial port access functions from plugin

Post by asw24b »

support wrote:Note you can see the base class implementation of plugin here:

Code: Select all

/Library/Application Support/Perceptive Automation/Indigo 5/IndigoPluginHost.app/Contents/PlugIns/plugin_base.py
You'll see that openSerial() as Jay mentioned just calls through to pySerial but handles the common error cases with plugin-friendly error logging. Note you can see some of the internals of how the plugin host parses XML along with some internal methods in there. Methods that aren't documented in the dev docs are not guaranteed to change name/argument signature/etc., but if you need access to an unpublished API then let us know and we can look at formalizing it.

Please let me know how the pySerial's RFC2217 / serial_for_url() works for you. I haven't tried it yet, but if it works then it will probably make sense to either extend the plugin's openSerial() method to handle it or add a new API for the plugin to open from the URL.

It might also make since to provide an option in the config UI XML for a control that lists both local serial ports and has an option for the user to enter an URL, but that likely won't happen in the v5 time frame.

Matt,

Is pySerial included in 10.x by default, or do you guys embed a copy inside of Indigo ?

Mike
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Serial port access functions from plugin

Post by matt (support) »

We embed it inside the IndigoPluginHost. I believe you'll see it directly next to the plugin_base.py file mentioned above.
Image
Locked

Return to “Extending Indigo with Plugins and Python”