Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers echo_flow_control.py Source File

echo_flow_control.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 from host_test import Test
00018 
00019 
00020 class EchoTest(Test):
00021     def __init__(self):
00022         Test.__init__(self)
00023         self.mbed.init_serial()
00024         self.mbed.extra_serial.rtscts = True
00025         self.mbed.reset()
00026 
00027     def test(self):
00028         self.mbed.flush()
00029         self.notify("Starting the ECHO test")
00030         TEST="longer serial test"
00031         check = True
00032         for i in range(1, 100):
00033             self.mbed.extra_serial.write(TEST + "\n")
00034             l = self.mbed.extra_serial.readline().strip()
00035             if not l: continue
00036 
00037             if l != TEST:
00038                 check = False
00039                 self.notify('"%s" != "%s"' % (l, TEST))
00040             else:
00041                 if (i % 10) == 0:
00042                     self.notify('.')
00043 
00044         return check
00045 
00046 
00047 if __name__ == '__main__':
00048     EchoTest().run()