using NIDAQmx.DAQmxEnum;
using NIDAQmxConst;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NIDAQmx
{
    public abstract class COChannel : OutChannel
    {
        internal COChannel(DAQmxSession session) : base(session)
        {
            AttributeSession = new ChannelAttributeSession(session);
        }
        internal override ChannelAttributeSession AttributeSession { get; }
        internal void CreatePulseFreq(string counter, string nameToAssignToChannel, PulseFreqUnits units, AnalogActiveEdge idleState, double initialDelay, double freq, double dutyCycle)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.COCreate.DAQmxCreateCOPulseChanFreq>()(_Session.TaskHandle, counter, nameToAssignToChannel, units, idleState, initialDelay, freq, dutyCycle));
            if (_Session.Error)
            {
                throw new Exception($"Create PulseFreq Channel fail");
            }
            ChannelName = counter;
        }
        internal void CreatePulseTime(string counter, string nameToAssignToChannel, PulseTimeUnits units, AnalogActiveEdge idleState, double initialDelay, double lowTime, double highTime)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.COCreate.DAQmxCreateCOPulseChanTime>()(_Session.TaskHandle, counter, nameToAssignToChannel, units, idleState, initialDelay, lowTime, highTime));
            if (_Session.Error)
            {
                throw new Exception($"Create PulseTime Channel fail");
            }
            ChannelName = counter;
        }
        internal void CreateCOPulseChanTicks(string counter, string nameToAssignToChannel, string sourceTerminal, AnalogActiveEdge idleState, int initialDelay, int lowTicks, int highTicks)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.COCreate.DAQmxCreateCOPulseChanTicks>()(_Session.TaskHandle, counter, nameToAssignToChannel, sourceTerminal, idleState, initialDelay, lowTicks, highTicks));
            if (_Session.Error)
            {
                throw new Exception($"Create PulseTicks Channel fail");
            }
            ChannelName = counter;
        }
        public void WriteCtrFreq(int numSampsPerChan, bool autoStart, double timeout, bool dataLayout, ref double frequency, ref double dutyCycle, ref int numSampsPerChanWritten)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteCtrFreq>()(_Session.TaskHandle, numSampsPerChan, autoStart, timeout, dataLayout, ref frequency, ref dutyCycle, ref numSampsPerChanWritten, IntPtr.Zero));
        }
        public void WriteCtrFreqScalar(bool autoStart, double timeout, double frequency, double dutyCycle)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteCtrFreqScalar>()(_Session.TaskHandle, autoStart, timeout, frequency, dutyCycle, IntPtr.Zero));
        }
        public void WriteCtrTime(int numSampsPerChan, bool autoStart, double timeout, bool dataLayout, ref double highTime, ref double lowTime, ref int numSampsPerChanWritten)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteCtrTime>()(_Session.TaskHandle, numSampsPerChan, autoStart, timeout, dataLayout, ref highTime, ref lowTime, ref numSampsPerChanWritten, IntPtr.Zero));
        }
        public void WriteCtrTimeScalar(bool autoStart, double timeout, double highTime, double lowTime)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteCtrTimeScalar>()(_Session.TaskHandle, autoStart, timeout, highTime, lowTime, IntPtr.Zero));
        }

        public void WriteCtrTicks(int numSampsPerChan, bool autoStart, double timeout, bool dataLayout, ref  uint highTicks, ref uint lowTicks,ref int numSampsPerChanWritten)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteCtrTicks>()(_Session.TaskHandle, numSampsPerChan, autoStart, timeout, dataLayout, ref highTicks, ref lowTicks, ref numSampsPerChanWritten, IntPtr.Zero));
        }
        public void WriteCtrTicksScalar(bool autoStart, double timeout, uint highTicks, uint lowTicks)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteCtrTicksScalar>()(_Session.TaskHandle, autoStart, timeout, highTicks, lowTicks, IntPtr.Zero));
        }

    }
}
