﻿//============================================================-
// clogger_api.cs
// Class file for C-LOGGER
//                                             CONTEC.Co.,Ltd.
//============================================================-
using System;
using System.Runtime.InteropServices;

public enum CLoggerConst
{
    //----------------------------------------
    // App size
    //----------------------------------------
    LOGGER_PARAM_WINDOW_OFF						= 0,		// Minimize
    LOGGER_PARAM_WINDOW_NORMAL					= 1,		// Normal
    LOGGER_PARAM_WINDOW_MAX						= 2,		// Maximize

    //----------------------------------------
    // Termination processing status
    //----------------------------------------
    LOGGER_STATUS_SUCCESS						= 0,		// Normal completed
    LOGGER_STATUS_FAILURE						= 1,		// C-LOGGER completed error
    LOGGER_STATUS_EXCEL							= 1,		// Excel error
    LOGGER_STATUS_OVER							= 1,		// Excel error

    //----------------------------------------
    // Operation status
    //----------------------------------------
    LOGGER_STATUS_STOP                          = 0,		// Stop
    LOGGER_STATUS_BUSY                          = 1,		// Busy
    LOGGER_STATUS_START_TRG						= 2,		// Start trigger

    //----------------------------------------
    // Enable/Disable
    //----------------------------------------
    LOGGER_PARAM_DISABLE						= 0,		// disable
    LOGGER_PARAM_ENABLE							= 1,		// enable

    //----------------------------------------
    // Input Type
    //----------------------------------------
    LOGGER_PARAM_SINGLEENDED					= 0,		// SingleEnded
    LOGGER_PARAM_DIFFERENTIAL					= 1,		// Differential

    //----------------------------------------
    // Clock Type
    //----------------------------------------
    LOGGER_PARAM_CLOCK_INTERNAL					= 0,		// internal
    LOGGER_PARAM_CLOCK_EXTERNAL					= 1,		// external

    //----------------------------------------
    // Sampling Clock Unit
    //----------------------------------------
    LOGGER_PARAM_FREQUNIT_USEC					= 0,		// usec
    LOGGER_PARAM_FREQUNIT_MSEC					= 1,		// msec
    LOGGER_PARAM_FREQUNIT_SEC					= 2,		// sec
    LOGGER_PARAM_FREQUNIT_HZ					= 3,		// Hz
    LOGGER_PARAM_FREQUNIT_KHZ					= 4,		// kHz
    LOGGER_PARAM_FREQUNIT_MHZ					= 5,		// MHz

    //----------------------------------------
    // TRIGGER TYPE
    //----------------------------------------
    LOGGER_PARAM_TRIGGER_NONE					= 0,		// none
    LOGGER_PARAM_TRIGGER_DIGITAL_RISING			= 1,		// digital edge rising
    LOGGER_PARAM_TRIGGER_DIGITAL_FALLING		= 2,		// digital edge falling
    LOGGER_PARAM_TRIGGER_LEVEL					= 3,		// level
    LOGGER_PARAM_TRIGGER_INRANGE				= 4,		// inrange
    LOGGER_PARAM_TRIGGER_OUTRANGE				= 5,		// outrange
    LOGGER_PARAM_TRIGGER_ELAPSED_TIME			= 6,		// elapsed
    LOGGER_PARAM_TRIGGER_CURRENT_TIME			= 7,		// current

    //----------------------------------------
    // TRIGGER
    //----------------------------------------
    LOGGER_PARAM_STARTTRIGGER					= 0,		// start trigger
    LOGGER_PARAM_STOPTRIGGER					= 1,		// stop trigger

    //----------------------------------------
    // TRIGGER EDGE
    //----------------------------------------
    LOGGER_PARAM_EDGE_RISING					= 0,		// rising
    LOGGER_PARAM_EDGE_FALLING					= 1,		// falling
    LOGGER_PARAM_EDGE_BOTH						= 2,		// both

    //----------------------------------------
    // TIMETYPE
    //----------------------------------------
    LOGGER_PARAM_TIMETYPE_ELAPSED				= 0,		// elapsed
    LOGGER_PARAM_TIMETYPE_CURRENT				= 1,		// current

