basic serial interface

Questions about hardware that can be controlled by Indigo (but not through the interfaces and plugins listed). If Indigo doesn't support some bit of hardware you're interested in, and you don't find a 3rd Party Plugin for it, add it to this forum. Be sure to include links to as much information as you can find about it.

Note: adding it here does not mean we're going to add it - and in fact it's possible one of our 3rd party developers may decide to write a plugin for it.
Forum rules
Questions about hardware that can be controlled by Indigo (but not through the interfaces and plugins listed). If Indigo doesn't support some bit of hardware you're interested in, and you don't find a 3rd Party Plugin for it, add it to this forum. Be sure to include links to as much information as you can find about it.

Note: adding it here does not mean we're going to add it - in fact it's possible one of our 3rd party developers may decide to write a plugin for it. We add hardware/features based on a lot of different factors beyond just having a request for it.
User avatar
brianlloyd
Posts: 226
Joined: Sun May 26, 2013 5:46 pm
Location: San Antonio, TX, USA

basic serial interface

Post by brianlloyd »

Does a basic serial interface device exist? I need to control a device by sending strings over a serial port. Very simple and I would think that such a generic device would exist but I can't find it, either as an intrinsic Indigo device, or a plug-in.
User avatar
FlyingDiver
Posts: 7326
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: basic serial interface

Post by FlyingDiver »

I don't think anyone has done a generic serial interface plugin, but if you just need to send strings to the interface, writing a Python script to do it isn't that hard. You could use the code in one of the plugins that does serial communication (Lutron, Pentair, Concord4, Cynical, etc.)
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7326
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: basic serial interface

Post by FlyingDiver »

For example, all the serial communication in the Lutron plugin is encapsulated in this one class:

Code: Select all

########################################
class SerialGateway:
########################################

    def __init__(self, plugin, dev):
        self.logger = logging.getLogger("Plugin.SerialGateway")
        self.dev = dev
        self.plugin = plugin
        self.connected = False
        dev.updateStateOnServer(key="status", value="Disconnected")
        dev.updateStateImageOnServer(indigo.kStateImageSel.SensorOff)

        self.connSerial = None
        self.command = ''
        

    def start(self):
        self.logger.info(u"{}: Running Serial Start".format(self.dev.name))

        serialUrl = self.plugin.getSerialPortUrl(self.dev.pluginProps, u"serialPort")
        self.logger.info(u"{}: Serial Port URL is: {}".format(self.dev.name, serialUrl))

        try:
            self.connSerial = self.plugin.openSerial(u"Lutron Gateway", serialUrl, 9600, stopbits=1, timeout=2, writeTimeout=1)
            if self.connSerial is None:
                self.logger.error(u"{}: Failed to open serial port".format(self.dev.name))
                self.dev.updateStateOnServer(key="status", value="Failed")
                self.dev.updateStateImageOnServer(indigo.kStateImageSel.SensorTripped)
                return

        except Exception, e:
            self.logger.error(u"{}: Failed to open serial port".format(self.dev.name))
            self.dev.updateStateOnServer(key="status", value="Failed")
            self.dev.updateStateImageOnServer(indigo.kStateImageSel.SensorTripped)
            return

        self.connected = True
        self.dev.updateStateOnServer(key="status", value="Connected")
        self.dev.updateStateImageOnServer(indigo.kStateImageSel.SensorOn)

        # Disable main repeater terminal prompt
        self.send("#MONITORING,12,2")

        # Enable main repeater HVAC monitoring
        self.send("#MONITORING,17,1")

        # Enable main repeater monitoring param 18 (undocumented but seems to be enabled by default for ethernet connections)
        self.send("#MONITORING,18,1")

    def stop(self):
        self.logger.debug(u"Serial stop called")
        if self.connected:
            self.connSerial.close()
            self.connected = False
        self.connSerial = None  
       

    def poll(self):

        if not self.connected:
            self.start()

        try:
            s = self.connSerial.read()
        except:
            self.logger.error(u"{}: Error reading from serial port".format(self.dev.name))
            self.dev.updateStateOnServer(key="status", value="Failed")
            self.dev.updateStateImageOnServer(indigo.kStateImageSel.SensorTripped)
            self.connected = False
            return
            
        if len(s) > 0:
            
            if s == '\r':               # RadioRA 2 messages are always terminated with CRLF
                tmp = self.command
                self.command = ''
                return tmp
            else:
                self.command += s

    def send(self, cmd):
        self.logger.debug(u"Sending serial command: %s" % cmd)
        cmd = cmd + "\r"
        self.connSerial.write(str(cmd))

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
brianlloyd
Posts: 226
Joined: Sun May 26, 2013 5:46 pm
Location: San Antonio, TX, USA

Re: basic serial interface

Post by brianlloyd »

Thanks Joe. I am a bit of a dinosaur. I haven't really hacked code for about 20 years. I don't know Python. The last languages I had full facility with were PL/M and Pascal, and that was back in the '80s.. I had started to pick up C and Java but got sidetracked on other things. I have a really steep learning curve ahead and, unfortunately, I can't quite read your code.

But I really do appreciate your reply.
User avatar
FlyingDiver
Posts: 7326
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: basic serial interface

Post by FlyingDiver »

Give this a try: https://github.com/FlyingDiver/Indigo-m ... /tag/0.0.1

Create a device, specify the serial port. Create an action with the string you want to send.

It's currently fixed at 9600, 1 stop bit. I'll make that configurable next. I don't have any serial devices I can easily test with.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
brianlloyd
Posts: 226
Joined: Sun May 26, 2013 5:46 pm
Location: San Antonio, TX, USA

Re: basic serial interface

Post by brianlloyd »

Works perfectly. I am using it to control my Somfy RTS roller shades with an URTSI-II interface. Their ZRTSI Z-Wave interface is supported by Indigo but is unable to send the STOP command to the roller shades. STOP selects the "down and closed" position so it can't be used to open and close the shades. The URTSI-II is only serial (RS-232 or RS-485).

Anyway, simple and straight-forward solution. Thank you. I really appreciate it.
RobS
Posts: 2
Joined: Sun Jan 24, 2016 10:41 am

Re: basic serial interface

Post by RobS »

Any chance of making that baud rate configurable?
I have a picky device that will only work at 38.4k.
I had been using Simple Serial, but that plugin is dead with the update.
Thanks!
User avatar
FlyingDiver
Posts: 7326
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: basic serial interface

Post by FlyingDiver »

RobS wrote:Any chance of making that baud rate configurable?
I have a picky device that will only work at 38.4k.
I had been using Simple Serial, but that plugin is dead with the update.
Thanks!
Edit line 20 of the plugin.py file in the plugin wrapper and put whatever you want there.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
User avatar
FlyingDiver
Posts: 7326
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: basic serial interface

Post by FlyingDiver »

On second thought, thanks to @Dave17, here's a pre-release that allows configuration per port device:

https://github.com/FlyingDiver/Indigo-m ... g/2024.0.1
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
RobS
Posts: 2
Joined: Sun Jan 24, 2016 10:41 am

Re: basic serial interface

Post by RobS »

WooHoo! That works perfectly!
Thanks guys!!
Post Reply

Return to “Hardware Support Inquiries and Requests”