def write_block(self, interface, command, data, check_multi_flag=True): ''' Write serial data given command, and data. ''' with node_io_rlock_obj: # only allow one greenlet at a time if interface: interface.inc_intf_write_block_count() success = False retry_count = 0 data_with_checksum = bytearray() data_with_checksum.append(command) data_with_checksum.extend(data) data_with_checksum.append(calculate_checksum(data_with_checksum[1:])) while success is False and retry_count <= MAX_RETRY_COUNT: if check_multi_flag: if self.multi_node_index >= 0: if not self.check_set_multi_node_index(interface): break try: self.serial.write(data_with_checksum) success = True except IOError as err: self.node_log(interface, 'Write Error: ' + str(err)) retry_count = retry_count + 1 if retry_count <= MAX_RETRY_COUNT: self.node_log(interface, 'Retry (IOError) in write_block: port={0} cmd={1} data={2} retry={3}'.format(self.serial.port, command, data, retry_count)) else: self.node_log(interface, 'Retry (IOError) limit reached in write_block: port={0} cmd={1} data={2} retry={3}'.format(self.serial.port, command, data, retry_count)) if interface: interface.inc_intf_write_error_count() gevent.sleep(0.025) return success
def write_block(self, interface, command, data): ''' Write serial data given command, and data. ''' interface.inc_intf_write_block_count() success = False retry_count = 0 data_with_checksum = bytearray() data_with_checksum.append(command) data_with_checksum.extend(data) data_with_checksum.append(calculate_checksum(data_with_checksum[1:])) while success is False and retry_count <= MAX_RETRY_COUNT: try: self.serial.write(data_with_checksum) success = True except IOError as err: self.node_log(interface, 'Write Error: ' + str(err)) retry_count = retry_count + 1 if retry_count <= MAX_RETRY_COUNT: self.node_log( interface, 'Retry (IOError) in write_block: port={0} cmd={1} data={2} retry={3}' .format(self.serial.port, command, data, retry_count)) else: self.node_log( interface, 'Retry (IOError) limit reached in write_block: port={0} cmd={1} data={2} retry={3}' .format(self.serial.port, command, data, retry_count)) interface.inc_intf_write_error_count() gevent.sleep(0.1) return success
def write_block(self, interface, command, data): ''' Write i2c data given command, and data. ''' interface.inc_intf_write_block_count() success = False retry_count = 0 data_with_checksum = data if self.api_level <= 19: data_with_checksum.append(command) data_with_checksum.append(calculate_checksum(data_with_checksum)) while success is False and retry_count <= MAX_RETRY_COUNT: try: def _write(): # self.io_request = monotonic() self.i2c_helper.i2c.write_i2c_block_data(self.i2c_addr, command, data_with_checksum) # self.io_response = monotonic() return True success = self.i2c_helper.with_i2c(_write) if success is None: success = False except IOError as err: interface.log('Write Error: ' + str(err)) self.i2c_helper.i2c_end() retry_count = retry_count + 1 if retry_count <= MAX_RETRY_COUNT: interface.log('Retry (IOError) in write_block: addr={0} cmd={1} data={2} retry={3} ts={4}'.format(self.i2c_addr, command, data, retry_count, self.i2c_helper.i2c_timestamp)) else: interface.log('Retry (IOError) limit reached in write_block: addr={0} cmd={1} data={2} retry={3} ts={4}'.format(self.i2c_addr, command, data, retry_count, self.i2c_helper.i2c_timestamp)) interface.inc_intf_write_error_count() return success