    //----------------------------------------
    // AUTOSAVETYPE
    //----------------------------------------
    LOGGER_PARAM_SAVE_NONE						= 0,		// none
    LOGGER_PARAM_SAVE_CLB						= 1,		// binary file(clb)
    LOGGER_PARAM_SAVE_CSV						= 2,		// text file(csv)

    //----------------------------------------
    // IMAGE AREA
    //----------------------------------------
    LOGGER_PARAM_AREA_ENTIRE					= 0,		// entire(save image entire)
    LOGGER_PARAM_AREA_GRAPH						= 1,		// YT Graph(save image YT Graph)

    //----------------------------------------
    // AXIS
    //----------------------------------------
    LOGGER_PARAM_AXIS_X							= 0,		// x axis
    LOGGER_PARAM_AXIS_Y							= 1,		// y axis
    LOGGER_PARAM_AXIS_TITLE_GRAPH				= 2,		// graph title

    //----------------------------------------
    // AXIS
    //----------------------------------------
    LOGGER_PARAM_ZOOM_IN						= 0,		// zoomin
    LOGGER_PARAM_ZOOM_OUT						= 1,		// zoomout

    //----------------------------------------
    // TIMEUNIT
    //----------------------------------------
    LOGGER_PARAM_AXISTYPE_ABSOLUTE				= 0,		// absolute
    LOGGER_PARAM_AXISTYPE_RELATIVE				= 1,		// relative

    //----------------------------------------
    // GRAPH
    //----------------------------------------
    LOGGER_PARAM_GRAPH_OPEN						= 0,		// open
    LOGGER_PARAM_GRAPH_CLOSE					= 1,		// close

    //----------------------------------------
    // TARGET
    //----------------------------------------
    LOGGER_PARAM_FILE							= 0,		// file + graph
    LOGGER_PARAM_GRAPH							= 1,		// graph

    //----------------------------------------
    // EVENT
    //----------------------------------------
    LOGGER_PARAM_EVENT_NONE						= 0,		// none
    LOGGER_PARAM_EVENT_START					= 0x02,		// event that start
    LOGGER_PARAM_EVENT_RPTEND					= 0x10,		// event that repeat end
    LOGGER_PARAM_EVENT_END						= 0x20,		// event that end
    LOGGER_PARAM_EVENT_DATANUM					= 0x80,		// event that device operation end
    LOGGER_PARAM_EVENT_OFERR					= 0x10000,	// event that overflow
    LOGGER_PARAM_EVENT_SCERR					= 0x20000,	// event that sampling clock period error

    //----------------------------------------
    // DATA TYPE
    //----------------------------------------
    LOGGER_PARAM_DATA_BINARY					= 0,		// binary
    LOGGER_PARAM_DATA_VOLTAGE					= 1,		// voltage

    //----------------------------------------
    // BUFFER MODE
    //----------------------------------------
    LOGGER_PARAM_MODE_BASIC						= 0,		// basic mode
    LOGGER_PARAM_MODE_API						= 1,		// basic mode + API mode

    //----------------------------------------
    // CHANNEL NAME
    //----------------------------------------
    LOGGER_PARAM_MAX_CHANNEL_NAME				= 256,		// channel name (char[channels][CLOGGER_PARAM_MAX_CHANNEL_NAME])

    //----------------------------------------
    // RANGE
    //----------------------------------------
    PM10										= 0,		// ±10V
    PM5											= 1,		// ±5V
    PM25										= 2,		// ±2.5V
    PM125										= 3,		// ±1.25V
    P10											= 50,		// 0～10V
    P5											= 51,		// 0～5V
    P25											= 53,		// 0～2.5V
    P125										= 54,		// 0～1.25V
    P20MA										= 100,		// 0～20mA
    P4TO20MA									= 101,		// 4～20mA
    PM20MA										= 102,		// ±20mA
    P1TO5										= 150,		// 1～5V
}

