def GetSerialNumber(): settings = {} with open('settings.yml', 'r') as infile: settings = yaml.load(infile) infile.close() env.print_debug('>> GetSerialNumber: {} <<'.format(settings['SN'])) return settings['SN']
def SetSerialNumber(sn=None): settings = {} with open('settings.yml', 'r') as infile: settings = yaml.load(infile) infile.close() env.print_debug('>> SetSerialNumber: {} <<'.format(sn)) if sn != None and sn != settings['SN']: settings['SN'] = sn with open('settings.yml', 'w') as outfile: yaml.dump(settings, outfile, default_flow_style=False) outfile.close() return settings['SN']
def SetDUTinfo(sn=None): settings = {} with open('settings.yml', 'r') as infile: settings = yaml.load(infile) infile.close() env.print_debug('>> SetSerialNumber: {} <<'.format(sn)) # env.print_debug('>> SetI210MacAddress: {} <<'.format(I210MacAddress)) # env.print_debug('>> SetFPGAMacAddress: {} <<'.format(FPGAMacAddress)) if sn != None: settings['SN'] = sn # settings['i210'] = I210MacAddress # settings['fpga'] = FPGAMacAddress with open('settings.yml', 'w') as outfile: yaml.dump(settings, outfile, default_flow_style=False) outfile.close() return settings['SN']
def SetDUTinfo(sn=None, I210MacAddress=None, FPGAMacAddress=None): settings = {} with open('settings.yml', 'r') as infile: settings = yaml.load(infile) infile.close() env.print_debug('>> SetSerialNumber: {} <<'.format(sn)) env.print_debug('>> SetI210MacAddress: {} <<'.format(I210MacAddress)) env.print_debug('>> SetFPGAMacAddress: {} <<'.format(FPGAMacAddress)) if sn != None and I210MacAddress != None and FPGAMacAddress != None: settings['SN'] = sn settings['i210'] = I210MacAddress[0:2] + ':' + I210MacAddress[ 2:4] + ':' + I210MacAddress[4:6] + ':' + I210MacAddress[ 6:8] + ':' + I210MacAddress[8:10] + ':' + I210MacAddress[10:12] settings['fpga'] = FPGAMacAddress[0:2] + ':' + FPGAMacAddress[ 2:4] + ':' + FPGAMacAddress[4:6] + ':' + FPGAMacAddress[ 6:8] + ':' + FPGAMacAddress[8:10] + ':' + FPGAMacAddress[10:12] with open('settings.yml', 'w') as outfile: yaml.dump(settings, outfile, default_flow_style=False) outfile.close() return settings['SN']
def send_cmd(cmd, flag_space=False): if ser == None: raise Exception("Serial Port is not connected!") if hasattr(ser, 'flushInput'): ser.flushInput() ser.flush() env.print_debug("Transmit [{}]".format(cmd)) ser.write(cmd + '\n') print 'Write cmd : ', cmd log_entry_start(cmd) result = '' # for cmd retry #if settings['ADB']['SID']: # retry = settings['ADB'].get('RETRIES') #else: retry = settings['UART'].get('RETRIES') timeout = int(settings['CMD_TIMEOUT']) # for cmd timeout initial = time.time() duration = 0 while wait_until_read and (retry is None or retry > 0): result += ser_read() #print result if (DefaultShellPrompt in result) or (ShellPrompt in result): break ''' # check in statements ">". and send "'" to exit if cmd==' EOFEOF ' and result.find('>') != -1: cmd = "'" ser.write(cmd + '\n') ''' duration = time.time() - initial if duration > 1: sys.stdout.write('\rElapsed Time: %#.8f seconds' % duration) sys.stdout.flush() if flag_space and len(s) < 1: if retry is not None: retry -= 1 print "wait..." else: if retry is not None and duration > timeout: retry -= 1 # check in statements ">". and send "'" to exit test_cmd = 'exit' ser.write(test_cmd + '\n') ''' result = ser_read( len(DefaultShellPrompt) ) if result.find('>') != -1: test_cmd = "'" ser.write(test_cmd + '\n') ''' env.print_error('\nTimeout (%#.8f > %s) !!! please wait...' % (duration, timeout)) ser.write(cmd + '\n') if result.find(DefaultShellPromptNewLine) != -1: break ser_read() if duration > 1: sys.stdout.write('\n') sys.stdout.flush() env.print_debug("Receive [{}]".format(result)) # Remove unwanted characters in resp result = result.replace(cmd, "") result = result.replace(DefaultShellPromptNewLine, "") result = result.strip() print 'Result-->', result return result