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 DataListener(OpenRTM_aist.ConnectorDataListenerT):
00025   def __init__(self, name):
00026     self._name = name
00027 
00028   def __del__(self):
00029     print "dtor of ", self._name
00030 
00031   def __call__(self, info, cdrdata):
00032     data = OpenRTM_aist.ConnectorDataListenerT.__call__(self, info, cdrdata, RTC.TimedLong(RTC.Time(0,0),0))
00033     print "------------------------------"
00034     print "Listener:       ", self._name
00035     print "Profile::name:  ", info.name
00036     print "Profile::id:    ", info.id
00037     print "Data:           ", data.data
00038     print "------------------------------"
00039 
00040 
00041 class ConnListener(OpenRTM_aist.ConnectorListener):
00042   def __init__(self, name):
00043     self._name = name
00044 
00045   def __del__(self):
00046     print "dtor of ", self._name
00047 
00048   def __call__(self, info):
00049     print "------------------------------"
00050     print "Listener:       ", self._name
00051     print "Profile::name:  ", info.name
00052     print "Profile::id:    ", info.id
00053     print "------------------------------"
00054 
00055 
00056 
00057 class ConsoleOut(OpenRTM_aist.DataFlowComponentBase):
00058   def __init__(self, manager):
00059     OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00060     return
00061 
00062   def onInitialize(self):
00063     self._data = RTC.TimedLong(RTC.Time(0,0),0)
00064     self._inport = OpenRTM_aist.InPort("in", self._data)
00065     # Set InPort buffer
00066     self.addInPort("in", self._inport)
00067 
00068     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE,
00069                                           DataListener("ON_BUFFER_WRITE"))
00070 
00071 
00072     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL, 
00073                                           DataListener("ON_BUFFER_FULL"))
00074 
00075     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT, 
00076                                           DataListener("ON_BUFFER_WRITE_TIMEOUT"))
00077 
00078     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE, 
00079                                           DataListener("ON_BUFFER_OVERWRITE"))
00080 
00081     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ, 
00082                                           DataListener("ON_BUFFER_READ"))
00083 
00084     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_SEND, 
00085                                           DataListener("ON_SEND"))
00086 
00087     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
00088                                           DataListener("ON_RECEIVED"))
00089 
00090     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL, 
00091                                           DataListener("ON_RECEIVER_FULL"))
00092 
00093     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_TIMEOUT, 
00094                                           DataListener("ON_RECEIVER_TIMEOUT"))
00095 
00096     self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_ERROR,
00097                                           DataListener("ON_RECEIVER_ERROR"))
00098 
00099     self._inport.addConnectorListener(OpenRTM_aist.ConnectorListenerType.ON_CONNECT,
00100                                       ConnListener("ON_CONNECT"))
00101     self._inport.addConnectorListener(OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT,
00102                                       ConnListener("ON_DISCONNECT"))
00103 
00104     return RTC.RTC_OK
00105 
00106   def onExecute(self, ec_id):
00107 
00108     if self._inport.isNew():
00109       data = self._inport.read()
00110       print "Received: ", data
00111       print "Received: ", data.data
00112       print "TimeStamp: ", data.tm.sec, "[s] ", data.tm.nsec, "[ns]"
00113 
00114     return RTC.RTC_OK
00115 
00116 
00117 def ConsoleOutInit(manager):
00118   profile = OpenRTM_aist.Properties(defaults_str=consoleout_spec)
00119   manager.registerFactory(profile,
00120                           ConsoleOut,
00121                           OpenRTM_aist.Delete)
00122 
00123 def MyModuleInit(manager):
00124   ConsoleOutInit(manager)
00125 
00126   # Create a component
00127   comp = manager.createComponent("ConsoleOut")
00128 
00129 
00130 def main():
00131   # Initialize manager
00132   mgr = OpenRTM_aist.Manager.init(sys.argv)
00133 
00134   # Set module initialization proceduer
00135   # This procedure will be invoked in activateManager() function.
00136   mgr.setModuleInitProc(MyModuleInit)
00137 
00138   # Activate manager and register to naming service
00139   mgr.activateManager()
00140 
00141   # run the manager in blocking mode
00142   # runManager(False) is the default
00143   mgr.runManager()
00144 
00145   # If you want to run the manager in non-blocking mode, do like this
00146   # mgr.runManager(True)
00147 
00148 if __name__ == "__main__":
00149   main()


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