Simple Serial Plugin - just to use for debugging

Posted on
Tue Sep 27, 2011 6:38 pm
yergeyj offline
Posts: 259
Joined: Dec 29, 2004

Simple Serial Plugin - just to use for debugging

Simple Serial Plugin (0.5.0)

Version 0.5.0 available 27-Sep-2011
• Same version - since I never distributed it - but EOL bug fixed.

Version 0.7.0 available 30-Sep-2011
• Added configuration of serial port (baud rate, parity, data bits and stop bits) with help from DomoPat

Version 0.9.0 available 13-Oct-2011
• Added support for multiple serial port connections, via use of python threads and queues.

Version 0.9.1 available 27-Nov-2011
• Added support for sending decimal or hexadecimal strings to serial port with new Actions. Note that previous Action has been renamed from "directSerial" to "textToSerial" to allow easy differentiation from decimal and hex versions of the actions. PLEASE SEND ANOTHER PM, with your e-mail if you want the latest version.

Version 0.9.2 available 28-Nov-2011
• Fixed bugs with version 0.9.1 with sending decimal/hexadecimal strings.

Version 0.9.3 available 19-Dec-2011
• Added states, which display the most recent response, in text, decimal and hexadecimal notation.

Version 0.9.4 available 16-Feb-2013
• Modified decimal and hexadecimal decoding to catch and exit when values greater than 127 or 7F, respectively, are included, as current code uses character strings extensively, which cannot accommodate the extended Ascii characters. [Extended ASCII supported as of version 0.9.5 :wink: ]

Version 0.9.5 available 13-Feb-2015
• The decimal I/O option has been removed to simplify the plugin programming, as I don’t think anyone was using it anyway.
• The EOL set-up now includes “none” as an end-of-line option for commands. This allows use with a device that does not require an EOL, or allows the EOL to be specified for each command if the user so chooses.
• The device setup for the plugin has a new option, to specify “Format for I/O commands." The options are Text (only Standard ASCII character set allowed) and Hexadecimal (Extended ASCII characters from 0x00 through 0xFF allowed).
• IMPORTANT NOTE: Although communications to-from a device allows the use of the Extended ASCII character set, communications to-from the user and the Indigo log still require using the standard ASCII character set, therefore, hexadecimal commands from Actions, etc. are still specified using the format “23, 50, 55, 4D, 50, 3F, 00, FF” but can include characters beyond 7F.
• Feedback to the Indigo log, and the states (lastResponseHex and lastResponseText) are now tied to the specified I/O format type, i.e. text logging for text commands/responses/state, and hexadecimal logging (in 0x00, 0xFF, … format) for hexadecimal commands/responses/state.


This plugin is intended as a simple plugin to test a serial connection that communicates with text commands.
(If you are interested in having the plugin, please send me a PM with your e-mail address noted, and I will send you a copy of the plugin.)

Notes:

• Assumes a Serial Adaptor is connected to the Indigo server, typically using a USB-serial adaptor such as the Keyspan USA-19HS USB Serial Adapter
• To install this (or any new) plugin, place the .plugin file into the Indigo 5 > Plugins (Disabled) folder, then restart the server.


Configuration:

Create a New Device

Type: Plugin
Plugin: Simple Serial Plugin
Model: Simple Serial Connection

Edit Device Settings

Serial port: Select your serial port connected to the your Serial Adaptor (e.g. USA19H47P1.1)
Baud rate: 300-57600 (Default=9600)
Parity: None, Odd, Even (Default=None)
Data bits: 7, 8 (Default=8)
Stop bits: 1, 2 (Default=1)
End-of-line for commands: Choose <CR>, <CR><LF>, <LF>or "none" to end commands
Format for I/O commands: Choose "Text" or "Hexadecimal"

Devices States:

lastResponseText - Most recent response, in Text notation.
lastResponseHexadecimal - Most recent response, in Hexadecimal notation.

Actions:

There is a single set of default actions:

