Brian Daniels / mbed-tools

Fork of mbed-tools by Morpheus

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers serial_nc_tx_auto.py Source File

serial_nc_tx_auto.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2011-2013 ARM Limited
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009     http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 """
00017 
00018 import sys
00019 import uuid
00020 import time
00021 import string
00022 from sys import stdout
00023 
00024 class SerialNCTXTest():
00025 
00026     def test(self, selftest):
00027         selftest.mbed.flush();
00028         selftest.mbed.serial_write("S");
00029 
00030         strip_chars = string.whitespace + "\0"
00031 
00032         out_str = selftest.mbed.serial_readline()
00033         selftest.notify("HOST: " + out_str)
00034 
00035         if not out_str:
00036             selftest.notify("HOST: No output detected")
00037             return selftest.RESULT_IO_SERIAL
00038 
00039         out_str_stripped = out_str.strip(strip_chars)
00040 
00041         if out_str_stripped != "TX OK - Expected":
00042             selftest.notify("HOST: Unexpected output. Expected 'TX OK - Expected' but received '%s'" % out_str_stripped)
00043             return selftest.RESULT_FAILURE
00044 
00045         out_str = selftest.mbed.serial_readline()
00046 
00047         # If no characters received, pass the test
00048         if not out_str:
00049             selftest.notify("HOST: No further output detected")
00050             return selftest.RESULT_SUCCESS
00051         else:
00052             out_str_stripped = out_str.strip(strip_chars)
00053 
00054             if out_str_stripped == "TX OK - Unexpected":
00055                 selftest.notify("HOST: Unexpected output returned indicating TX still functioning")
00056             else:
00057                 selftest.notify("HOST: Extraneous output '%s' detected indicating unknown error" % out_str_stripped)
00058 
00059             return selftest.RESULT_FAILURE