using NIDAQmx.DAQmxEnum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace NIDAQmx
{
    public class DOChannel : OutChannel
    {
        internal DOChannel(DAQmxSession session) : base(session)
        {
            AttributeSession = new ChannelAttributeSession(session);
        }
        internal override ChannelAttributeSession AttributeSession { get; }
        internal void Create(string lines, string nameToAssignToLines, int lineGrouping)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DOCreate.DAQmxCreateDOChan>()(_Session.TaskHandle, lines, nameToAssignToLines, lineGrouping));
            if (_Session.Error)
            {
                throw new Exception($"Create Channel fail");
            }
            ChannelName = lines;
        }
        public void WriteDigital(int numSampsPerChan, bool autoStart, double timeout, bool dataLayout, ref byte writeArray, ref int sampsPerChanWritten)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteDigitalU8>()(_Session.TaskHandle, numSampsPerChan, autoStart, timeout, dataLayout, ref writeArray, ref sampsPerChanWritten, IntPtr.Zero));
        }
        public void WriteDigital(int numSampsPerChan, bool autoStart, double timeout, bool dataLayout, ref ushort writeArray, ref int sampsPerChanWritten)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteDigitalU16>()(_Session.TaskHandle, numSampsPerChan, autoStart, timeout, dataLayout, ref writeArray, ref sampsPerChanWritten, IntPtr.Zero));
        }
        public void WriteDigital(int numSampsPerChan, bool autoStart, double timeout, bool dataLayout, ref uint writeArray, ref int sampsPerChanWritten)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteDigitalU32>()(_Session.TaskHandle, numSampsPerChan, autoStart, timeout, dataLayout, ref writeArray, ref sampsPerChanWritten, IntPtr.Zero));
        }
        public void WriteDigitalScalar(bool autoStart, double timeout, uint value)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteDigitalScalarU32>()(_Session.TaskHandle, autoStart, timeout, value, IntPtr.Zero));
        }
        public void WriteDigitalLines(int numSampsPerChan, bool autoStart, double timeout, bool dataLayout, ref byte writeArray, ref int sampsPerChanWritten)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataWrite.DAQmxWriteDigitalLines>()(_Session.TaskHandle, numSampsPerChan, autoStart, timeout, dataLayout, ref writeArray, ref sampsPerChanWritten, IntPtr.Zero));
        }
    }
}