Send direct command to serial device - used to send commands directly to the serial port / adaptor, typically for debugging. Note that there is no syntax checking. Each command as typed has the EOL character selected in Edit Device Settings appended before sending to the serial port. The two variants of the action allow for text or hexadecimal command strings, with the latter expecting comma delimited strings.

Scripting Support:

Plugin ID: org.yergeyjDoesntHaveaURL.simpleserial

Send Text Command to Serial Device

Action ID: textToSerial
Properties for scripting: newCommand (text with command content; EOL added by plugin, per serial device setup)

Example:
Code: Select all
simpleSerialId = indigo.server.getPlugin("org.yergeyjDoesntHaveaURL.simpleserial")
if simpleSerialId.isEnabled():
   simpleSerialId.executeAction("textToSerial", deviceId=1842531032, props={"newCommand":"#PUMP?"})


Send Hexadecimal Command to Serial Device

Action ID: hexToSerial
Properties for scripting: newCommand (text with command content; EOL added by plugin, per serial device setup)

Example:
Code: Select all
simpleSerialId = indigo.server.getPlugin("org.yergeyjDoesntHaveaURL.simpleserial")
if simpleSerialId.isEnabled():
   simpleSerialId.executeAction("hexToSerial", deviceId=1842531032, props={"newCommand":"23, 50, 55, 4D, 50, 3F"})




Jim Yergey - 27-Sep-2011, most recently updated 13-Feb-2015
Last edited by yergeyj on Sat Feb 16, 2013 11:30 am, edited 14 times in total.

Posted on
Tue Sep 27, 2011 7:26 pm
matt (support) offline
Site Admin
User avatar
Posts: 18068
Joined: Jan 27, 2003
Location: Texas

Re: Simple Serial Plugin - just to use for debugging

Great idea -- Jay and I were talking about doing something similar the other day.

Image

Posted on
Tue Sep 27, 2011 7:38 pm
yergeyj offline
Posts: 259
Joined: Dec 29, 2004

Re: Simple Serial Plugin - just to use for debugging

support wrote:
Great idea -- Jay and I were talking about doing something similar the other day.



Thanks Matt.

If a few people try it from here and find it helps, I'll post it in the User Contribution area.

If you'd like, I can send you a copy to see if I have anything "poorly written" in the plugin.py file; I did not include a separate device.py, given the simplicity.

Jim

Posted on
Tue Sep 27, 2011 8:08 pm
matt (support) offline
Site Admin
User avatar
Posts: 18068
Joined: Jan 27, 2003
Location: Texas

Re: Simple Serial Plugin - just to use for debugging

Hi Jim,

Sure, send it over and we'll glance through it.

Image

Posted on
Tue Sep 27, 2011 8:17 pm
Swancoat offline
Posts: 408
Joined: Nov 20, 2009
Location: Houston

Re: Simple Serial Plugin - just to use for debugging

I'm using simple serial plugin to debug my serial device. Basically, everything works fine. Just using Carriage Return.

Thanks for making this!

Code: Select all
Sep 27, 2011 9:10:50 PM
  Simple Serial Plugin Debug      <<-- entering deviceStartComm, Device: new device; ID=1273709414, Type=simpleSerialCommunicator
  Simple Serial Plugin Debug      Serial Port Name is /dev/cu.KeySerial1
  Simple Serial Plugin Debug      Device name is new device
  Simple Serial Plugin Debug      Starting concurrent serial communications.
  Simple Serial Plugin Debug      Started concurrent thread.
  Simple Serial Plugin Debug      exiting deviceStartComm -->>

Sep 27, 2011 9:11:42 PM
  Action Group                    new action group
  Simple Serial Plugin Debug      Queue has 1 command(s) waiting.
  Simple Serial Plugin Debug      Processing command: #AUX1=1
  Simple Serial Plugin Debug      Sending command:#AUX1=1
.
  Simple Serial Plugin Debug      Returned string length 13
  Simple Serial Plugin Debug      Returned string is !00 AUX1 = 1
  Simple Serial Plugin            Remaining response to decode: !00 AUX1 = 1
, of length 13 characters
  Simple Serial Plugin Debug      #AUX1=1
 command completed.

