def __send__require_ack__( self, command ): """sending a command requires an ack from the device every time.""" io.debug( 'command:\n%s' % command ) # PC sends command # meter sends ACK msg = str( self.wrap( 0, command.code ) ) return self.__retry_write_with_ack__( msg, RETRIES )
def read(self, port): response = None for i in xrange(self.__retries__): io.debug( 'retry %s' % i ) port.read(0) response = port.read( 64 ) if len(response) > 0: break; return response
def read(self, port): response = None for i in xrange(self.__retries__): io.debug('retry %s' % i) port.read(0) response = port.read(64) if len(response) > 0: break return response
def __call__( self, port ): head = port.readline( ).strip( ) body = [ ] for line in port.readlines( ): try: body.append( format_glucose( line ) ) except InvalidGlucose, e: pass io.debug ( 'read glucose:head:%s:body.len:%s' % ( head, len(body) ) ) self.response = ( head, glucose.l2np( body ) ) return self.response
def __requireAck__( self ): """Try to read an ack, raising MissingAck if we don't read it. Returns bytearray ack.""" ack = None for i in xrange( RETRIES ): ack = bytearray( self.read( 6 ) ) if ack == '': io.debug( "empty ack:%s:%s:sleeping:%s" % ( i, ack, self.__pause__ ) ) time.sleep( self.__pause__ ) else: break io.info( 'ACK: %s' % lib.hexdump( ack ) ) if ack == '': raise MissingAck(i) return ack
class ReadGlucose(OneTouchCommand): code = list(bytearray(b'DMP')) def __call__(self, port): head = port.readline().strip() body = [] for line in port.readlines(): try: body.append(format_glucose(line)) except InvalidGlucose, e: pass io.debug('read glucose:head:%s:body.len:%s' % (head, len(body))) self.response = (head, glucose.l2np(body)) return self.response