SeqIn.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 seqin_spec = ["implementation_id", "SeqIn",
12  "type_name", "SequenceInComponent",
13  "description", "Sequence InPort 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, manager):
26  OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
27  return
28 
29 
30  def onInitialize(self):
31  self._octet = RTC.TimedOctet(RTC.Time(0,0),0)
32  self._short = RTC.TimedShort(RTC.Time(0,0),0)
33  self._long = RTC.TimedLong(RTC.Time(0,0),0)
34  self._float = RTC.TimedFloat(RTC.Time(0,0),0)
35  self._double = RTC.TimedDouble(RTC.Time(0,0),0)
36  self._octetSeq = RTC.TimedOctetSeq(RTC.Time(0,0),[])
37  self._shortSeq = RTC.TimedShortSeq(RTC.Time(0,0),[])
38  self._longSeq = RTC.TimedLongSeq(RTC.Time(0,0),[])
39  self._floatSeq = RTC.TimedFloatSeq(RTC.Time(0,0),[])
40  self._doubleSeq = RTC.TimedDoubleSeq(RTC.Time(0,0),[])
41 
42  self._octetIn = OpenRTM_aist.InPort("Octet", self._octet)
43  self._shortIn = OpenRTM_aist.InPort("Short", self._short)
44  self._longIn = OpenRTM_aist.InPort("Long", self._long)
45  self._floatIn = OpenRTM_aist.InPort("Float", self._float)
46  self._doubleIn = OpenRTM_aist.InPort("Double", self._double)
47  self._octetSeqIn = OpenRTM_aist.InPort("OctetSeq", self._octetSeq)
48  self._shortSeqIn = OpenRTM_aist.InPort("ShortSeq", self._shortSeq)
49  self._longSeqIn = OpenRTM_aist.InPort("LongSeq", self._longSeq)
50  self._floatSeqIn = OpenRTM_aist.InPort("FloatSeq", self._floatSeq)
51  self._doubleSeqIn = OpenRTM_aist.InPort("DoubleSeq", self._doubleSeq)
52 
53 
54  # Set InPort buffer
55  self.addInPort("Octet", self._octetIn)
56  self.addInPort("Short", self._shortIn)
57  self.addInPort("Long", self._longIn)
58  self.addInPort("Float", self._floatIn)
59  self.addInPort("Double", self._doubleIn)
60 
61  self.addInPort("OctetSeq", self._octetSeqIn)
62  self.addInPort("ShortSeq", self._shortSeqIn)
63  self.addInPort("LongSeq", self._longSeqIn)
64  self.addInPort("FloatSeq", self._floatSeqIn)
65  self.addInPort("DoubleSeq", self._doubleSeqIn)
66  return RTC.RTC_OK
67 
68 
69  def onExecute(self, ec_id):
70  octet_ = self._octetIn.read()
71  short_ = self._shortIn.read()
72  long_ = self._longIn.read()
73  float_ = self._floatIn.read()
74  double_ = self._doubleIn.read()
75 
76  octetSeq_ = self._octetSeqIn.read()
77  shortSeq_ = self._shortSeqIn.read()
78  longSeq_ = self._longSeqIn.read()
79  floatSeq_ = self._floatSeqIn.read()
80  doubleSeq_ = self._doubleSeqIn.read()
81 
82  octetSize_ = len(octetSeq_.data)
83  shortSize_ = len(shortSeq_.data)
84  longSize_ = len(longSeq_.data)
85  floatSize_ = len(floatSeq_.data)
86  doubleSize_ = len(doubleSeq_.data)
87 
88  octetSeqDisp_ = []
89  for i in range(octetSize_):
90  octetSeqDisp_.append(ord(octetSeq_.data[i]))
91 
92  maxsize = max(octetSize_, shortSize_, longSize_, floatSize_, doubleSize_)
93  octetSeqDisp_ = octetSeqDisp_ + ['-'] * (maxsize - octetSize_)
94  shortSeq_.data = shortSeq_.data + ['-'] * (maxsize - shortSize_)
95  longSeq_.data = longSeq_.data + ['-'] * (maxsize - longSize_)
96  floatSeq_.data = floatSeq_.data + ['-'] * (maxsize - floatSize_)
97  doubleSeq_.data = doubleSeq_.data + ['-'] * (maxsize - doubleSize_)
98 
99  if 0x20 <= octet_.data < 0x7e :
100  octetDisp_ = chr(octet_.data)
101  else:
102  octetDisp_ = " "
103  print '%3.2s %10.8s %10.8s %10.8s %10.8s %10.8s' \
104  % (' ', 'octet', 'short', 'long', 'float', 'double')
105  print '%3.2s %7s[%s] %10.8s %10.8s %10.8s %10.8s' \
106  % (' ', octet_.data, octetDisp_, short_.data, long_.data, float_.data, double_.data)
107  print "-----------------------------------------------------------"
108  print " Sequence Data "
109  print "-----------------------------------------------------------"
110  for i in range(maxsize):
111  if 0x20 <= octetSeqDisp_[i] < 0x7e :
112  octetDisp_ = chr(octetSeqDisp_[i])
113  else:
114  octetDisp_ = " "
115  print '%3.2s %7s[%s] %10.8s %10.8s %10.8s %10.8s' \
116  % (i, octetSeqDisp_[i], octetDisp_, shortSeq_.data[i], longSeq_.data[i], floatSeq_.data[i], doubleSeq_.data[i])
117 
118  # Moving cursor (^[[nA : n lines upward)
119  print "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r"
120 
121  time.sleep(0.5)
122  return RTC.RTC_OK
123 
124 
125 def SeqInInit(manager):
126  profile = OpenRTM_aist.Properties(defaults_str=seqin_spec)
127  manager.registerFactory(profile,
128  SeqIn,
129  OpenRTM_aist.Delete)
130 
131 
132 def MyModuleInit(manager):
133  SeqInInit(manager)
134 
135  # Create a component
136  comp = manager.createComponent("SeqIn")
137 
138 
139 def main():
140  # Initialize manager
141  mgr = OpenRTM_aist.Manager.init(sys.argv)
142 
143  # Set module initialization proceduer
144  # This procedure will be invoked in activateManager() function.
145  mgr.setModuleInitProc(MyModuleInit)
146 
147  # Activate manager and register to naming service
148  mgr.activateManager()
149 
150  # run the manager in blocking mode
151  # runManager(False) is the default
152  mgr.runManager()
153 
154  # If you want to run the manager in non-blocking mode, do like this
155  # mgr.runManager(True)
156 
157 if __name__ == "__main__":
158  main()
159 
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
def addInPort(self, name, inport)
Definition: RTObject.py:2721
InPort template class.
Definition: InPort.py:58


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