rtinject_comp.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 # -*- coding: utf-8 -*-
00004 
00005 '''rtshell
00006 
00007 Copyright (C) 2009-2014
00008     Geoffrey Biggs
00009     RT-Synthesis Research Group
00010     Intelligent Systems Research Institute,
00011     National Institute of Advanced Industrial Science and Technology (AIST),
00012     Japan
00013     All rights reserved.
00014 Licensed under the Eclipse Public License -v 1.0 (EPL)
00015 http://www.opensource.org/licenses/eclipse-1.0.txt
00016 
00017 Writer component used by rtinject
00018 
00019 '''
00020 
00021 
00022 import gen_comp
00023 
00024 import OpenRTM_aist
00025 import RTC
00026 import sys
00027 
00028 
00029 ###############################################################################
00030 ## Writer component for rtinject
00031 
00032 class Writer(gen_comp.GenComp):
00033     def __init__(self, mgr, port_specs, val=None, *args, **kwargs):
00034         gen_comp.GenComp.__init__(self, mgr, port_specs, *args, **kwargs)
00035         self._val = val
00036 
00037     def _behv(self, ec_id):
00038         for p in self._ports.values():
00039             p.port.write(self._val)
00040         return RTC.RTC_OK, 1
00041 
00042 
00043 ###############################################################################
00044 ## From-standard-input writer component for rtinject
00045 
00046 class StdinWriter(Writer):
00047     def __init__(self, mgr, port_specs, buf=None, mutex=None, *args,
00048             **kwargs):
00049         Writer.__init__(self, mgr, port_specs, *args, **kwargs)
00050         if buf is None:
00051             raise ValueError('buf cannot be None.')
00052         if mutex is None:
00053             raise ValueError('mutex cannot be None.')
00054         self._val_buffer = buf
00055         self._mutex = mutex
00056 
00057     def _behv(self, ec_id):
00058         with self._mutex:
00059             if self._val_buffer:
00060                 self._val = self._val_buffer.pop(0)
00061                 result = Writer._behv(self, ec_id)
00062                 return result
00063             else:
00064                 return RTC.RTC_OK, 0
00065 


rtshell
Author(s): Geoffrey Biggs
autogenerated on Fri Aug 28 2015 12:55:12