Sep 27, 2011 9:12:01 PM
  Received INSTEON                "Master Bath Main" off
  Action Group                    new action group
  Simple Serial Plugin Debug      Queue has 1 command(s) waiting.
  Simple Serial Plugin Debug      Processing command: #AUX1=0
  Simple Serial Plugin Debug      Sending command:#AUX1=0
.
  Simple Serial Plugin Debug      Returned string length 13
  Simple Serial Plugin Debug      Returned string is !00 AUX1 = 0
  Simple Serial Plugin            Remaining response to decode: !00 AUX1 = 0
, of length 13 characters
  Simple Serial Plugin Debug      #AUX1=0
 command completed.

http://nerdhome.jimdo.com

Posted on
Wed Sep 28, 2011 6:20 am
yergeyj offline
Posts: 259
Joined: Dec 29, 2004

Re: Simple Serial Plugin - just to use for debugging

Oops, as soon as I posted and started getting PM, I found an error with respect to the end-of-line character.
:oops:

Here's how that is set up in Devices.XML:

Code: Select all
            <Field type="menu" id="eolCharacter">
                <Label>End-of-line for commands:</Label>
                <List>
                    <Option value="CR">Carraige Return</Option>
                    <Option value="CRLF">Carraige Return + Line Feed</Option>
                    <Option value="LF">Line Feed</Option>
                </List>
            </Field>



And here is how that's translated into the serial command:

Code: Select all
    def directJandy(self, pluginAction):
        dev = indigo.devices[pluginAction.deviceId]
        devProps = dev.pluginProps
        command = pluginAction.props.get("newCommand")
        endOfLine = devProps.get("eolCharacter")
        if endOfLine == "CR":
            endOfLine = "\r"
        elif endOfLine == "CRLF":
            endOfLine = "\r\l"
        else:
            endOfLine = "\l"
        command = command + endOfLine
        self.queueSerialCmd(command)


For some reason, the carriage return works and is properly translated by python and sent as a <CR> however the line feed character is just sent as text "\l" ?

Any thoughts why?

Jim

Posted on
Wed Sep 28, 2011 6:33 am
matt (support) offline
Site Admin
User avatar
Posts: 18068
Joined: Jan 27, 2003
Location: Texas

Re: Simple Serial Plugin - just to use for debugging

use \n instead.

Image

Posted on
Wed Sep 28, 2011 3:02 pm
yergeyj offline
Posts: 259
Joined: Dec 29, 2004

Re: Simple Serial Plugin - just to use for debugging

support wrote:
use \n instead.



That was it - fixed and distributed to those who requested.

BTW, I tried just entering commands in the "Edit Action Settings" with a "\r" appended, but that didn't seem to work - they were sent as "command-as-typed\r" as opposed to "command-as-typed<CR>" and yet, as shown below, the plugin just appends a text string with exactly the same information??

Code: Select all
   def directJandy(self, pluginAction):
      dev = indigo.devices[pluginAction.deviceId]
      devProps = dev.pluginProps
      command = pluginAction.props.get("newCommand")
      endOfLine = devProps.get("eolCharacter")
      if endOfLine == "CR":
         endOfLine = "\r"
      elif endOfLine == "CRLF":
         endOfLine = "\r\n"
      else:
         endOfLine = "\n"
      command = command + endOfLine
      self.queueSerialCmd(command)


Any thought why it doesn't work from the dialog?

Jim

Posted on
Thu Sep 29, 2011 7:49 am
DomoPat offline
User avatar
Posts: 163
Joined: Jul 17, 2010
Location: Toulouse, France

Re: Simple Serial Plugin - just to use for debugging

Hi Jim,

received your plugin this morning and got it to talk and receive data from my Weeder boards in a few minutes. Thank you, and congratulations for a useful piece of code.

