using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace INT69DC_7C.SerialManger
{
    public partial class SerialMgrComm
    {
        private const string PathDll = "SD Card\\Run\\DllSerialMgr.dll";

        public delegate void fnSerialVersionCB(StringBuilder pVersion);
        public static fnSerialVersionCB fnSerialVersionCallback;

        public delegate void fnSerialMgrDebugCB(int level, StringBuilder pMessage);
        public static fnSerialMgrDebugCB fnSerialMgrDebugCallback;

        public delegate void fnSerialMgrPortConnectCB(StringBuilder commPort, int status, int errDetail);
        public static fnSerialMgrPortConnectCB fnSerialMgrPortConnectCallback;

        public delegate void fnSerialMgrRcvPacketCB(StringBuilder commPort, IntPtr pData, int length);
        public static fnSerialMgrRcvPacketCB fnSerialMgrRcvPacketCallback;

        public delegate void fnSerialMgrRcvPacketStrCB(StringBuilder commPort, StringBuilder pMessage, int length);
        public static fnSerialMgrRcvPacketStrCB fnSerialMgrRcvPacketStrCallback;

        public delegate void fnSerialMgrRcvErrPacketCB(StringBuilder commPort, IntPtr pData, int length);
        public static fnSerialMgrRcvErrPacketCB fnSerialMgrRcvErrPacketCallback;

        public delegate void fnSerialMgrRcvErrPacketStrCB(StringBuilder commPort, StringBuilder pMessage, int length);
        public static fnSerialMgrRcvErrPacketStrCB fnSerialMgrRcvErrPacketStrCallback;

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Register_DebugCB(fnSerialMgrDebugCB func);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Register_ConnectCB(fnSerialMgrPortConnectCB func);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Register_VersionCB(fnSerialVersionCB func);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Register_RcvPacketCB(fnSerialMgrRcvPacketCB func);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Register_RcvPacketStrCB(fnSerialMgrRcvPacketStrCB func);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Register_RcvErrPacketCB(fnSerialMgrRcvErrPacketCB func);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Register_RcvErrPacketStrCB(fnSerialMgrRcvErrPacketStrCB func);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_HelloWorld();

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Getversion();

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Activation();

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern void DLL_SerialMgr_Deactivation();

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern int DLL_SerialMgr_PortOpen(IntPtr commPort, int BaudRate, int StopBit, int Parity, int DataBit);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern int DLL_SerialMgr_PortClose(IntPtr commPort);

        [DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
        public static extern int DLL_SerialMgr_PortSendMsg(IntPtr commPort, IntPtr pData, int Length);

    }
}
