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


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