def send_changes_to_module(self, timeout: float = None): """ Takes the collection of changes made using the write command and sends them all to the hardware collectively. """ try: if self._changes is None or len(self._changes) == 0: return timeout = self.timeout if timeout is None else timeout requests.get(self._url, params=self._changes, timeout=timeout) self.flush_changes() except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout) as ex: raise WebIOConnectionError(ex)
def update_from_module(self, timeout: float = None): """Makes a hardware call to the base module to retrieve the value of all IOs, storing their results in memory.""" try: timeout = self.timeout if timeout is None else timeout vals = self._get(timeout) if vals is not None: self._io = vals self.flush_changes() except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout) as ex: raise WebIOConnectionError(ex)
def write_immediate(self, addr: str, value: object, timeout: float = None): """ Instead of waiting for a group write, writes the given value immediately. Note, this is not very efficient and should be used sparingly. """ try: timeout = self.timeout if timeout is None else timeout to_str = self._value_to_str(value) self._io[addr] = value requests.get(self._url, params={addr: to_str}, timeout=timeout) except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout) as ex: raise WebIOConnectionError(ex)
def read_immediate(self, addr: str, timeout: None) -> object: """Makes a hardware call to the base module to retrieve the value of the IO. This is inefficient and should be used sparingly.""" try: self._check_for_address(addr) timeout = self.timeout if timeout is None else timeout vals = self._get(timeout=timeout) if vals is None: return None return vals.get(addr) except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout) as ex: raise WebIOConnectionError(ex)
def write_immediate(self, addr: Union[str, List[str]], value: Union[object, List[object]], timeout: float = None): """ Instead of waiting for a group write, writes the given value immediately. Note, this is not very efficient and should be used sparingly. """ if isinstance(addr, list): if isinstance(value, list): items = {addr: self._value_to_str(val) for addr, val in zip(addr, value)} else: value = self._value_to_str(value) items = {addr: value for addr in addr} else: items = {addr: self._value_to_str(value)} try: timeout = self.timeout if timeout is None else timeout with lock: self._req.get(self._url, params=items, timeout=timeout) for addr, value in items.items(): self._io[addr] = value except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout) as ex: raise WebIOConnectionError(ex)