using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace DSRemoteCSharp
{
    public class DSRemoteWrapper
    {
        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconGetVersion([In, Out] byte[] version, int len);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconCreateInstance(ref IntPtr handle, int connectionType);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconConnect(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)]string connectionString);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconDestroyInstance(IntPtr handle);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconDisconnect(IntPtr handle);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconGetChannelCount(IntPtr handle, ref UIntPtr count);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconChannelGetName(IntPtr channel, [In, Out] byte[] name, int len);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconSetAppWindowVisible(IntPtr handle, bool visible);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconChannelSetTransferred(IntPtr handle, bool transferred);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconLoadSetup(IntPtr handle, [MarshalAs(UnmanagedType.LPStr)]string fileName);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconIsInAqusition(IntPtr handle, ref bool value);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconStartMeasurement(IntPtr handle);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconStopMeasurement(IntPtr handle);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconBeginRead(IntPtr handle, ref double startTime, ref double endTime);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconChannelReadScalarData(IntPtr handle, ref double[] data, double[] timestamps, ref int count);
        
        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconChannelReadScalarData_2(IntPtr handle, [In, Out] double[] data, [In, Out] double[] timestamps, ref UIntPtr count);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconControlChannelWriteData(IntPtr handle, double data);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconEndRead(IntPtr handle);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconGetSampleRate(IntPtr handle, ref double sampleRate);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconGetChannelType(IntPtr handle, ref int chType);
        
        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconIsChannelControl(IntPtr handle, ref bool result);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconGetChUnit(IntPtr handle, [In, Out] byte[] resultUnit, int len);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static unsafe extern int dsconEnumerateChannels(IntPtr handle, ref byte** channelIdList, ref UIntPtr count);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static unsafe extern int dsconFreeEnumerateChannels(IntPtr handle, ref byte** channelIdList);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconCreateChannelInstance(IntPtr handle, byte[] id, ref IntPtr chInstance);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconCreateChannelInstanceByName(IntPtr handle, byte[] chName, ref IntPtr chInstance);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconFreeChannelInstance(IntPtr chInstance);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconInitChannelIdEnum(IntPtr handle);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconGetNextChannelId(IntPtr handle, [In, Out] byte[] id);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconGetNextChannelIdSize(IntPtr handle, ref int size);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconChannelGetNameUtf8(IntPtr channel, [In, Out] byte[] name, UIntPtr len, ref UIntPtr required);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconCreateChannelInstanceByNameUtf8(IntPtr handle, byte[] utf8Name, ref IntPtr chInstance);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconChannelReadScalarData_2abs(IntPtr handle, [In, Out] double[] data, [In, Out] double[] timestamps, ref UIntPtr count);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconGetState(IntPtr handle, ref int state);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconStartStoring(IntPtr handle, byte[] utf8FileName);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconStopStoring(IntPtr handle);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconStopStoringEx(IntPtr handle, ref int stateAfterStop);

        [DllImport("DSRemoteConnect64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern int dsconSetBufferSize(IntPtr handle, int bufferSize);

    }
}
