Code covered by the BSD License  

Highlights from
Matlab LibTiePie 0.4.3 instrument driver for Handyscope HS5

Matlab LibTiePie 0.4.3 instrument driver for Handyscope HS5

by

 

03 Oct 2013 (Updated )

MatlabLibTiePie : TiePie engineering's instrument library for Matlab 7.6 = 2008a and higher.

LibTiePie.Oscilloscope
% Use LibTiePie.Oscilloscope for controlling LibTiePie oscilloscopes.
% Do not create LibTiePie.Oscilloscope objects directly, but use Library.List.OpenOscilloscope().
%
% For more information, see api.tiepie.com and www.tiepie.com/LibTiePie .
%
% (c) 2012-2013 TiePie engineering.

classdef Oscilloscope < LibTiePie.Device
  properties ( Access = private )
    FData = [];
    FConnectionTestData = LibTiePie.Enum.TRISTATE.empty;
    FMeasureMode = LibTiePie.Enum.MM.empty;
    FSegmentCount = 0;
  end
  properties ( SetAccess = private )
    ChannelCount;
    Channels = LibTiePie.OscilloscopeChannel.empty;
    Data; % Data of all channels in one matrix. (When MeasureMode == MM.BLOCK it may be ready multiple time after a measurement. When MeasureMode == MM.STREAM it may be read just once, as a read indicates the data buffer may be used for next data.)
    ConnectionTestData; % Connection test data of all channels in one matrix.
  end
  properties
    MeasureMode;
    RecordLength;
    SampleFrequency;
    SegmentCount;
    AutoResolutionMode;
    Resolution;

    PreSampleRatio;
    TriggerDelay;
    TriggerHoldOffCount;
    TriggerTimeOut;
    TriggerSourceOR;
    TriggerSourceAND;

    ClockSource;
    ClockOutput;
  end
  properties ( SetAccess = private )
    HasConnectionTest;

    MeasureModes;
    RecordLengthMax;
    SampleFrequencyMax;
    SegmentCountMax;
    AutoResolutionModes;
    Resolutions;

    TriggerHoldOffCountMax;
    TriggerSources;

    ClockSources;
    ClockOutputs;
  end
  methods
    function obj = Oscilloscope( oLibTiePie , hDevice )
      obj = obj@LibTiePie.Device( oLibTiePie , hDevice );
      for k = 1:obj.ChannelCount
        obj.Channels( k ) = LibTiePie.OscilloscopeChannel( obj , k );
      end
    end

    function Start( self )
      calllib( self.sLibrary , 'ScpStart' , self.hDevice );
      self.oLibTiePie.CheckStatus;
      self.FData = [];
      % Cache MeasureMode and SegmentCount for use in GetData, user can change settings after start:
      self.FMeasureMode = self.MeasureMode;
      self.FSegmentCount = self.SegmentCount;
    end
    function StartConnectionTest( self , qwChannelMask )
      if ( nargin < 2 )
        qwChannelMask = 0; % Use all enabled channels.
      end
      calllib( self.sLibrary , 'ScpStartConnectionTest' , self.hDevice , qwChannelMask );
      self.FConnectionTestData = LibTiePie.Enum.TRISTATE.empty;
      self.oLibTiePie.CheckStatus;
    end
    function Stop( self )
      calllib( self.sLibrary , 'ScpStop' , self.hDevice );
      self.oLibTiePie.CheckStatus;
    end

    function bIsConnectionTestCompleted = IsConnectionTestCompleted( self )
      bIsConnectionTestCompleted = calllib( self.sLibrary , 'ScpIsConnectionTestCompleted' , self.hDevice );
    end
    function bIsDataOverflow = IsDataOverflow( self )
      bIsDataOverflow = calllib( self.sLibrary , 'ScpIsDataOverflow' , self.hDevice );
    end
    function bIsDataReady = IsDataReady( self )
      bIsDataReady = calllib( self.sLibrary , 'ScpIsDataReady' , self.hDevice );
    end
    function bIsResolutionEnhanced = IsResolutionEnhanced( self )
      bIsResolutionEnhanced = calllib( self.sLibrary , 'ScpIsResolutionEnhanced' , self.hDevice );
    end
    function bIsRunning = IsRunning( self )
      bIsRunning = calllib( self.sLibrary , 'ScpIsRunning' , self.hDevice );
    end
    function bIsTriggered = IsTriggered( self )
      bIsTriggered = calllib( self.sLibrary , 'ScpIsTriggered' , self.hDevice );
    end
  end
  methods
    function wChannelCount = get.ChannelCount( self )
      wChannelCount = calllib( self.sLibrary , 'ScpGetChannelCount' , self.hDevice );
    end

    function arData = GetData( self )
      if self.IsDataReady
        qwRecordLength = self.RecordLength;
        wChannelCount = self.ChannelCount;

        arData = zeros( qwRecordLength , wChannelCount , 'single' );
        parData = calllib( self.sLibrary , 'HlpPointerArrayNew' , wChannelCount );
        pData = libpointer( 'singlePtr' , arData );
        for k = 0:wChannelCount - 1;
          pChannelData = pData + k * qwRecordLength;
          calllib( self.sLibrary , 'HlpPointerArraySet' , parData , k , pChannelData );
        end
        %parData.setdatatype( 'singlePtrPtr' ); // This should change parData to the correct type, however it crashes Matlab (2012b). Because of that, the signature of ScpGetData in libtiepie.h has been changed to use void** instead of float** in Matlab.
        qwReadCount = calllib( self.sLibrary , 'ScpGetData' , self.hDevice , parData , wChannelCount , 0 , qwRecordLength );
        calllib( self.sLibrary , 'HlpPointerArrayDelete' , parData );

        if qwReadCount ~= qwRecordLength
          % Less data read than expected. Find out why:
          self.oLibTiePie.CheckStatus;
        end

        % Copy the gotten data from the libpointer to the data matrix:
        arData = pData.Value;

        if ( self.FMeasureMode == LibTiePie.Enum.MM.BLOCK ) && ( self.FSegmentCount == 1 )
          % Cache data when in block mode and using only one segment, to allow multiple reads of Data:
          self.FData = arData;
        end
      else
        error( 'Data is not ready. Perform a measurement and wait until IsDataReady.' );
      end
    end

    function arData = get.Data( self )
      warning( 'Deprecated: Use GetData(), this propery will be removed in version 0.5.0!' )
      if isempty( self.FData )
        arData = self.GetData;
      else
        arData = self.FData;
      end
    end

    function arConnectionTestData = get.ConnectionTestData( self )
      if isempty( self.FConnectionTestData )
        if self.IsConnectionTestCompleted
          wChannelCount = self.ChannelCount;

          self.FConnectionTestData = zeros( 1 , wChannelCount , 'uint8' );
          [ qwReadCount self.FConnectionTestData ] = calllib( self.sLibrary , 'ScpGetConnectionTestData' , self.hDevice , self.FConnectionTestData , wChannelCount );
          self.FConnectionTestData = LibTiePie.Enum.TRISTATE( self.FConnectionTestData );

          if qwReadCount ~= wChannelCount
            % Less ConnectionTestData read than expected. Find out why:
            self.oLibTiePie.CheckStatus;
          end
        else
          error( 'ConnectionTestData is not ready. Perform a measurement and wait until IsConnectionTestCompleted.' );
        end
      end
      arConnectionTestData = self.FConnectionTestData;
    end

    function arMeasureModes = get.MeasureModes( self )
      arMeasureModes = LibTiePie.Enum.MM( LibTiePie.BitMask2Array( calllib( self.sLibrary , 'ScpGetMeasureModes' , self.hDevice ) ) );
    end;
    function dwMeasureMode = get.MeasureMode( self )
      dwMeasureMode = LibTiePie.Enum.MM( calllib( self.sLibrary , 'ScpGetMeasureMode' , self.hDevice ) );
    end;
    function set.MeasureMode( self , dwMeasureMode )
      calllib( self.sLibrary , 'ScpSetMeasureMode' , self.hDevice , uint32( dwMeasureMode ) );
      self.oLibTiePie.CheckStatus;
    end;

    function qwRecordLengthMax = get.RecordLengthMax( self )
      qwRecordLengthMax = calllib( self.sLibrary , 'ScpGetRecordLengthMax' , self.hDevice );
    end;
    function qwRecordLength = get.RecordLength( self )
      qwRecordLength = calllib( self.sLibrary , 'ScpGetRecordLength' , self.hDevice );
    end;
    function set.RecordLength( self , qwRecordLength )
      calllib( self.sLibrary , 'ScpSetRecordLength' , self.hDevice , qwRecordLength );
      self.oLibTiePie.CheckStatus;
    end;

    function dSampleFrequencyMax = get.SampleFrequencyMax( self )
      dSampleFrequencyMax = calllib( self.sLibrary , 'ScpGetSampleFrequencyMax' , self.hDevice );
    end;
    function dSampleFrequency = get.SampleFrequency( self )
      dSampleFrequency = calllib( self.sLibrary , 'ScpGetSampleFrequency' , self.hDevice );
    end;
    function set.SampleFrequency( self , dSampleFrequency )
      calllib( self.sLibrary , 'ScpSetSampleFrequency' , self.hDevice , dSampleFrequency );
      self.oLibTiePie.CheckStatus;
    end;

    function dwSegmentCountMax = get.SegmentCountMax( self )
      dwSegmentCountMax = calllib( self.sLibrary , 'ScpGetSegmentCountMax' , self.hDevice );
    end;
    function dwSegmentCount = get.SegmentCount( self )
      dwSegmentCount = calllib( self.sLibrary , 'ScpGetSegmentCount' , self.hDevice );
    end;
    function set.SegmentCount( self , dwSegmentCount )
      calllib( self.sLibrary , 'ScpSetSegmentCount' , self.hDevice , dwSegmentCount );
      self.oLibTiePie.CheckStatus;
    end;

    function arAutoResolutionModes = get.AutoResolutionModes( self )
      arAutoResolutionModes = LibTiePie.Enum.AR( LibTiePie.BitMask2Array( calllib( self.sLibrary , 'ScpGetAutoResolutionModes' , self.hDevice ) ) );
    end;
    function dwAutoResolutionMode = get.AutoResolutionMode( self )
      dwAutoResolutionMode = LibTiePie.Enum.AR( calllib( self.sLibrary , 'ScpGetAutoResolutionMode' , self.hDevice ) );
    end;
    function set.AutoResolutionMode( self , dwAutoResolutionMode )
      calllib( self.sLibrary , 'ScpGetAutoResolutionMode' , self.hDevice , dwAutoResolutionMode );
      self.oLibTiePie.CheckStatus;
    end;

    function byarResolutions = get.Resolutions( self )
      dwLength = calllib( self.sLibrary , 'ScpGetResolutions' , self.hDevice , [] , 0 );
      [ dwLength , byarResolutions ] = calllib( self.sLibrary , 'ScpGetResolutions' , self.hDevice , zeros( dwLength , 1 ) , dwLength );
    end;
    function byResolution = get.Resolution( self )
      byResolution = calllib( self.sLibrary , 'ScpGetResolution' , self.hDevice );
    end;
    function set.Resolution( self , byResolution )
      calllib( self.sLibrary , 'ScpSetResolution' , self.hDevice , byResolution );
      self.oLibTiePie.CheckStatus;
    end;


    function dPreSampleRatio = get.PreSampleRatio( self )
      dPreSampleRatio = calllib( self.sLibrary , 'ScpGetPreSampleRatio' , self.hDevice );
    end;
    function set.PreSampleRatio( self , dPreSampleRatio )
      calllib( self.sLibrary , 'ScpSetPreSampleRatio' , self.hDevice , dPreSampleRatio );
      self.oLibTiePie.CheckStatus;
    end;

    function dTriggerDelay = get.TriggerDelay( self )
      dTriggerDelay = calllib( self.sLibrary , 'ScpGetTriggerDelay' , self.hDevice );
    end;
    function set.TriggerDelay( self , dTriggerDelay )
      calllib( self.sLibrary , 'ScpSetTriggerDelay' , self.hDevice , dTriggerDelay );
      self.oLibTiePie.CheckStatus;
    end;

    function qwTriggerHoldOffCountMax = get.TriggerHoldOffCountMax( self )
      qwTriggerHoldOffCountMax = calllib( self.sLibrary , 'ScpGetTriggerHoldOffCountMax' , self.hDevice );
    end;
    function qwTriggerHoldOffCount = get.TriggerHoldOffCount( self )
      qwTriggerHoldOffCount = calllib( self.sLibrary , 'ScpGetTriggerHoldOffCount' , self.hDevice );
    end;
    function set.TriggerHoldOffCount( self , qwTriggerHoldOffCount )
      calllib( self.sLibrary , 'ScpSetTriggerHoldOffCount' , self.hDevice , qwTriggerHoldOffCount );
      self.oLibTiePie.CheckStatus;
    end;

    function dTriggerTimeOut = get.TriggerTimeOut( self )
      dTriggerTimeOut = calllib( self.sLibrary , 'ScpGetTriggerTimeOut' , self.hDevice );
    end;
    function set.TriggerTimeOut( self , dTriggerTimeOut )
      calllib( self.sLibrary , 'ScpSetTriggerTimeOut' , self.hDevice , dTriggerTimeOut );
      self.oLibTiePie.CheckStatus;
    end;

    function qwTriggerSources = get.TriggerSources( self )
      qwTriggerSources = calllib( self.sLibrary , 'ScpGetTriggerSources' , self.hDevice );
    end;

    function qwTriggerSourceOR = get.TriggerSourceOR( self )
      qwTriggerSourceOR = calllib( self.sLibrary , 'ScpGetTriggerSourceOR' , self.hDevice );
    end;
    function set.TriggerSourceOR( self , qwTriggerSourceOR )
      calllib( self.sLibrary , 'ScpSetTriggerSourceOR' , self.hDevice , qwTriggerSourceOR );
      self.oLibTiePie.CheckStatus;
    end;

    function qwTriggerSourceAND = get.TriggerSourceAND( self )
      qwTriggerSourceAND = calllib( self.sLibrary , 'ScpGetTriggerSourceAND' , self.hDevice );
    end;
    function set.TriggerSourceAND( self , qwTriggerSourceAND )
      calllib( self.sLibrary , 'ScpSetTriggerSourceAND' , self.hDevice , qwTriggerSourceAND );
      self.oLibTiePie.CheckStatus;
    end;


    function arClockSources = get.ClockSources( self )
      arClockSources = LibTiePie.Enum.CS( LibTiePie.BitMask2Array( calllib( self.sLibrary , 'ScpGetClockSources' , self.hDevice ) ) );
    end;
    function dwClockSource = get.ClockSource( self )
      dwClockSource = LibTiePie.Enum.CS( calllib( self.sLibrary , 'ScpGetClockSource' , self.hDevice ) );
    end;
    function set.ClockSource( self , dwClockSource )
      calllib( self.sLibrary , 'ScpSetClockSource' , self.hDevice , uint32( dwClockSource ) );
      self.oLibTiePie.CheckStatus;
    end;

    function arClockOutputs = get.ClockOutputs( self )
      arClockOutputs = LibTiePie.Enum.CO( LibTiePie.BitMask2Array( calllib( self.sLibrary , 'ScpGetClockOutputs' , self.hDevice ) ) );
    end;
    function dwClockOutput = get.ClockOutput( self )
      dwClockOutput = LibTiePie.Enum.CO( calllib( self.sLibrary , 'ScpGetClockOutput' , self.hDevice ) );
    end;
    function set.ClockOutput( self , dwClockOutput )
      calllib( self.sLibrary , 'ScpSetClockOutput' , self.hDevice , uint32( dwClockOutput ) );
      self.oLibTiePie.CheckStatus;
    end;
  end
  methods
    function bHasConnectionTest = get.HasConnectionTest( self )
      bHasConnectionTest = calllib( self.sLibrary , 'ScpHasConnectionTest' , self.hDevice );
    end
  end
end

Contact us