Package VisionEgg :: Module Daq |
[frames] | no frames]

# Source Code for Module VisionEgg.Daq

      1  # The Vision Egg: Daq
      2  #
      3  # Copyright (C) 2001-2003 Andrew Straw.
      4  # Author: Andrew Straw <astraw@users.sourceforge.net>
      5  # URL: <http://www.visionegg.org/>
      6  #
      7  # Distributed under the terms of the GNU Lesser General Public License
      8  # (LGPL). See LICENSE.TXT that came with this file.
      9
     10  """
     11  Definition of data acquisition and triggering interfaces.
     12
     13  This module provides an interface to abstract data acquisition
     14  devices.  To interface with real data acquisition devices, use a
     15  module that subclasses the classes defined here.
     16
     17  *WARNING* This module has not been extensively tested or used, and should be
     18  considered unstable.
     19
     20  """
     21
     22  import VisionEgg
     23  import VisionEgg.ParameterTypes as ve_types
     24
     25  __version__ = VisionEgg.release_name
     26
     27 -class Trigger(VisionEgg.ClassWithParameters):
     28      pass
     29
     30 -class ChannelParameters(VisionEgg.ClassWithParameters):
     31      pass
     32
     33 -class SignalType(ChannelParameters):
     34      constant_parameters_and_defaults = {
     35          'units':('Unknown units',
     36                   ve_types.String),
     37          }
     38 -    def __init__(self,**kw):
     39          if self.__class__ == SignalType:
     40              raise RuntimeError("Trying to instantiate abstract base class.")
     41          else:
     42              ChannelParameters.__init__(self,**kw)
     43
     44 -class Analog(SignalType):
     45      constant_parameters_and_defaults = {
     46          'gain':(1.0,
     47                  ve_types.Real),
     48          'offset':(0.0,
     49                    ve_types.Real)}
     50
     51 -class Digital(SignalType):
     52      pass
     53
     54 -class DaqMode(ChannelParameters):
     55 -    def __init__(self,**kw):
     56          if self.__class__ == DaqMode:
     57              raise RuntimeError("Trying to instantiate abstract base class.")
     58          else:
     59              ChannelParameters.__init__(self,**kw)
     60
     61 -class Buffered(DaqMode):
     62      parameters_and_defaults = {
     63          'sample_rate_hz':(5000.0,
     64                            ve_types.Real),
     65          'duration_sec':(5.0,
     66                          ve_types.Real),
     67          'trigger':(None,
     68                     ve_types.Instance(Trigger)),
     69          }
     70
     71 -class Immediate(DaqMode):
     72      pass
     73
     74 -class Functionality(ChannelParameters):
     75 -    def __init__(self,**kw):
     76          if self.__class__ == Functionality:
     77              raise RuntimeError("Trying to instantiate abstract base class.")
     78          else:
     79              ChannelParameters.__init__(self,**kw)
     80
     81 -class Input(Functionality):
     82 -    def get_data(self):
     83          raise RuntimeError("Must override get_data method with daq implementation!")
     84
     85 -class Output(Functionality):
     86 -    def put_data(self,data):
     87          raise RuntimeError("Must override put_data method with daq implementation!")
     88
     89 -class Channel(VisionEgg.ClassWithParameters):
     90      constant_parameters_and_defaults = {
     91          'signal_type' : (None,
     92                           ve_types.Instance(SignalType)),
     93          'daq_mode' : (None,
     94                        ve_types.Instance(DaqMode)),
     95          'functionality' : (None,
     96                             ve_types.Instance(Functionality)),
     97          }
     98 -    def __init__(self,**kw):
     99          VisionEgg.ClassWithParameters.__init__(self,**kw)
    100          self.constant_parameters.signal_type.channel = self
    101          self.constant_parameters.daq_mode.channel = self
    102          self.constant_parameters.functionality.channel = self
    103          self.device = None # Not set yet
    104
    105 -    def arm_trigger(self):
    106          raise NotImpelemetedError("This method must be overridden.")
    107
    108 -class Device:
    109 -    def __init__(self, channels = None):
    110          self.channels = []
    111          if channels is not None:
    112              if type(channels) is not types.ListType:
    113                  raise ValueError("channels must be a list of channels")
    114              for channel in channels:
    115                  self.add_channel( channel )
    116
    117 -    def add_channel(self,channel):
    118          # override this method if you need to do error checking
    119          if isinstance(channel,Channel):
    120              self.channels.append(channel)
    121          else:
    122              raise ValueError("%s not instance of VisionEgg.Daq.Channel"%channel)
    123          channel.device = self
    124