Symphony-DAS / symphony-matlab

Symphony Data Acquisition System
http://symphony-das.github.io
MIT License
19 stars 5 forks source link

Help regarding integrating of rig switches #2

Closed ragavsathish closed 9 years ago

ragavsathish commented 9 years ago

Hi Mark, Thanks for integrating Heka device support. I am trying to integrate rig toggle switches to control the state (start, stop and pause) of acquisition software.

Can you please review below approach and advise on it ?

classdef HekaITC18Multiclamp < symphonyui.core.descriptions.RigDescription
....
  methods

        function obj = HekaITC18Multiclamp()
            import symphonyui.builtin.daqs.*;
            import symphonyui.builtin.devices.*;
            import fi.helsinki.biosci.ala-alaurila.devices.*;
            ....
            rigSwitch1 = RighSwitch('rigSwitch1').bindStream(daq.getStream('DIGITAL_IN.1'))
            daq.getStream('DIGITAL_IN.1').setBitPosition(rigSwitch1, 1)
            ...
            obj.devices = {amp1, amp2, green, blue, trigger1, trigger2, rigSwitch1};
classdef Pulse < symphonyui.core.Protocol
    ....
        function prepareEpoch(obj, epoch)
           .....
           ..... 
            d = obj.rig.getDevice('rigSwitch1');
            r = epoch.response(d)
            d.checkStatus(r, 1)
But am not sure where to bind Rig Switch event listeners, Is it ok to bind on acquisition service constructor ?

If am doing some thing wrong, kindly correct me

Thanks, Sathish

cafarm commented 9 years ago

I don't think you need to subclass UnitConvertingDevice for this functionality. I'd just create a protocol superclass (AlaLaurilaProtocol or something) and derive all your protocols from it. Attach your run switch to the ITC trigger in and set epoch.waitForTrigger = true on the first epoch of the protocol. Then when each epoch completes check the current state of the rig switch.

 classdef AlaLaurilaProtocol < symphonyui.core.Protocol

    properties (Hidden)
        runTriggered = false
    end

    methods

        function prepareEpoch(obj, epoch)
            prepareEpoch@symphonyui.core.Protocol(obj, epoch);

            if obj.numEpochsPrepared == 1
                epoch.waitForTrigger = true;
            end
        end

        function completeEpoch(obj, epoch)
            completeEpoch@symphonyui.core.Protocol(obj, epoch);

            device = obj.rig.getDevice('rigSwitch1');
            quantities = epoch.response(device).getData();
            obj.runTriggered = quantities(end) == 1;
        end

        function tf = continueRun(obj)
            tf = obj.runTriggered;
        end

    end

end
ragavsathish commented 9 years ago

Yeah, it looks simple and clean :+1: Thank you.