os.makedirs("log") os.chdir("log") # Log file name logFileName = "log_" + datetime.now().strftime("%Y%m%d_%H%M%S") + ".txt" if os.path.exists(logFileName): os.remove(logFileName) logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" Packet Error Rate Test \n") logFile.write("-------------------------------------------------------\n") logFile.write("Channel: " + str(DEFAULT_CHANNEL) + "\n") # Set serial read time-out serialport.setTimeout(SERIAL_PORT_TIMEOUT_ROUTER) # Factory new the controller print '[Factory New]' isFN = 0 serialport.sendBuffer('ATZ\r\n') while (isFN == 0): fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' # Create network sendCommand(serialport, createNwkCmd, channel=DEFAULT_CHANNEL) time.sleep(1)
os.makedirs("log") os.chdir("log") # Log file name logFileName = "log_" + datetime.now().strftime("%Y%m%d_%H%M%S") + ".txt" if os.path.exists(logFileName): os.remove(logFileName) logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" Packet Error Rate Test \n") logFile.write("-------------------------------------------------------\n") logFile.write("Channel: " + str(DEFAULT_CHANNEL) + "\n") # Set serial read time-out serialport.setTimeout(SERIAL_PORT_TIMEOUT_ROUTER) # Factory new the controller print '[Factory New]' isFN = 0 serialport.sendBuffer('ATZ\r\n') while(isFN == 0): fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' # Create network sendCommand(serialport, createNwkCmd, channel=DEFAULT_CHANNEL) time.sleep(1)
def runTest(self, event): # Log file directory if not os.path.exists("log"): os.makedirs("log") os.chdir("log") # Log file name logFileName = "log_" + datetime.now().strftime("%Y%m%d_%H%M%S") + ".txt" if os.path.exists(logFileName): os.remove(logFileName) logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" UART Rx Test \n") logFile.write("-------------------------------------------------------\n") # Serial port time-out serialport.setTimeout(SERIAL_TIMEOUT) # Factory new the controller print '[Factory New]' isFN = 0 while(isFN == 0): serialport.sendBuffer('ATZ\r\n') fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' packetId = 0 lastErrorPacketId = 0 errorCounts = 0 atCommand='ATI2\r\n' for packetId in range(0, 1000): serialport.sendBuffer(atCommand) logFile.write(atCommand) # Log the echo from the controller echo = serialport.readline() print echo logFile.write(echo) response = serialport.readline() responseOK = serialport.readline() logMessage = '[' + str(packetId) + '] ' + response + responseOK print logMessage logFile.write(logMessage) if (response.startswith('ERROR')): errorCounts += 1 logMessage = '[Error occurs after ' + str(packetId - lastErrorPacketId) + ' packets]\n' print logMessage lastErrorPacketId = packetId logFile.write(logMessage) # Print the test result print 'Tried: ' + str(packetId + 1) + '\n' print 'Error Counts: ' + str(errorCounts) + '\n' logFile.write('Tried: ' + str(packetId + 1) + '\n') logFile.write('Error Counts: ' + str(errorCounts) + '\n') logFile.close() return
return "[Error: " + attrStr + "]\n" # Create network sendCommand(serialport, createNwkCmd, channel=DEFAULT_CHANNEL) time.sleep(1) # Enable join sendCommand(serialport, joinEnableCmd, time=PERMIT_JOIN_DURATION) # Start time start = datetime.now() print "[Permit join enabled]" # Set serial read timeout serialport.setTimeout(10000) # Log file if not os.path.exists("log"): os.makedirs("log") os.chdir("log") if os.path.exists("deviceInfo.txt"): os.remove("deviceInfo.txt") logFile = open("deviceInfo.txt", "w+") logFile.write("=======================================================\n") logFile.write("[Log created]\n" + datetime.now().strftime("%d %b %Y %H:%M:%S") + "\n") # Join started isStarted = 1
os.makedirs("log") os.chdir("log") # Log file name logFileName = "log_" + datetime.now().strftime("%Y%m%d_%H%M%S") + ".txt" if os.path.exists(logFileName): os.remove(logFileName) logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" UART Rx Test \n") logFile.write("-------------------------------------------------------\n") #print '[UART RX Test]' # Serial port timeout serialport.setTimeout(SERIAL_TIMEOUT) # Factory new the controller print '[Factory New]' isFN = 0 while (isFN == 0): serialport.sendBuffer('ATZ\r\n') fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' #Create network #sendCommand(serialport, createNwkCmd, channel=0x1A) #time.sleep(1)
os.makedirs("log") os.chdir("log") # Log file name logFileName = "log_" + datetime.now().strftime("%Y%m%d_%H%M%S") + ".txt" if os.path.exists(logFileName): os.remove(logFileName) logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" UART Rx Test \n") logFile.write("-------------------------------------------------------\n") #print '[UART RX Test]' # Serial port timeout serialport.setTimeout(SERIAL_TIMEOUT) # Factory new the controller print '[Factory New]' isFN = 0 while(isFN == 0): serialport.sendBuffer('ATZ\r\n') fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' #Create network #sendCommand(serialport, createNwkCmd, channel=0x1A) #time.sleep(1)
return '[Error: ' + attrStr + ']\n' #Create network sendCommand(serialport, createNwkCmd, channel=DEFAULT_CHANNEL) time.sleep(1) #Enable join sendCommand(serialport, joinEnableCmd, time=PERMIT_JOIN_DURATION) #Start time start = datetime.now() print '[Permit join enabled]' #Set serial read timeout serialport.setTimeout(10000) # Log file if not os.path.exists("log"): os.makedirs("log") os.chdir("log") if os.path.exists("deviceInfo.txt"): os.remove("deviceInfo.txt") logFile = open("deviceInfo.txt", "w+") logFile.write("=======================================================\n") logFile.write("[Log created]\n" + datetime.now().strftime("%d %b %Y %H:%M:%S") + "\n") #Join started
def runTest(self, event): # Log file directory if not os.path.exists("log"): os.makedirs("log") os.chdir("log") # Log file name logFileName = "log_" + datetime.now().strftime("%Y%m%d_%H%M%S") + ".txt" if os.path.exists(logFileName): os.remove(logFileName) logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" UART Rx Test \n") logFile.write("-------------------------------------------------------\n") # Serial port time-out serialport.setTimeout(SERIAL_TIMEOUT) # Factory new the controller print '[Factory New]' isFN = 0 while (isFN == 0): serialport.sendBuffer('ATZ\r\n') fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' packetId = 0 lastErrorPacketId = 0 errorCounts = 0 atCommand = 'ATI2\r\n' for packetId in range(0, 1000): serialport.sendBuffer(atCommand) logFile.write(atCommand) # Log the echo from the controller echo = serialport.readline() print echo logFile.write(echo) response = serialport.readline() responseOK = serialport.readline() logMessage = '[' + str(packetId) + '] ' + response + responseOK print logMessage logFile.write(logMessage) if (response.startswith('ERROR')): errorCounts += 1 logMessage = '[Error occurs after ' + str( packetId - lastErrorPacketId) + ' packets]\n' print logMessage lastErrorPacketId = packetId logFile.write(logMessage) # Print the test result print 'Tried: ' + str(packetId + 1) + '\n' print 'Error Counts: ' + str(errorCounts) + '\n' logFile.write('Tried: ' + str(packetId + 1) + '\n') logFile.write('Error Counts: ' + str(errorCounts) + '\n') logFile.close() return