platypush/plugins/serial/__init__.py
def write(self, data, device=None, baud_rate=None):
        """
        Writes data to the serial device.

        :param device: Device to write (default: default configured device)
        :type device: str

        :param baud_rate: Baud rate (default: default configured baud_rate)
        :type baud_rate: int

        :param data: Data to send to the serial device
        :type data: str, bytes or dict. If dict, it will be serialized as JSON.
        """

        if not device:
            if not self.device:
                raise RuntimeError('No device specified nor default device configured')
            device = self.device

        if baud_rate is None:
            if self.baud_rate is None:
                raise RuntimeError('No baud_rate specified nor default configured')
            baud_rate = self.baud_rate

        if isinstance(data, dict):
            data = json.dumps(data)
        if isinstance(data, str):
            data = data.encode('utf-8')

        try:
            serial_available = self.serial_lock.acquire(timeout=2)
            if serial_available:
                try:
                    ser = self._get_serial(device=device, baud_rate=baud_rate)
                except Exception as e:
                    self.logger.debug(e)
                    time.sleep(1)
                    ser = self._get_serial(device=device, baud_rate=baud_rate, reset=True)

                self.logger.info('Writing {} to {}'.format(data, self.device))
                ser.write(data)
        finally:
            try:
                self.serial_lock.release()
            except Exception as e:
                self.logger.debug(e)

        Writes data to the serial device.

        :param device: Device to write (default: default configured device)
        :type device: str

        :param baud_rate: Baud rate (default: default configured baud_rate)
        :type baud_rate: int

        :param data: Data to send to the serial device
        :type data: str, bytes or dict. If dict, it will be serialized as JSON.
        
Writes data to the serial device.
Writes data to the serial device .
def write(self, data, device=None, baud_rate=None):
        if not device:
            if not self.device:
                raise RuntimeError('No device specified nor default device configured')
            device = self.device
        if baud_rate is None:
            if self.baud_rate is None:
                raise RuntimeError('No baud_rate specified nor default configured')
            baud_rate = self.baud_rate
        if isinstance(data, dict):
            data = json.dumps(data)
        if isinstance(data, str):
            data = data.encode('utf-8')
        try:
            serial_available = self.serial_lock.acquire(timeout=2)
            if serial_available:
                try:
                    ser = self._get_serial(device=device, baud_rate=baud_rate)
                except Exception as e:
                    self.logger.debug(e)
                    time.sleep(1)
                    ser = self._get_serial(device=device, baud_rate=baud_rate, reset=True)
                self.logger.info('Writing {} to {}'.format(data, self.device))
                ser.write(data)
        finally:
            try:
                self.serial_lock.release()
            except Exception as e:
                self.logger.debug(e)
def write ( self , data , device = None , baud_rate = None ) : if not device : if not self . device : raise RuntimeError ( 'No device specified nor default device configured' ) device = self . device if baud_rate is None : if self . baud_rate is None : raise RuntimeError ( 'No baud_rate specified nor default configured' ) baud_rate = self . baud_rate if isinstance ( data , dict ) : data = json . dumps ( data ) if isinstance ( data , str ) : data = data . encode ( 'utf-8' ) try : serial_available = self . serial_lock . acquire ( timeout = 2 ) if serial_available : try : ser = self . _get_serial ( device = device , baud_rate = baud_rate ) except Exception as e : self . logger . debug ( e ) time . sleep ( 1 ) ser = self . _get_serial ( device = device , baud_rate = baud_rate , reset = True ) self . logger . info ( 'Writing {} to {}' . format ( data , self . device ) ) ser . write ( data ) finally : try : self . serial_lock . release ( ) except Exception as e : self . logger . debug ( e )
Writes data to the serial device.
Writes data to the serial device .
"""
        Writes data to the serial device.

        :param device: Device to write (default: default configured device)
        :type device: str

        :param baud_rate: Baud rate (default: default configured baud_rate)
        :type baud_rate: int

        :param data: Data to send to the serial device
        :type data: str, bytes or dict. If dict, it will be serialized as JSON.
        """
self
data
Data to send to the serial device
Data to send to the serial device
device
Device to write (default: default configured device)
Device to write ( default : default configured device )
baud_rate
Baud rate (default: default configured baud_rate)
Baud rate ( default : default configured baud_rate )