I quickly changed kSleepAfterSerialCommand to 0.1 as my device seems much quicker than yours. A few questions:
- I could not find where to adjust baud rate, parity, etc.. I have been lucky that the Weeder boards use your default setting. Where is that setting, and shouldn't it be available in the config window to make the plugin more flexible ?
- in the readSerialBuffer routine, why do you 'sleep' after reading the data in the buffer ? is there a particular reason for your device or is it a general good practice ?

Thank you,

Patrick

Posted on
Thu Sep 29, 2011 9:37 am
jay (support) offline
Site Admin
User avatar
Posts: 13353
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Simple Serial Plugin - just to use for debugging

DomoPat: nice work, are you going to build a more fully featured Weeder plugin based on this code? That would be a valuable plugin IMO.

We're including the PySerial library with Indigo, so that's what's used for the serial communication. Check out the Opening serial ports section of the docs for specifics on setting specifics.

Jim: you might want to consider allowing the user to enter baud, parity, etc. in the config dialog. Along with allowing multiple devices... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Sep 29, 2011 1:01 pm
DomoPat offline
User avatar
Posts: 163
Joined: Jul 17, 2010
Location: Toulouse, France

Re: Simple Serial Plugin - just to use for debugging

DomoPat: nice work, are you going to build a more fully featured Weeder plugin based on this code? That would be a valuable plugin IMO.


I am trying: my system uses 4 Weeder boards, so I would like them interfaced through a plugin evidently. I am not a professional programmer, just a hobbyist, but I have been able to do a small Python program to communicate with the boards, as a learning Python exercise. Now with the 'Simple Serial Plugin' I feel confident I can get something achieved. But it might take a while !

We're including the PySerial library with Indigo, so that's what's used for the serial communication. Check out the Opening serial ports section of the docs for specifics on setting specifics.


Thank you, I used it already in my exercises. I don't know how I could miss the openserial commands this morning, I now see where and how it happens.

Posted on
Thu Sep 29, 2011 7:03 pm
yergeyj offline
Posts: 259
Joined: Dec 29, 2004

Re: Simple Serial Plugin - just to use for debugging

jay wrote:
Jim: you might want to consider allowing the user to enter baud, parity, etc. in the config dialog. Along with allowing multiple devices... ;)


Working on the serial parameters - actually one of the other testers has it working and I will incorporate soon.

With regard to allowing multiple devices, I have been able to pass the serial "conn" to the concurrent thread, but still do not understand how to pass the command queue? Unlike the serial connection, the command queue has to be regularly updated, and updated separately for the different devices. It's not obvious how this is done for the EastDAQ plugin?

Jim

Posted on
Thu Sep 29, 2011 7:24 pm
hamw offline
Posts: 1057
Joined: Mar 31, 2008

Re: Simple Serial Plugin - just to use for debugging

Is this a potential replacement for Serial Bridge?

Posted on
Thu Sep 29, 2011 7:33 pm
yergeyj offline
Posts: 259
Joined: Dec 29, 2004

Re: Simple Serial Plugin - just to use for debugging

hamw wrote:
Is this a potential replacement for Serial Bridge?


Absolutely, as this plugin works directly with the serial adaptor. :-)

Also note, however, that the original AppleScripts for controlling the Jandy Aqualink were also recently updated to use SerialX, which operates with Lion.

That said, the plugin provides much better two-way communication with the pool system, as it allows COSMSGS to be turned on in the Jandy systems, which provides immediate updates to the adaptor, and therefore plugin and Indigo, of any changes to the pool/spa system that occur, including temperature changes, irrespective of which device in the system (e.g. Touch panel, Spa remote) originates the change.

If you'd like a copy to try, send me a PM with your e-mail address (per the original post for the plugin).

Jim

Posted on
Fri Sep 30, 2011 12:37 pm
dmeeker@mac.com offline
Posts: 85
Joined: Aug 26, 2011

Re: Simple Serial Plugin - just to use for debugging

Jim,

What approach would one take to modify the plugin to allow for Matt's suggestion of allowing us to customize baud, parity, etc.

Any thoughts on putting that in the config dialogue? Or any place in the scripts that could be easily edited (in the connection string)?

Who is online

Users browsing this forum: No registered users and 1 guest