SimpleIO/ConsoleOut.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # -*- Python -*-
4 
5 import sys
6 import time
7 
8 import RTC
9 import OpenRTM_aist
10 
11 consoleout_spec = ["implementation_id", "ConsoleOut",
12  "type_name", "ConsoleOut",
13  "description", "Console output component",
14  "version", "1.0",
15  "vendor", "Shinji Kurihara",
16  "category", "example",
17  "activity_type", "DataFlowComponent",
18  "max_instance", "10",
19  "language", "Python",
20  "lang_type", "script",
21  ""]
22 
23 
25  def __init__(self, name):
26  self._name = name
27 
28  def __del__(self):
29  print "dtor of ", self._name
30 
31  def __call__(self, info, cdrdata):
32  data = OpenRTM_aist.ConnectorDataListenerT.__call__(self, info, cdrdata, RTC.TimedLong(RTC.Time(0,0),0))
33  print "------------------------------"
34  print "Listener: ", self._name
35  print "Profile::name: ", info.name
36  print "Profile::id: ", info.id
37  print "Data: ", data.data
38  print "------------------------------"
39 
40 
42  def __init__(self, name):
43  self._name = name
44 
45  def __del__(self):
46  print "dtor of ", self._name
47 
48  def __call__(self, info):
49  print "------------------------------"
50  print "Listener: ", self._name
51  print "Profile::name: ", info.name
52  print "Profile::id: ", info.id
53  print "------------------------------"
54 
55 
56 
58  def __init__(self, manager):
59  OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
60  return
61 
62  def onInitialize(self):
63  self._data = RTC.TimedLong(RTC.Time(0,0),0)
64  self._inport = OpenRTM_aist.InPort("in", self._data)
65  # Set InPort buffer
66  self.addInPort("in", self._inport)
67 
68  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE,
69  DataListener("ON_BUFFER_WRITE"))
70 
71 
72  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL,
73  DataListener("ON_BUFFER_FULL"))
74 
75  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT,
76  DataListener("ON_BUFFER_WRITE_TIMEOUT"))
77 
78  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE,
79  DataListener("ON_BUFFER_OVERWRITE"))
80 
81  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ,
82  DataListener("ON_BUFFER_READ"))
83 
84  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_SEND,
85  DataListener("ON_SEND"))
86 
87  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
88  DataListener("ON_RECEIVED"))
89 
90  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL,
91  DataListener("ON_RECEIVER_FULL"))
92 
93  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_TIMEOUT,
94  DataListener("ON_RECEIVER_TIMEOUT"))
95 
96  self._inport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_ERROR,
97  DataListener("ON_RECEIVER_ERROR"))
98 
99  self._inport.addConnectorListener(OpenRTM_aist.ConnectorListenerType.ON_CONNECT,
100  ConnListener("ON_CONNECT"))
101  self._inport.addConnectorListener(OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT,
102  ConnListener("ON_DISCONNECT"))
103 
104  return RTC.RTC_OK
105 
106  def onExecute(self, ec_id):
107 
108  if self._inport.isNew():
109  data = self._inport.read()
110  print "Received: ", data
111  print "Received: ", data.data
112  print "TimeStamp: ", data.tm.sec, "[s] ", data.tm.nsec, "[ns]"
113 
114  return RTC.RTC_OK
115 
116 
117 def ConsoleOutInit(manager):
118  profile = OpenRTM_aist.Properties(defaults_str=consoleout_spec)
119  manager.registerFactory(profile,
120  ConsoleOut,
121  OpenRTM_aist.Delete)
122 
123 def MyModuleInit(manager):
124  ConsoleOutInit(manager)
125 
126  # Create a component
127  comp = manager.createComponent("ConsoleOut")
128 
129 
130 def main():
131  # Initialize manager
132  mgr = OpenRTM_aist.Manager.init(sys.argv)
133 
134  # Set module initialization proceduer
135  # This procedure will be invoked in activateManager() function.
136  mgr.setModuleInitProc(MyModuleInit)
137 
138  # Activate manager and register to naming service
139  mgr.activateManager()
140 
141  # run the manager in blocking mode
142  # runManager(False) is the default
143  mgr.runManager()
144 
145  # If you want to run the manager in non-blocking mode, do like this
146  # mgr.runManager(True)
147 
148 if __name__ == "__main__":
149  main()
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
This class is abstract base class for listener classes that provides callbacks for various events in ...
def addInPort(self, name, inport)
Definition: RTObject.py:2721
InPort template class.
Definition: InPort.py:58
This class is abstract base class for listener classes that provides callbacks for various events in ...


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34