namespace CLoggerCs
{
    unsafe public delegate int PLOGGEREVENTCALLBACK(short Id, uint Event, int wParam, int lParam, void *Param);
    public class CLogger
    {
        [DllImport("clogger_api.dll")] static extern int LoggerOpenApplication(string DeviceName, ref short AppId, ushort OpenMode);
        [DllImport("clogger_api.dll")] static extern int LoggerCloseApplication(short AppId, ref uint Status);
        [DllImport("clogger_api.dll")] static extern int LoggerStartOperation(short AppId, ref uint Status);
        [DllImport("clogger_api.dll")] static extern int LoggerStopOperation(short AppId);
        [DllImport("clogger_api.dll")] static extern int LoggerGetApplicationStatus(short AppId, ref uint Status);
        [DllImport("clogger_api.dll")] static extern int LoggerExportSettingFile(short AppId, string FilePath);
        [DllImport("clogger_api.dll")] static extern int LoggerImportSettingFile(short AppId, string FilePath, ref uint Status);
        [DllImport("clogger_api.dll")] static extern int LoggerSaveDataFile(short AppId, string FilePath, short Param1, short Param2);
        [DllImport("clogger_api.dll")] static extern int LoggerLoadDataFile(short AppId, string FilePath);
        [DllImport("clogger_api.dll")] static extern int LoggerSetDeviceName(short AppId, string DeviceName);
        [DllImport("clogger_api.dll")] static extern int LoggerGetDeviceName(short AppId, System.Text.StringBuilder DeviceName);
        [DllImport("clogger_api.dll")] static extern int LoggerSetChannelSetting(short AppId, ushort InputType, ushort SequenceNum, [MarshalAs(UnmanagedType.LPArray)] ushort[] ChannelNo, [MarshalAs(UnmanagedType.LPArray)] byte[] ChannelName, [MarshalAs(UnmanagedType.LPArray)] ushort[] Range);
        [DllImport("clogger_api.dll")] static extern int LoggerGetChannelSetting(short AppId, ref ushort InputType, ref ushort SequenceNum, [MarshalAs(UnmanagedType.LPArray)] ushort[] ChannelNo, [MarshalAs(UnmanagedType.LPArray)] byte[] ChannelName, [MarshalAs(UnmanagedType.LPArray)] ushort[] Range);
        [DllImport("clogger_api.dll")] static extern int LoggerSetScaleConversion(short AppId, ushort SequenceNo, ushort ScaleEnable, float MinData, float MaxData, float MinScale, float MaxScale);
        [DllImport("clogger_api.dll")] static extern int LoggerGetScaleConversion(short AppId, ushort SequenceNo, ref ushort ScaleEnable, ref float MinData, ref float MaxData, ref float MinScale, ref float MaxScale);
        [DllImport("clogger_api.dll")] static extern int LoggerSetSamplingClock(short AppId, ushort ClockType, ushort SamplingClockUnit, double SamplingClock);
        [DllImport("clogger_api.dll")] static extern int LoggerGetSamplingClock(short AppId, ref ushort ClockType, ushort SamplingClockUnit, ref double SamplingClock);
        [DllImport("clogger_api.dll")] static extern int LoggerSetSamplingSetting(short AppId, uint SamplingTimes, float ScanClock, uint RepeatTimes, ushort StartTriggerType, ushort StopTriggerType, uint DelayTime);
        [DllImport("clogger_api.dll")] static extern int LoggerGetSamplingSetting(short AppId, ref uint SamplingTimes, ref float ScanClock, ref uint RepeatTimes, ref ushort StartTriggerType, ref ushort StopTriggerType, ref uint DelayTime);
        [DllImport("clogger_api.dll")] static extern int LoggerSetAnalogLevelTrigger(short AppId, ushort StartStopTrigger, ushort StartStopTriggerEdge, ushort SequenceNo, float BorderValue);
        [DllImport("clogger_api.dll")] static extern int LoggerGetAnalogLevelTrigger(short AppId, ushort StartStopTrigger, ref ushort StartStopTriggerEdge, ref ushort SequenceNo, ref float BorderValue);
        [DllImport("clogger_api.dll")] static extern int LoggerSetAnalogRangeTrigger(short AppId, ushort StartStopTrigger, ushort SequenceNo, float Upper_BorderValue, float Lower_BorderValue, uint Start_Times);
        [DllImport("clogger_api.dll")] static extern int LoggerGetAnalogRangeTrigger(short AppId, ushort StartStopTrigger, ref ushort SequenceNo, ref float Upper_BorderValue, ref float Lower_BorderValue, ref uint Start_Times);
        [DllImport("clogger_api.dll")] static extern int LoggerSetTimeTrigger(short AppId, ushort StartStopTrigger, ushort TimeType, uint Time1, uint Time2, uint Time3);
        [DllImport("clogger_api.dll")] static extern int LoggerGetTimeTrigger(short AppId, ushort StartStopTrigger, ref ushort TimeType, ref uint Time1, ref uint Time2, ref uint Time3);
        [DllImport("clogger_api.dll")] static extern int LoggerSetAutoSave(short AppId, ushort ExcelEnable, ushort AutosaveType, string FilePath);
        [DllImport("clogger_api.dll")] static extern int LoggerGetAutoSave(short AppId, ref ushort ExcelEnable, ref ushort AutosaveType, System.Text.StringBuilder FilePath);
        [DllImport("clogger_api.dll")] static extern int LoggerCaptureScreen(short AppId, ushort WindowNo, ushort ImageArea, string FilePath);
        [DllImport("clogger_api.dll")] static extern int LoggerSetGraphZoom(short AppId, ushort WindowNo, ushort Axis, ushort Zoom);
        [DllImport("clogger_api.dll")] static extern int LoggerGetGraphZoom(short AppId, ushort WindowNo, ushort Axis, ref ushort Zoom);
        [DllImport("clogger_api.dll")] static extern int LoggerSetGraphChannel(short AppId, ushort WindowNo, ushort SequenceNo, ushort ChannelEnable, ushort Activate, ushort DisplayDot);
        [DllImport("clogger_api.dll")] static extern int LoggerGetGraphChannel(short AppId, ushort WindowNo, ushort SequenceNo, ref ushort ChannelEnable, ref ushort Activate, ref ushort DisplayDot);
        [DllImport("clogger_api.dll")] static extern int LoggerSetGraph(short AppId, ushort WindowNo, ushort TimeUnit, ushort Digit, ushort Area2Enable, ushort YaxisMagnificationEnable, ushort ChannelDispEnable, ushort AutoScrollEnable);
        [DllImport("clogger_api.dll")] static extern int LoggerGetGraph(short AppId, ushort WindowNo, ref ushort TimeUnit, ref ushort Digit, ref ushort Area2Enable, ref ushort YaxisMagnificationEnable, ref ushort ChannelDispEnable, ref ushort AutoScrollEnable);
        [DllImport("clogger_api.dll")] static extern int LoggerSetGraphLabelText(short AppId, ushort WindowNo, ushort TargetItem, ushort TitleEnable, string TitleText);
        [DllImport("clogger_api.dll")] static extern int LoggerGetGraphLabelText(short AppId, ushort WindowNo, ushort TargetItem, ref ushort TitleEnable, System.Text.StringBuilder TitleText);
        [DllImport("clogger_api.dll")] static extern int LoggerSetMemoryOption(short AppId, ushort MemorySize);
        [DllImport("clogger_api.dll")] static extern int LoggerGetMemoryOption(short AppId, ref ushort MemorySize);
        [DllImport("clogger_api.dll")] static extern int LoggerGraphWindowOperation(short AppId, ushort WindowOperation, ushort Target, ushort WindowNo);
        [DllImport("clogger_api.dll")] unsafe static extern int LoggerSetNotifyEvent(short AppId, IntPtr pProc, uint Event, void* Param);
        [DllImport("clogger_api.dll")] static extern int LoggerGetNotifyEvent(short AppId, ref uint Event);
        [DllImport("clogger_api.dll")] static extern int LoggerGetErrorString(int ErrorCode, System.Text.StringBuilder ErrorString);
        [DllImport("clogger_api.dll")] static extern int LoggerGetSamplingData(short AppId, ref uint SamplingTimes, [MarshalAs(UnmanagedType.LPArray)] float[] Data);
        [DllImport("clogger_api.dll")] static extern int LoggerGetSamplingDataBin(short AppId, ref uint SamplingTimes, [MarshalAs(UnmanagedType.LPArray)] uint[] Data);
        [DllImport("clogger_api.dll")] static extern int LoggerSetEventSamplingTimes(short AppId, uint SamplingData);
        [DllImport("clogger_api.dll")] static extern int LoggerGetEventSamplingTimes(short AppId, ref uint SamplingData);
        [DllImport("clogger_api.dll")] static extern int LoggerGetStoredSamplingCount(short AppId, ref uint StoredSamplingCount);
        [DllImport("clogger_api.dll")] static extern int LoggerGetTotalSamplingCount(short AppId, ref uint  SamplingCount);
        [DllImport("clogger_api.dll")] static extern int LoggerSetAcquiredMode(short AppId, ushort Mode);
        [DllImport("clogger_api.dll")] static extern int LoggerGetAcquiredMode(short AppId, ref ushort Mode);
        [DllImport("clogger_api.dll")] static extern int LoggerMoveGraphPos(short AppId, ushort WindowNo, ushort Axis, int Distance, ref uint Status);

        // Constructor
        public CLogger()
        {
        }


        public int OpenApplication(string DeviceName, out short AppId, ushort OpenMode)
        {
            AppId = 0;
            int ret = LoggerOpenApplication(DeviceName, ref AppId, OpenMode);
            return ret;
        }

        public int CloseApplication(short AppId, out uint Status)
        {
            Status = 0;
            int ret = LoggerCloseApplication(AppId, ref Status);
            return ret;
        }

        public int StartOperation(short AppId, out uint Status)
        {
            Status = 0;
            int ret = LoggerStartOperation(AppId, ref Status);
            return ret;
        }

        public int StopOperation(short AppId)
        {
            int ret = LoggerStopOperation(AppId);
            return ret;
        }

        public int GetApplicationStatus(short AppId, out uint Status)
        {
            Status = 0;
            int ret = LoggerGetApplicationStatus(AppId, ref Status);
            return ret;
        }

        public int ExportSettingFile(short AppId, string FilePath)
        {
            int ret = LoggerExportSettingFile(AppId, FilePath);
            return ret;
        }

        public int ImportSettingFile(short AppId, string FilePath, out uint Status)
        {
            Status = 0;
            int ret = LoggerImportSettingFile(AppId, FilePath, ref Status);
            return ret;
        }

        public int SaveDataFile(short AppId, string FilePath, short Param1, short Param2)
        {
            int ret = LoggerSaveDataFile(AppId, FilePath, Param1, Param2);
            return ret;
        }
        public int LoadDataFile(short AppId, string FilePath)
        {

            int ret = LoggerLoadDataFile(AppId, FilePath);
            return ret;
        }
        public int SetDeviceName(short AppId, string DeviceName)
        {

            int ret = LoggerSetDeviceName(AppId, DeviceName);
            return ret;
        }
        public int GetDeviceName(short AppId, out string DeviceName)
        {
            DeviceName = new String('0', 1);
            System.Text.StringBuilder devicenamestring = new System.Text.StringBuilder(256);

            int ret = LoggerGetDeviceName(AppId, devicenamestring);
            if(ret == 0)
            {
                DeviceName = devicenamestring.ToString();
            }
            return ret;
        }
        public int SetChannelSetting(short AppId, ushort InputType, ushort SequenceNum, ushort[] ChannelNo, byte[] ChannelName, ushort[] Range)
        {

            int ret = LoggerSetChannelSetting(AppId, InputType, SequenceNum, ChannelNo, ChannelName, Range);
            return ret;
        }
        public int GetChannelSetting(short AppId, out ushort InputType, ref ushort SequenceNum, ushort[] ChannelNo, byte[] ChannelName, ushort[] Range)
        {
            InputType = 0;
            int ret = LoggerGetChannelSetting(AppId, ref InputType, ref SequenceNum, ChannelNo, ChannelName, Range);
            return ret;
        }
        public int SetScaleConversion(short AppId, ushort SequenceNo, ushort ScaleEnable, float MinData, float MaxData, float MinScale, float MaxScale)
        {

            int ret = LoggerSetScaleConversion(AppId, SequenceNo, ScaleEnable, MinData, MaxData, MinScale, MaxScale);
            return ret;
        }
        public int GetScaleConversion(short AppId, ushort SequenceNo, out ushort ScaleEnable, out float MinData, out float MaxData, out float MinScale, out float MaxScale)
        {
            ScaleEnable = 0;
            MinData = 0;
            MaxData = 0;
            MinScale = 0;
            MaxScale = 0;
            int ret = LoggerGetScaleConversion(AppId, SequenceNo, ref ScaleEnable, ref MinData, ref MaxData, ref MinScale, ref MaxScale);
            return ret;
        }
        public int SetSamplingClock(short AppId, ushort ClockType, ushort SamplingClockUnit, double SamplingClock)
        {

            int ret = LoggerSetSamplingClock(AppId, ClockType, SamplingClockUnit, SamplingClock);
            return ret;
        }
        public int GetSamplingClock(short AppId, out ushort ClockType, ushort SamplingClockUnit, out double SamplingClock)
        {
            ClockType = 0;
            SamplingClock = 0;
            int ret = LoggerGetSamplingClock(AppId, ref ClockType, SamplingClockUnit, ref SamplingClock);
            return ret;
        }
        public int SetSamplingSetting(short AppId, uint SamplingTimes, float ScanClock, uint RepeatTimes, ushort StartTriggerType, ushort StopTriggerType, uint DelayTime)
        {

            int ret = LoggerSetSamplingSetting(AppId, SamplingTimes, ScanClock, RepeatTimes, StartTriggerType, StopTriggerType, DelayTime);
            return ret;
        }
        public int GetSamplingSetting(short AppId, out uint SamplingTimes, out float ScanClock, out uint RepeatTimes, out ushort StartTriggerType, out ushort StopTriggerType, out uint DelayTime)
        {
            SamplingTimes = 0;
            ScanClock = 0;
            RepeatTimes = 0;
            StartTriggerType = 0;
            StopTriggerType = 0;
            DelayTime = 0;
            int ret = LoggerGetSamplingSetting(AppId, ref SamplingTimes, ref ScanClock, ref RepeatTimes, ref StartTriggerType, ref StopTriggerType, ref DelayTime);
            return ret;
        }
        public int SetAnalogLevelTrigger(short AppId, ushort StartStopTrigger, ushort StartStopTriggerEdge, ushort SequenceNo, float BorderValue)
        {

            int ret = LoggerSetAnalogLevelTrigger(AppId, StartStopTrigger, StartStopTriggerEdge, SequenceNo, BorderValue);
            return ret;
        }
        public int GetAnalogLevelTrigger(short AppId, ushort StartStopTrigger, out ushort StartStopTriggerEdge, out ushort SequenceNo, out float BorderValue)
        {
            StartStopTriggerEdge = 0;
            SequenceNo = 0;
            BorderValue = 0;
            int ret = LoggerGetAnalogLevelTrigger(AppId, StartStopTrigger, ref StartStopTriggerEdge, ref SequenceNo, ref BorderValue);
            return ret;
        }
        public int SetAnalogRangeTrigger(short AppId, ushort StartStopTrigger, ushort SequenceNo, float Upper_BorderValue, float Lower_BorderValue, uint Start_Times)
        {

            int ret = LoggerSetAnalogRangeTrigger(AppId, StartStopTrigger, SequenceNo, Upper_BorderValue, Lower_BorderValue, Start_Times);
            return ret;
        }
        public int GetAnalogRangeTrigger(short AppId, ushort StartStopTrigger, out ushort SequenceNo, out float Upper_BorderValue, out float Lower_BorderValue, out uint Start_Times)
        {
            SequenceNo = 0;
            Upper_BorderValue = 0;
            Lower_BorderValue = 0;
            Start_Times = 0;

            int ret = LoggerGetAnalogRangeTrigger(AppId, StartStopTrigger, ref SequenceNo, ref Upper_BorderValue, ref Lower_BorderValue, ref Start_Times);
            return ret;
        }
        public int SetTimeTrigger(short AppId, ushort StartStopTrigger, ushort TimeType, uint Time1, uint Time2, uint Time3)
        {

            int ret = LoggerSetTimeTrigger(AppId, StartStopTrigger, TimeType, Time1, Time2, Time3);
            return ret;
        }
        public int GetTimeTrigger(short AppId, ushort StartStopTrigger, out ushort TimeType, out uint Time1, out uint Time2, out uint Time3)
        {
            TimeType = 0;
            Time1 = 0;
            Time2 = 0;
            Time3 = 0;
            int ret = LoggerGetTimeTrigger(AppId, StartStopTrigger, ref TimeType, ref Time1, ref Time2, ref Time3);
            return ret;
        }
        public int SetAutoSave(short AppId, ushort ExcelEnable, ushort AutosaveType, string FilePath)
        {

            int ret = LoggerSetAutoSave(AppId, ExcelEnable, AutosaveType, FilePath);
            return ret;
        }
        public int GetAutoSave(short AppId, out ushort ExcelEnable, out ushort AutosaveType, out string FilePath)
        {
            ExcelEnable = 0;
            AutosaveType = 0;
            FilePath = new String('0', 1);
            System.Text.StringBuilder filepathstring = new System.Text.StringBuilder(256);
            int ret = LoggerGetAutoSave(AppId, ref ExcelEnable, ref AutosaveType, filepathstring);
            if(ret == 0)
            {
                FilePath = filepathstring.ToString();
            }
            return ret;
        }
        public int CaptureScreen(short AppId, ushort WindowNo, ushort ImageArea, string FilePath)
        {

            int ret = LoggerCaptureScreen(AppId, WindowNo, ImageArea, FilePath);
            return ret;
        }
        public int SetGraphZoom(short AppId, ushort WindowNo, ushort Axis, ushort Zoom)
        {

            int ret = LoggerSetGraphZoom(AppId, WindowNo, Axis, Zoom);
            return ret;
        }
        public int GetGraphZoom(short AppId, ushort WindowNo, ushort Axis, out ushort Zoom)
        {
            Zoom = 0;
            int ret = LoggerGetGraphZoom(AppId, WindowNo, Axis, ref Zoom);
            return ret;
        }
        public int SetGraphChannel(short AppId, ushort WindowNo, ushort SequenceNo, ushort ChannelEnable, ushort Activate, ushort DisplayDot)
        {

            int ret = LoggerSetGraphChannel(AppId, WindowNo, SequenceNo, ChannelEnable, Activate, DisplayDot);
            return ret;
        }
        public int GetGraphChannel(short AppId, ushort WindowNo, ushort SequenceNo, out ushort ChannelEnable, out ushort Activate, out ushort DisplayDot)
        {
            ChannelEnable = 0;
            Activate = 0;
            DisplayDot = 0;
            int ret = LoggerGetGraphChannel(AppId, WindowNo, SequenceNo, ref ChannelEnable, ref Activate, ref DisplayDot);
            return ret;
        }
        public int SetGraph(short AppId, ushort WindowNo, ushort TimeUnit, ushort Digit, ushort Area2Enable, ushort YaxisMagnificationEnable, ushort ChannelDispEnable, ushort AutoScrollEnable)
        {

            int ret = LoggerSetGraph(AppId, WindowNo, TimeUnit, Digit, Area2Enable, YaxisMagnificationEnable, ChannelDispEnable, AutoScrollEnable);
            return ret;
        }
        public int GetGraph(short AppId, ushort WindowNo, out ushort TimeUnit, out ushort Digit, out ushort Area2Enable, out ushort YaxisMagnificationEnable, out ushort ChannelDispEnable, out ushort AutoScrollEnable)
        {
            TimeUnit = 0;
            Digit = 0;
            Area2Enable = 0;
            YaxisMagnificationEnable = 0;
            ChannelDispEnable = 0;
            AutoScrollEnable = 0;
            int ret = LoggerGetGraph(AppId, WindowNo, ref TimeUnit, ref Digit, ref Area2Enable, ref YaxisMagnificationEnable, ref ChannelDispEnable, ref AutoScrollEnable);
            return ret;
        }
        public int SetGraphLabelText(short AppId, ushort WindowNo, ushort TargetItem, ushort TitleEnable, string TitleText)
        {

            int ret = LoggerSetGraphLabelText(AppId, WindowNo, TargetItem, TitleEnable, TitleText);
            return ret;
        }
        public int GetGraphLabelText(short AppId, ushort WindowNo, ushort TargetItem, out ushort TitleEnable, out string TitleText)
        {
            TitleEnable = 0;
            TitleText = new String('0', 1);
            System.Text.StringBuilder titletextstring = new System.Text.StringBuilder(256);
            int ret = LoggerGetGraphLabelText(AppId, WindowNo, TargetItem, ref TitleEnable, titletextstring);
            if(ret == 0)
            {
                TitleText = titletextstring.ToString();
            }
            return ret;
        }
        public int SetMemoryOption(short AppId, ushort MemorySize)
        {

            int ret = LoggerSetMemoryOption(AppId, MemorySize);
            return ret;
        }
        public int GetMemoryOption(short AppId, out ushort MemorySize)
        {
            MemorySize = 0;
            int ret = LoggerGetMemoryOption(AppId, ref MemorySize);
            return ret;
        }
        public int GraphWindowOperation(short AppId, ushort WindowOperation, ushort Target, ushort WindowNo)
        {

            int ret = LoggerGraphWindowOperation(AppId, WindowOperation, Target, WindowNo);
            return ret;
        }
        unsafe public int SetNotifyEvent(short AppId, IntPtr pProc, uint Event, void* Param)
        {
            int ret = LoggerSetNotifyEvent(AppId, pProc, Event, Param);
            return ret;
        }

        public int GetNotifyEvent(short AppId, out uint Event)
        {
            Event = 0;
            int ret = LoggerGetNotifyEvent(AppId, ref Event);
            return ret;
        }
        public int GetErrorString(int ErrorCode, out string ErrorString)
        {
            ErrorString = new String('0', 1);
            System.Text.StringBuilder errorstring = new System.Text.StringBuilder(256);
            int ret = LoggerGetErrorString(ErrorCode, errorstring);
            if (ret == 0)
            {
                ErrorString = errorstring.ToString();
            }

            return ret;
        }
        public int GetSamplingData(short AppId, ref uint SamplingTimes, ref float[] Data)
        {

            int ret = LoggerGetSamplingData(AppId, ref SamplingTimes, Data);
            return ret;
        }
        public int GetSamplingDataBin(short AppId, ref uint SamplingTimes, ref uint[] Data)
        {
            int ret = LoggerGetSamplingDataBin(AppId, ref SamplingTimes, Data);
            return ret;
        }
        public int SetEventSamplingTimes(short AppId, uint SamplingData)
        {

            int ret = LoggerSetEventSamplingTimes(AppId, SamplingData);
            return ret;
        }
        public int GetEventSamplingTimes(short AppId, out uint SamplingData)
        {
            SamplingData = 0;
            int ret = LoggerGetEventSamplingTimes(AppId, ref SamplingData);
            return ret;
        }
        public int GetStoredSamplingCount(short AppId, out uint StoredSamplingCount)
        {
            StoredSamplingCount = 0;
            int ret = LoggerGetStoredSamplingCount(AppId, ref StoredSamplingCount);
            return ret;
        }
        public int GetTotalSamplingCount(short AppId, out uint SamplingCount)
        {
            SamplingCount = 0;
            int ret = LoggerGetTotalSamplingCount(AppId, ref SamplingCount);
            return ret;
        }
        public int SetAcquiredMode(short AppId, ushort Mode)
        {

            int ret = LoggerSetAcquiredMode(AppId, Mode);
            return ret;
        }
        public int GetAcquiredMode(short AppId, out ushort Mode)
        {
            Mode = 0;
            int ret = LoggerGetAcquiredMode(AppId, ref Mode);
            return ret;
        }
        public int MoveGraphPos(short AppId, ushort WindowNo, ushort Axis, int Distance, out uint Status)
        {
            Status = 0;
            int ret = LoggerMoveGraphPos(AppId, WindowNo, Axis, Distance, ref Status);
            return ret;
        }

    }
}
