nad_receiver/__init__.py
def exec_command(self, domain, function, operator, value=None):
        """
        Write a command to the receiver and read the value it returns.

        The receiver will always return a value, also when setting a value.
        """
        if operator in CMDS[domain][function]['supported_operators']:
            if operator is '=' and value is None:
                raise ValueError('No value provided')

            if value is None:
                cmd = ''.join([CMDS[domain][function]['cmd'], operator])
            else:
                cmd = ''.join(
                    [CMDS[domain][function]['cmd'], operator, str(value)])
        else:
            raise ValueError('Invalid operator provided %s' % operator)

        if not self.ser.is_open:
            self.ser.open()

        try:
            self.lock.acquire()

            self.ser.write(''.join(['\r', cmd, '\r']).encode('utf-8'))
            time.sleep(0.1)
            # not sure why, but otherwise it is not ready yet to do the read.

            msg = self.ser.read(self.ser.in_waiting)
            
            try:
                msg = msg.decode()[1:-1]
                msg = msg.split('=')[1]
                return msg
            except IndexError:
                pass

        finally:
            self.lock.release()
def exec_command(self, domain, function, operator, value=None):
        """
        Write a command to the receiver and read the value it returns.

        The receiver will always return a value, also when setting a value.
        """
        if operator in CMDS[domain][function]['supported_operators']:
            if operator is '=' and value is None:
                raise ValueError('No value provided')

            if value is None:
                cmd = ''.join([CMDS[domain][function]['cmd'], operator])
            else:
                cmd = ''.join(
                    [CMDS[domain][function]['cmd'], operator, str(value)])
        else:
            raise ValueError('Invalid operator provided %s' % operator)

        if not self.ser.is_open:
            self.ser.open()

        try:
            self.lock.acquire()

            self.ser.write(''.join(['\r', cmd, '\r']).encode('utf-8'))
            time.sleep(0.1)
            # not sure why, but otherwise it is not ready yet to do the read.

            msg = self.ser.read(self.ser.in_waiting)
            
            try:
                msg = msg.decode()[1:-1]
                msg = msg.split('=')[1]
                return msg
            except IndexError:
                pass

        finally:
            self.lock.release()
def exec_command ( self , domain , function , operator , value = None ) : if operator in CMDS [ domain ] [ function ] [ 'supported_operators' ] : if operator is '=' and value is None : raise ValueError ( 'No value provided' ) if value is None : cmd = '' . join ( [ CMDS [ domain ] [ function ] [ 'cmd' ] , operator ] ) else : cmd = '' . join ( [ CMDS [ domain ] [ function ] [ 'cmd' ] , operator , str ( value ) ] ) else : raise ValueError ( 'Invalid operator provided %s' % operator ) if not self . ser . is_open : self . ser . open ( ) try : self . lock . acquire ( ) self . ser . write ( '' . join ( [ '\r' , cmd , '\r' ] ) . encode ( 'utf-8' ) ) time . sleep ( 0.1 ) # not sure why, but otherwise it is not ready yet to do the read. msg = self . ser . read ( self . ser . in_waiting ) try : msg = msg . decode ( ) [ 1 : - 1 ] msg = msg . split ( '=' ) [ 1 ] return msg except IndexError : pass finally : self . lock . release ( )
Write a command to the receiver and read the value it returns.

        The receiver will always return a value, also when setting a value.
Write a command to the receiver and read the value it returns .