Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rpc.py Source File

rpc.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 from mbedrpc import SerialRPC, DigitalOut, DigitalIn, pin
00019 
00020 
00021 class RpcTest(Test):
00022     def test(self):
00023         self.notify("RPC Test")
00024         s = SerialRPC(self.mbed.port, debug=True)
00025 
00026         self.notify("Init remote objects")
00027 
00028         p_out = pin("p10")
00029         p_in  = pin("p11")
00030 
00031         if hasattr(self.mbed.options, 'micro'):
00032             if self.mbed.options.micro == 'M0+':
00033                 print "Freedom Board: PTA12 <-> PTC4"
00034                 p_out = pin("PTA12")
00035                 p_in  = pin("PTC4")
00036 
00037         self.output = DigitalOut(s, p_out);
00038         self.input = DigitalIn(s, p_in);
00039 
00040         self.check = True
00041         self.write_read_test(1)
00042         self.write_read_test(0)
00043         return self.check
00044 
00045     def write_read_test(self, v):
00046         self.notify("Check %d" % v)
00047         self.output.write(v)
00048         if self.input.read() != v:
00049             self.notify("ERROR")
00050             self.check = False
00051         else:
00052             self.notify("OK")
00053 
00054 
00055 if __name__ == '__main__':
00056     RpcTest().run()