Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
echo.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 from sys import stdout 00021 00022 class EchoTest(): 00023 00024 # Test parameters 00025 TEST_SERIAL_BAUDRATE = 115200 00026 TEST_LOOP_COUNT = 50 00027 00028 def test(self, selftest): 00029 """ This host test will use mbed serial port with 00030 baudrate 115200 to perform echo test on that port. 00031 """ 00032 # Custom initialization for echo test 00033 selftest.mbed.init_serial_params(serial_baud=self.TEST_SERIAL_BAUDRATE) 00034 selftest.mbed.init_serial() 00035 00036 # Test function, return True or False to get standard test notification on stdout 00037 selftest.mbed.flush() 00038 selftest.notify("HOST: Starting the ECHO test") 00039 result = True 00040 00041 """ This ensures that there are no parasites left in the serial buffer. 00042 """ 00043 for i in range(0, 2): 00044 selftest.mbed.serial_write("\n") 00045 c = selftest.mbed.serial_readline() 00046 00047 for i in range(0, self.TEST_LOOP_COUNT): 00048 TEST_STRING = str(uuid.uuid4()) + "\n" 00049 selftest.mbed.serial_write(TEST_STRING) 00050 c = selftest.mbed.serial_readline() 00051 if c is None: 00052 return selftest.RESULT_IO_SERIAL 00053 if c.strip() != TEST_STRING.strip(): 00054 selftest.notify('HOST: "%s" != "%s"'% (c, TEST_STRING)) 00055 result = False 00056 else: 00057 sys.stdout.write('.') 00058 stdout.flush() 00059 return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE
Generated on Tue Jul 12 2022 12:21:49 by
