ConsoleOut.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # -*- Python -*-
00004 
00005 import sys
00006 import time
00007 
00008 import RTC
00009 import OpenRTM_aist
00010 
00011 consoleout_spec = ["implementation_id", "ConsoleOut",
00012                    "type_name",         "ConsoleOut",
00013                    "description",       "Console output component",
00014                    "version",           "1.0",
00015                    "vendor",            "Shinji Kurihara",
00016                    "category",          "example",
00017                    "activity_type",     "DataFlowComponent",
00018                    "max_instance",      "10",
00019                    "language",          "Python",
00020                    "lang_type",         "script",
00021                    ""]
00022 
00023 
00024 class ConsoleOut(OpenRTM_aist.DataFlowComponentBase):
00025   def __init__(self, manager):
00026     OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00027     return
00028 
00029   def onInitialize(self):
00030     self._data = RTC.TimedLong(RTC.Time(0,0),0)
00031     self._inport = OpenRTM_aist.InPort("in", self._data)
00032     # Set InPort buffer
00033     self.addInPort("in", self._inport)
00034     return RTC.RTC_OK
00035 
00036   def onExecute(self, ec_id):
00037     if self._inport.isNew():
00038       data = self._inport.read()
00039       print "Received: ", data.data
00040       print "TimeStamp: ", data.tm.sec, "[s] ", data.tm.nsec, "[ns]"
00041     time.sleep(0.001)
00042     return RTC.RTC_OK
00043 
00044 
00045 def MyModuleInit(manager):
00046   profile = OpenRTM_aist.Properties(defaults_str=consoleout_spec)
00047   manager.registerFactory(profile,
00048                           ConsoleOut,
00049                           OpenRTM_aist.Delete)
00050 
00051   # Create a component
00052   comp = manager.createComponent("ConsoleOut")
00053 
00054 
00055 def main():
00056   # Initialize manager
00057   mgr = OpenRTM_aist.Manager.init(sys.argv)
00058 
00059   # Set module initialization proceduer
00060   # This procedure will be invoked in activateManager() function.
00061   mgr.setModuleInitProc(MyModuleInit)
00062 
00063   # Activate manager and register to naming service
00064   mgr.activateManager()
00065 
00066   # run the manager in blocking mode
00067   # runManager(False) is the default
00068   mgr.runManager()
00069 
00070   # If you want to run the manager in non-blocking mode, do like this
00071   # mgr.runManager(True)
00072 
00073 if __name__ == "__main__":
00074         main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28