MATLAB: How to get MATLAB to automatically acquire a waveform when the oscilloscope detects a fault in the waveform

Instrument Control Toolbox

I am interfacing with my LeCroy WaveRunner scope in the "tmtool" using the MATLAB Instrument Driver from the file exchange:
I want my scope to detect when there is a peak in my waveform, trigger when this happens, and then return the waveform to MATLAB.
I've tried using the "trigger" function defined in the MDD file, but this just triggers the scope manually when you execute it. I want to continue working in the tmtool (as opposed to writing a script). Is there a way for me to do this?

Best Answer

The workflow you describe (single sequence acquisition and reading the waveform after acquisition is triggered and completed) can be achieved using "SCPI" commands to communicate with your instrument.
The commands you need to use are specific to the instrument/vendor you are using, and a full list of these commands should be available in the instrument programming manual.
For LeCroy oscilloscopes specifically, the workflow you describe is discussed in the section "Single acquisition, with wait for trigger":
Based on the above resource, you will need to:
  1. Set the "State" property in the "Acquisition" group to "single"
  2. Send the "WAIT" command using the "sendcommand" function
  3. Check that the operation is complete by querying for "*OPC?" using the "getProperty" function.
  4. Once the operation is complete, read the waveform using "readwaveform".
You can use the functionality included in the "lecroy_basic_driver.mdd" to call each of these commands sequentially within tmtool, or you can create a new function within the MDD file that calls these commands, and then call that function from the tmtool.