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

namespace NIDAQmx
{
    public class DIChannel : InChannel
    {
        internal DIChannel(DAQmxSession session) : base(session)
        {
            AttributeSession = new ChannelAttributeSession(session);
        }
        internal override ChannelAttributeSession AttributeSession { get; }
        public void ReadDigital(int numSampsPerChan,double timeout,bool fillMode,ref byte readArray,uint arraySizeInSamps,ref int sampsPerChanRead)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataRead.DAQmxReadDigitalU8>()(_Session.TaskHandle, numSampsPerChan, timeout, fillMode, ref readArray, arraySizeInSamps, ref sampsPerChanRead, IntPtr.Zero));
        }
        public void ReadDigital(int numSampsPerChan, double timeout, bool fillMode, ref ushort readArray, uint arraySizeInSamps, ref int sampsPerChanRead)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataRead.DAQmxReadDigitalU16>()(_Session.TaskHandle, numSampsPerChan, timeout, fillMode, ref readArray, arraySizeInSamps, ref sampsPerChanRead, IntPtr.Zero));
        }
        public void ReadDigital(int numSampsPerChan, double timeout, bool fillMode, ref uint readArray, uint arraySizeInSamps, ref int sampsPerChanRead)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataRead.DAQmxReadDigitalU32>()(_Session.TaskHandle, numSampsPerChan, timeout, fillMode, ref readArray, arraySizeInSamps, ref sampsPerChanRead, IntPtr.Zero));
        }
        public void ReadDigitalScalarU32(double timeout,ref uint value)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataRead.DAQmxReadDigitalScalarU32>()(_Session.TaskHandle,timeout,ref value,IntPtr.Zero));
        }
        public void ReadDigitalLines(int numSampsPerChan, double timeout, bool fillMode, ref byte readArray, uint arraySizeInSamps, ref int sampsPerChanRead,ref int numBytesPerSamp)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DataRead.DAQmxReadDigitalLines>()(_Session.TaskHandle, numSampsPerChan, timeout, fillMode, ref readArray, arraySizeInSamps, ref sampsPerChanRead,ref numBytesPerSamp, IntPtr.Zero));
        }
        internal void Create(string lines, string nameToAssignToLines, int lineGrouping)
        {
            _Session.CheckResult(_Session.GetDelegate<Internal.DICreate.DAQmxCreateDIChan>()(_Session.TaskHandle, lines,nameToAssignToLines,lineGrouping));
            if (_Session.Error)
            {
                throw new Exception($"Create Channel fail");
            }
            ChannelName = lines;
        }
    }
}
