basic serial interface

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.

Posted on
Wed Jun 09, 2021 7:33 pm
brianlloyd offline
User avatar
Posts: 226
Joined: May 26, 2013
Location: San Antonio, TX, USA

basic serial interface

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.

Posted on
Wed Jun 09, 2021 7:53 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: basic serial interface

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

Posted on
Wed Jun 09, 2021 7:54 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: basic serial interface

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

Posted on
Wed Jun 09, 2021 9:50 pm
brianlloyd offline
User avatar
Posts: 226
Joined: May 26, 2013
Location: San Antonio, TX, USA

Re: basic serial interface

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.

Posted on
Thu Jun 10, 2021 12:57 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: basic serial interface

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

Posted on
Thu Jun 10, 2021 2:39 pm
brianlloyd offline
User avatar
Posts: 226
Joined: May 26, 2013
Location: San Antonio, TX, USA

Re: basic serial interface

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.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests