// =================================================================
// \brief     This class provide API for open.dll
// \copyright Copyright (C) Siemens AG 2024 All Rights Reserved.
//            Confidential
// =================================================================

using System;
using System.Runtime.InteropServices;

namespace Siemens.SinumerikOne.OpenClientSample
{
   public class OpenApiWrapper
   {
      public enum OpenReturnCodes : int
      {
         /// <summary>
         /// Call was successful 
         /// </summary>
         Ok                                              =  0,
         
         // --------- Application control and Connection ---------
         /// <summary>
         /// An internal error occurred. 
         /// </summary>
         ErrorInternal                                   = -1001,
         /// <summary>
         /// SINUMERIK ONE install path not found in registry. 
         /// </summary>
         ErrorVcNotFound                                 = -1002,
         /// <summary>
         /// CreateProcess of SINUMERIK ONE instance failed. 
         /// </summary>
         ErrorCreateProcess                              = -1003,
         /// <summary>
         /// An SINUMERIK ONE instance is already running. 
         /// </summary>
         ErrorAlreadyRunning                             = -1004,
         /// <summary>
         /// SINUMERIK ONE close failed. 
         /// </summary>
         ErrorCloseFailed                                = -1005,
         /// <summary>
         /// SINUMERIK ONE instance not found. 
         /// </summary>
         ErrorInstanceNotFound                           = -1006,
         /// <summary>
         /// The connection to SINUMERIK ONE is occupied. 
         /// </summary>
         ErrorInstanceBusy                               = -1007,
         /// <summary>
         /// No connection to  SINUMERIK ONE. 
         /// </summary>
         ErrorNoConnection                               = -1008,
         /// <summary>
         /// SINUMERIK ONE is not ready for communication. 
         /// </summary>
         ErrorVcNotReady                                 = -1009,
         /// <summary>
         /// Invalid parameter. 
         /// </summary>
         ErrorInvalidParameter                           = -1010,
         /// <summary>
         /// No valid license found. This code is deprecated !
         /// </summary>
         ErrorNoLicenseDeprecated                        = -1011,
         /// <summary>
         /// Connection to SINUMERIK ONE has been closed. 
         /// </summary>
         ErrorConnectionClosed                           = -1012,
         /// <summary>
         /// S7DOS simulation mode is active. 
         /// </summary>
         ErrorS7DosSimulationActive                      = -1013,
         /// <summary>
         /// Version incompatible. 
         /// </summary>
         ErrorVersionIncompatible                        = -1014,
         /// <summary>
         /// The called feature is not supported by the currently used backend. 
         /// </summary>
         ErrorNotSupportedByBackend                      = -1015,
         /// <summary>
         /// At least one Window could not be embedded (blackbox mode). 
         /// </summary>
         WarningWindowEmbedding                          =  1002,
         /// <summary>
         /// The Client has a lower(,but comnpatible) version than the Middleware. 
         /// </summary>
         WarningVersionClientOld                         =  1003,
         /// <summary>
         /// The Middleware has a lower(but comnpatible) version than the Client. 
         /// </summary>
         WarningVersionMiddlewareOld                     =  1004,
         /// <summary>
         /// Detected a lost client connection. Client has to reconnect. 
         /// </summary>
         WarningConnectionCorrupted                      =  1005,
         
         // --------- File handling (VCPs, startprofiles, etc.) ---------
         /// <summary>
         /// The file could not be found. 
         /// </summary>
         ErrorFileNotFound                               = -2001,
         /// <summary>
         /// There is a project already open. 
         /// </summary>
         ErrorProjectOpen                                = -2002,
         /// <summary>
         /// Loading the vcp file failed. 
         /// </summary>
         ErrorLoadFailed                                 = -2003,
         /// <summary>
         /// No project open. 
         /// </summary>
         ErrorNoProjectOpen                              = -2004,
         /// <summary>
         /// File is write protected. 
         /// </summary>
         ErrorWriteProtected                             = -2005,
         /// <summary>
         /// Simulation is running. 
         /// </summary>
         ErrorSimRunning                                 = -2006,
         /// <summary>
         /// Saving the file failed. 
         /// </summary>
         ErrorWriteFailed                                = -2007,
         /// <summary>
         /// Closing the project failed. 
         /// </summary>
         ErrorVcpCloseFailed                             = -2008,
         /// <summary>
         /// The file is invalid. 
         /// </summary>
         ErrorInvalidFile                                = -2009,
         /// <summary>
         /// The selected cnc software is not available. 
         /// </summary>
         ErrorCncSwUnavailable                           = -2010,
         /// <summary>
         /// The file could not be created. 
         /// </summary>
         ErrorFileCreationFailed                         = -2011,
         /// <summary>
         /// The frontend not installed. 
         /// </summary>
         ErrorFrontendNotInstalled                       = -2012,
         /// <summary>
         /// The no license for the frontend. This code is deprecated !
         /// </summary>
         ErrorFrontendNotLicensedDeprecated              = -2013,
         /// <summary>
         /// The path to the project file is too long. 
         /// </summary>
         ErrorFilePathTooLong                            = -2014,
         /// <summary>
         /// The selected nck scaling is invalid. 
         /// </summary>
         ErrorInvalidNckscaling                          = -2015,
         /// <summary>
         /// The selected ncu number is invalid. 
         /// </summary>
         ErrorInvalidNcunumber                           = -2016,
         
         // --------- Simulation Control ---------
         /// <summary>
         /// Starting the simulation failed. 
         /// </summary>
         ErrorStartSimFailed                             = -3001,
         /// <summary>
         /// Stopping the simulation failed. 
         /// </summary>
         ErrorStopSimFailed                              = -3002,
         /// <summary>
         /// Reseting the simulation failed. 
         /// </summary>
         ErrorResetSimFailed                             = -3004,
         /// <summary>
         /// Reseting the simulation failed. 
         /// </summary>
         ErrorSimSpeedInvalid                            = -3005,
         /// <summary>
         /// Simulation is not available. 
         /// </summary>
         ErrorSimNotAvailable                            = -3006,
         /// <summary>
         /// Simulation is not running. 
         /// </summary>
         ErrorSimNotRunning                              = -3007,
         /// <summary>
         /// Simulation is running. 
         /// </summary>
         SimRunning                                      =  3001,
         /// <summary>
         /// Simulation is not running. 
         /// </summary>
         SimNotRunning                                   =  3002,
         
         // --------- Synchronized Operation ---------
         /// <summary>
         /// The event is unknown.
         /// </summary>
         ErrorEventUnknown                               = -4001,
         /// <summary>
         /// No events are registered.
         /// </summary>
         ErrorNoEventsRegistered                         = -4002,
         /// <summary>
         /// The simulation got interrupted.
         /// </summary>
         ErrorSimInterrupted                             = -4003,
         
         // --------- Data Access ---------
         /// <summary>
         /// Unknown dictionary entry. 
         /// </summary>
         ErrorUnknownElement                             = -5001,
         /// <summary>
         /// The dictionary id is invalid. 
         /// </summary>
         ErrorInvalidDictId                              = -5002,
         /// <summary>
         /// Not enough memory for the data. 
         /// </summary>
         ErrorInsufficientMemory                         = -5003,
         /// <summary>
         /// Elemente is not an array. 
         /// </summary>
         ErrorNoarray                                    = -5004,
         /// <summary>
         /// Wrong type for the data. 
         /// </summary>
         ErrorWrongType                                  = -5005,
         /// <summary>
         /// Wrong accesrights for the data. 
         /// </summary>
         ErrorInsufficientRights                         = -5006,
         /// <summary>
         /// The application is not in the wait state  
         /// </summary>
         ErrorNotInWait                                  = -5007,
         /// <summary>
         /// No further data available. 
         /// </summary>
         NoMoreData                                      =  5001,
         
         // --------- File Operations ---------
         /// <summary>
         /// The domain for file system operation is invalid. 
         /// </summary>
         ErrorFileOpInvalidDomain                        = -6001,
         /// <summary>
         /// The source path for file system operation is not absolute. 
         /// </summary>
         ErrorFileOpSourcePathNotAbsolute                = -6002,
         /// <summary>
         /// The source file for file system operation does not exist. 
         /// </summary>
         ErrorFileOpSourceFileNotExists                  = -6003,
         /// <summary>
         /// The destination path for file system operation is not absolute. 
         /// </summary>
         ErrorFileOpDestinationPathNotAbsolute           = -6004,
         /// <summary>
         /// The destination file or directory for file system operation already exsists. 
         /// </summary>
         ErrorFileOpDestinationAlreadyExists             = -6005,
         /// <summary>
         /// The destination directory for file system operation does not exists. 
         /// </summary>
         ErrorFileOpDestinationDirectoryNotExists        = -6006,
         /// <summary>
         /// The directory for file system operation does not exists. 
         /// </summary>
         ErrorFileOpDirectoryNotExists                   = -6007,
         /// <summary>
         /// The directory for file system operation is not empty. 
         /// </summary>
         ErrorFileOpDirectoryNotEmpty                    = -6008,
         /// <summary>
         /// A file or a part program can't select. 
         /// </summary>
         ErrorFileSelectNotPossible                      = -6009,
         /// <summary>
         /// The channel does not exists. 
         /// </summary>
         ErrorChannelNotExists                           = -6010,
         /// <summary>
         /// The file is in edit mode. 
         /// </summary>
         ErrorFileUsed                                   = -6011,
         
         // --------- License handling ---------
         /// <summary>
         /// General error, licensing failed. 
         /// </summary>
         ErrorLicenseNoLicense                           = -7001,
         /// <summary>
         /// The application mentioned in the license file, does not match any known application in the xMVM context. 
         /// </summary>
         ErrorLicenseUnknownApplication                  = -7002,
         /// <summary>
         /// The frontend is not CMVM or RMVM. 
         /// </summary>
         ErrorLicenseUnknownFrontend                     = -7003,
         /// <summary>
         /// The connection to the license server could not be established. 
         /// </summary>
         ErrorLicenseNoConnection                        = -7004,
         /// <summary>
         /// The license handler could not be instantiated. 
         /// </summary>
         ErrorLicenseNoLicenseHandler                    = -7005,
         /// <summary>
         /// The Server is busy, cant read, cant write. 
         /// </summary>
         ErrorLicenseErrorAtServerSite                   = -7006,
         /// <summary>
         /// The license for a particular feature is not available. 
         /// </summary>
         ErrorLicenseOptionalLicenseKeyNotAvailable      = -7007,
         /// <summary>
         /// The license for a particular feature could not be granted. 
         /// </summary>
         ErrorLicenseOptionalLicenseKeyNotGranted        = -7008,
         /// <summary>
         /// The license for a particular feature could not be locked at the license server. 
         /// </summary>
         ErrorLicenseOptionalLicenseNotAqcuired          = -7009,
         /// <summary>
         /// The validation of the license file failed. 
         /// </summary>
         ErrorLicenseOptionalLicenseCheckFailed          = -7010,
         /// <summary>
         /// The acquistion of a license was not successfull. 
         /// </summary>
         ErrorLicenseKeyNotAvailable                     = -7011,
         /// <summary>
         /// The main license key could not be granted. 
         /// </summary>
         ErrorLicenseKeyGrantFailed                      = -7012,
         /// <summary>
         /// The main license key could not be released. 
         /// </summary>
         ErrorLicenseKeyReleaseFailed                    = -7013,
         /// <summary>
         /// The main license key is invalid. 
         /// </summary>
         ErrorLicenseInvalid                             = -7014,
         /// <summary>
         /// The license key is already in use. 
         /// </summary>
         ErrorLicenseAlreadyInUse                        = -7015,
         /// <summary>
         /// The validation of the license key failed. 
         /// </summary>
         ErrorLicenseCheckFailed                         = -7016,
         /// <summary>
         /// All licenses from the license pool are currently in use. 
         /// </summary>
         ErrorLicenseAllLicensesInUse                    = -7017,
         /// <summary>
         /// The type of the used license is unknown. 
         /// </summary>
         ErrorLicenseUnknownLicense                      = -7018,
      }

      public enum OpenDictionaryElementType
      {
         Bool                    = 1,
         Integer8Bit             = 2,
         UInteger8Bit            = 3,
         Integer16Bit            = 4,
         UInteger16Bit           = 5,
         Integer32Bit            = 6,
         UInteger32Bit           = 7,
         Integer64Bit            = 8,
         UInteger64Bit           = 9,
         Double                  = 10,
         String                  = 11,
         IntegerArray32Bit       = 12,
         UIntegerArray64Bit      = 13,
         BoolArray               = 14,
         DoubleArray             = 15,
         StringArray             = 16,
         UIntegerArray32Bit      = 17,
         UIntegerArray16Bit      = 18,
         UIntegerArray8Bit       = 19,
      }

      public enum OpenEventMaskDefinition : ulong
      {
         Unknown                                = 0x0000000000000000,
         NckFirstIpo                            = 0x0000000000000008,
         NckBootReady                           = 0x0000000000000004,
         NckIpo                                 = 0x0000000000000001,
         NckChannelNewMotion                    = 0x0000000000000100,
         NckChannelNewBlock                     = 0x0000000000000200,
         NckChannelConfigChanged                = 0x0000000000000400,
         NckChannelStartPositioningMotion       = 0x0000000000000800,
         NckChannelEndPositioningMotion         = 0x0000000000001000,
         NckChannelLengthSlicePath              = 0x0000000000001001,
         NckChannelLengthSlicePositioning       = 0x0000000000001002,
         NckChannelAngleSlicePositioning        = 0x0000000000001003,
         NckChannelAngleSliceOrientation        = 0x0000000000001004,
         NckChannelStateChanged                 = 0x0000000000001005,
         NckChannelProgramFinished              = 0x0000000000001006,
         PlcOb1                                 = 0x0000000000010000,
         PlcHwConfigChanged                     = 0x0000000000020000,
         PlcAcyclicCommunication                = 0x0000000000040000,
         ContentChanged                         = 0x0001000000000000,
         ResetStarted                           = 0x0002000000000000,
         ResetFinished                          = 0x0004000000000000,
      }

      public enum OpenAxisMode
      {
         /// <summary>
         /// axisMode undefined
         /// </summary>
         None = 0,
         /// <summary>
         /// interpolation mode
         /// </summary>
         Interpolation = 1,
         /// <summary>
         /// positioning mode
         /// </summary>
         Positioning = 2,
         /// <summary>
         /// speed mode turning left
         /// </summary>
         SpeedLeft = 3,
         /// <summary>
         /// speed mode turning right
         /// </summary>
         SpeedRight = 4,
         /// <summary>
         /// speed mode stopped
         /// </summary>
         SpeedStop = 5,
         /// <summary>
         /// following axis - no specified type
         /// </summary>
         Following = 6,
      }

      public enum OpenAxisReferenceState
      {
         /// <summary>
         /// reference state undefined
         /// </summary>
         None = 0,
         /// <summary>
         /// not referenced
         /// </summary>
         NotReferenced = 1,
         /// <summary>
         /// referenced
         /// </summary>
         Referenced = 2,
         /// <summary>
         /// referencing not required
         /// </summary>
         ReferenceNotRequired = 3,
      }

      public enum OpenMotionType
      {
         /// <summary>
         /// value undefined / OEMIPO1 / OEMIPO2 / Involute
         /// </summary>
         None = 0,
         /// <summary>
         /// rapid motion independent from $AC_G0MODE
         /// </summary>
         Rapid = 1,
         /// <summary>
         /// linear motion
         /// </summary>
         Linear = 2,
         /// <summary>
         /// circle motion G2 / G3 / CIP / CT
         /// </summary>
         Circle = 3,
         /// <summary>
         /// A/B/C-Spline / Poly
         /// </summary>
         Spline = 4,
         /// <summary>
         /// G33 / G331 / G332 / G34 / G35
         /// </summary>
         Thread = 5,
         /// <summary>
         /// involute INVCW / INVCCW
         /// </summary>
         Involute = 6,
      }

      public enum OpenCircleDirection
      {
         /// <summary>
         /// value undefined
         /// </summary>
         None = 0,
         /// <summary>
         /// clockwise
         /// </summary>
         Cw = 1,
         /// <summary>
         /// counter clockwise
         /// </summary>
         Ccw = 2,
      }

      public enum OpenOperatingMode
      {
         /// <summary>
         /// no operating mode
         /// </summary>
         None = 0,
         /// <summary>
         /// operating mode auto
         /// </summary>
         Auto = 1,
         /// <summary>
         /// operating jog
         /// </summary>
         Jog = 2,
         /// <summary>
         /// operating mode mda
         /// </summary>
         Mda = 3,
      }

      public enum OpenChannelState
      {
         /// <summary>
         /// no channel state
         /// </summary>
         None = 0,
         /// <summary>
         /// channel state activated
         /// </summary>
         Activated = 1,
         /// <summary>
         /// channel state stopped
         /// </summary>
         Stopped = 2,
         /// <summary>
         /// channel state reseted
         /// </summary>
         Reseted = 3,
      }

      public enum OpenAxisType
      {
         /// <summary>
         /// axisType undefined
         /// </summary>
         None = 0,
         /// <summary>
         /// linear axis
         /// </summary>
         Linear = 1,
         /// <summary>
         /// round axis
         /// </summary>
         Rotatory = 2,
         /// <summary>
         /// modulo axis
         /// </summary>
         Modulo = 3,
         /// <summary>
         /// spindle axis
         /// </summary>
         Spindle = 4,
      }


      public enum OpenProjectStates
      {
         Closed                  = 1,
         Opening                 = 2,
         Open                    = 3,
         Booting                 = 4,
         RunningOrPaused         = 5,
         ShuttingDown            = 6,
         Closing                 = 7,
         Resetting               = 8,
         Saving                  = 9,
         Error                   = 10,
      }

      [DllImport("open.dll", EntryPoint = "startApplication", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes StartApplication(string strProfileFileName);

      [DllImport("open.dll", EntryPoint = "stopApplication", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes StopApplication();

      [DllImport("open.dll", EntryPoint = "connect", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes Connect();

      [DllImport("open.dll", EntryPoint = "disconnect", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes Disconnect();

      [DllImport("open.dll", EntryPoint = "openProject", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes OpenProject(string strFileName);

      [DllImport("open.dll", EntryPoint = "createProject", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes CreateProject(string strFileName, string strVersion);

      [DllImport("open.dll", EntryPoint = "createProjectWithScaling", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes CreateProjectWithScaling(string strFileName, string strVersion, string strNckScaling);

      [DllImport("open.dll", EntryPoint = "createProjectWithScalingNCUNumber", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes CreateProjectWithScalingNCUNumber(string strFileName, string strVersion, string strNckScaling, UInt32 ncuNumber);

      [DllImport("open.dll", EntryPoint = "saveProject", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes SaveProject();

      [DllImport("open.dll", EntryPoint = "closeProject", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes CloseProject();

      [DllImport("open.dll", EntryPoint = "bootController", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes BootController();

      [DllImport("open.dll", EntryPoint = "shutdownController", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ShutdownController();

      [DllImport("open.dll", EntryPoint = "resetController", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ResetController();

      [DllImport("open.dll", EntryPoint = "registerForEvents", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes RegisterForEvents(UInt32 nEventListLength, IntPtr pEventList);

      [DllImport("open.dll", EntryPoint = "unregisterEvents", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes UnregisterEvents();

      [DllImport("open.dll", EntryPoint = "waitForEvents", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WaitForEvents();

      [DllImport("open.dll", EntryPoint = "continueSimulation", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ContinueSimulation();

      [DllImport("open.dll", EntryPoint = "getDictionaryId", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetDictionaryId(string strDictionaryElement, ref UInt32 pDictionaryId);

      [DllImport("open.dll", EntryPoint = "registerWatch", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes RegisterWatch(UInt32 nWatchListLength, IntPtr pDictionaryIdList);

      [DllImport("open.dll", EntryPoint = "unregisterWatch", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes UnregisterWatch();

      [DllImport("open.dll", EntryPoint = "getDictionaryElementType", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetDictionaryElementType(UInt32 nDictionaryId, ref byte pValue);

      [DllImport("open.dll", EntryPoint = "readUnsignedInteger64BitArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadUnsignedInteger64BitArray(UInt32 nDictionaryId, UInt32 nValueListMaxLength, UInt64[] pValueList);

      [DllImport("open.dll", EntryPoint = "readSignedInteger32BitArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadSignedInteger32BitArray(UInt32 nDictionaryId, UInt32 nValueListMaxLength, Int32[] pValueList);

      [DllImport("open.dll", EntryPoint = "readUnsignedInteger32BitArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadUnsignedInteger32BitArray(UInt32 nDictionaryId, UInt32 nValueListMaxLength, UInt32[] pValueList);

      [DllImport("open.dll", EntryPoint = "readUnsignedInteger16BitArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadUnsignedInteger16BitArray(UInt32 nDictionaryId, UInt32 nValueListMaxLength, UInt16[] pValueList);

      [DllImport("open.dll", EntryPoint = "readUnsignedInteger8BitArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadUnsignedInteger8BitArray(UInt32 nDictionaryId, UInt32 nValueListMaxLength, byte[] pValueList);

      [DllImport("open.dll", EntryPoint = "readBoolArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadBoolArray(UInt32 nDictionaryId, UInt32 nValueListMaxLength, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1)] bool[] pValueList);

      [DllImport("open.dll", EntryPoint = "readDoubleArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadDoubleArray(UInt32 nDictionaryId, UInt32 nValueListMaxLength, double[] pValueList);

      [DllImport("open.dll", EntryPoint = "readString", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadString(UInt32 nDictionaryId, UInt32 nStringMaxLength, IntPtr pString);

      [DllImport("open.dll", EntryPoint = "readStringArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadStringArray(UInt32 nDictionaryId, UInt32 nStringArrayMaxLength, UInt32 nStringMaxLength, IntPtr ppStringArray);

      [DllImport("open.dll", EntryPoint = "readUnsignedInteger16Bit", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadUnsignedInteger16Bit(UInt32 nDictionaryId, ref UInt16 pValue);

      [DllImport("open.dll", EntryPoint = "readSignedInteger16Bit", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadSignedInteger16Bit(UInt32 nDictionaryId, ref Int16 pValue);

      [DllImport("open.dll", EntryPoint = "readUnsignedInteger32Bit", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadUnsignedInteger32Bit(UInt32 nDictionaryId, ref UInt32 pValue);

      [DllImport("open.dll", EntryPoint = "readSignedInteger32Bit", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadSignedInteger32Bit(UInt32 nDictionaryId, ref Int32 pValue);

      [DllImport("open.dll", EntryPoint = "readUnsignedInteger64Bit", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadUnsignedInteger64Bit(UInt32 nDictionaryId, ref UInt64 pValue);

      [DllImport("open.dll", EntryPoint = "readSignedInteger64Bit", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadSignedInteger64Bit(UInt32 nDictionaryId, ref Int64 pValue);

      [DllImport("open.dll", EntryPoint = "getNumArrayElements", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetNumArrayElements(UInt32 nDictionaryId, ref UInt32 pNumArrayElements);

      [DllImport("open.dll", EntryPoint = "readBit", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadBit(UInt32 nDictionaryId, ref bool pValue);

      [DllImport("open.dll", EntryPoint = "readBool", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadBool(UInt32 nDictionaryId, ref bool pValue);

      [DllImport("open.dll", EntryPoint = "readByte", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadByte(UInt32 nDictionaryId, ref byte pValue);

      [DllImport("open.dll", EntryPoint = "readDouble", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadDouble(UInt32 nDictionaryId, ref double pValue);

      [DllImport("open.dll", EntryPoint = "readWord", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadWord(UInt32 nDictionaryId, ref UInt16 pValue);

      [DllImport("open.dll", EntryPoint = "readDoubleWord", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadDoubleWord(UInt32 nDictionaryId, ref UInt32 pValue);

      [DllImport("open.dll", EntryPoint = "readLongWord", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadLongWord(UInt32 nDictionaryId, ref UInt64 pValue);

      [DllImport("open.dll", EntryPoint = "readNextEvent", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadNextEvent(ref UInt64 pEvent);

      [DllImport("open.dll", EntryPoint = "readNextEventWithNcuIndex", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ReadNextEventWithNcuIndex(ref UInt64 pEvent, ref Int32 pNcuIndex);

      [DllImport("open.dll", EntryPoint = "writeBit", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteBit(UInt32 nDictionaryId, bool bValue);

      [DllImport("open.dll", EntryPoint = "writeBool", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteBool(UInt32 nDictionaryId, bool bValue);

      [DllImport("open.dll", EntryPoint = "writeByte", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteByte(UInt32 nDictionaryId, byte nValue);

      [DllImport("open.dll", EntryPoint = "writeDouble", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteDouble(UInt32 nDictionaryId, double dValue);

      [DllImport("open.dll", EntryPoint = "writeWord", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteWord(UInt32 nDictionaryId, UInt16 nValue);

      [DllImport("open.dll", EntryPoint = "writeDoubleWord", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteDoubleWord(UInt32 nDictionaryId, UInt32 nValue);

      [DllImport("open.dll", EntryPoint = "writeLongWord", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteLongWord(UInt32 nDictionaryId, UInt64 nValue);

      [DllImport("open.dll", EntryPoint = "writeBoolArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteBoolArray(UInt32 nDictionaryId, UInt32 nValueListLength, [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1)] bool[] pValueList);

      [DllImport("open.dll", EntryPoint = "getSimulationSpeed", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetSimulationSpeed(ref UInt32 pnPercent);

      [DllImport("open.dll", EntryPoint = "setSimulationSpeed", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes SetSimulationSpeed(UInt32 pnPercent);

      [DllImport("open.dll", EntryPoint = "getCardPath", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetCardPath(UInt32 nCardPathMaxLength, IntPtr pCardPath);

      [DllImport("open.dll", EntryPoint = "getCardPaths", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetCardPaths(UInt32 nCardPathsArrayMaxLength, UInt32 nCardPathMaxLength, IntPtr pCardPaths);

      [DllImport("open.dll", EntryPoint = "getFile", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetFile(string strSourceFilePath, string strDestinationFilePath);

      [DllImport("open.dll", EntryPoint = "putFile", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes PutFile(string strSourceFilePath, string strDestinationFilePath);

      [DllImport("open.dll", EntryPoint = "selectFile", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes SelectFile(string strSourceFilePath, string strChannelName);

      [DllImport("open.dll", EntryPoint = "deleteFile", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes DeleteFile(string strFilePath);

      [DllImport("open.dll", EntryPoint = "deleteDirectory", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes DeleteDirectory(string strDirectoryPath);

      [DllImport("open.dll", EntryPoint = "createDirectory", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes CreateDirectory(string strDirectoryPath);

      [DllImport("open.dll", EntryPoint = "listDirectory", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ListDirectory(string strDirectoryPath, string strResultFilePath);

      [DllImport("open.dll", EntryPoint = "getVersionInformation", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetVersionInformation(string strDestinationFilePath);

      [DllImport("open.dll", EntryPoint = "getProjectInformation", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetProjectInformation(string strVcpFilePath, string strDestinationFilePath);

      [DllImport("open.dll", EntryPoint = "getCurrentProjectInformation", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetCurrentProjectInformation(string strDestinationFilePath);

      [DllImport("open.dll", EntryPoint = "getCurrentProjectState", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetCurrentProjectState(ref Int32 pProjectState);

      [DllImport("open.dll", EntryPoint = "importProjectSettings", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ImportProjectSettings(string strFileName, string strImportContentFileName);

      [DllImport("open.dll", EntryPoint = "exportProjectSettings", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes ExportProjectSettings(string strFileName);

      [DllImport("open.dll", EntryPoint = "writeUnsignedInteger8BitArray", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes WriteUnsignedInteger8BitArray(UInt32 nDictionaryId, UInt32 nValueListMaxLength, byte[] pValueList);

      [DllImport("open.dll", EntryPoint = "getNumberOfNCUs", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
      public static extern OpenReturnCodes GetNumberOfNCUs(ref UInt32 pNumberOfNCUs);

   }
}
