diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..14fc6c3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,14 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "connect_demo" +version = "0.0.0" +dependencies = [ + "open_wrapper", +] + +[[package]] +name = "open_wrapper" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..355cc45 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[workspace] +members = [ + ".", # keep the Tauri app in the workspace + "open_wrapper" +] + +[package] +name = "connect_demo" +edition = "2021" +build = "build.rs" + +[workspace.package] +edition = "2021" + +[dependencies] +open_wrapper = { path = "open_wrapper" } diff --git a/OpenApiWrapper.cs b/OpenApiWrapper.cs new file mode 100644 index 0000000..55b286f --- /dev/null +++ b/OpenApiWrapper.cs @@ -0,0 +1,815 @@ +// ================================================================= +// \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 + { + /// + /// Call was successful + /// + Ok = 0, + + // --------- Application control and Connection --------- + /// + /// An internal error occurred. + /// + ErrorInternal = -1001, + /// + /// SINUMERIK ONE install path not found in registry. + /// + ErrorVcNotFound = -1002, + /// + /// CreateProcess of SINUMERIK ONE instance failed. + /// + ErrorCreateProcess = -1003, + /// + /// An SINUMERIK ONE instance is already running. + /// + ErrorAlreadyRunning = -1004, + /// + /// SINUMERIK ONE close failed. + /// + ErrorCloseFailed = -1005, + /// + /// SINUMERIK ONE instance not found. + /// + ErrorInstanceNotFound = -1006, + /// + /// The connection to SINUMERIK ONE is occupied. + /// + ErrorInstanceBusy = -1007, + /// + /// No connection to SINUMERIK ONE. + /// + ErrorNoConnection = -1008, + /// + /// SINUMERIK ONE is not ready for communication. + /// + ErrorVcNotReady = -1009, + /// + /// Invalid parameter. + /// + ErrorInvalidParameter = -1010, + /// + /// No valid license found. This code is deprecated ! + /// + ErrorNoLicenseDeprecated = -1011, + /// + /// Connection to SINUMERIK ONE has been closed. + /// + ErrorConnectionClosed = -1012, + /// + /// S7DOS simulation mode is active. + /// + ErrorS7DosSimulationActive = -1013, + /// + /// Version incompatible. + /// + ErrorVersionIncompatible = -1014, + /// + /// The called feature is not supported by the currently used backend. + /// + ErrorNotSupportedByBackend = -1015, + /// + /// At least one Window could not be embedded (blackbox mode). + /// + WarningWindowEmbedding = 1002, + /// + /// The Client has a lower(,but comnpatible) version than the Middleware. + /// + WarningVersionClientOld = 1003, + /// + /// The Middleware has a lower(but comnpatible) version than the Client. + /// + WarningVersionMiddlewareOld = 1004, + /// + /// Detected a lost client connection. Client has to reconnect. + /// + WarningConnectionCorrupted = 1005, + + // --------- File handling (VCPs, startprofiles, etc.) --------- + /// + /// The file could not be found. + /// + ErrorFileNotFound = -2001, + /// + /// There is a project already open. + /// + ErrorProjectOpen = -2002, + /// + /// Loading the vcp file failed. + /// + ErrorLoadFailed = -2003, + /// + /// No project open. + /// + ErrorNoProjectOpen = -2004, + /// + /// File is write protected. + /// + ErrorWriteProtected = -2005, + /// + /// Simulation is running. + /// + ErrorSimRunning = -2006, + /// + /// Saving the file failed. + /// + ErrorWriteFailed = -2007, + /// + /// Closing the project failed. + /// + ErrorVcpCloseFailed = -2008, + /// + /// The file is invalid. + /// + ErrorInvalidFile = -2009, + /// + /// The selected cnc software is not available. + /// + ErrorCncSwUnavailable = -2010, + /// + /// The file could not be created. + /// + ErrorFileCreationFailed = -2011, + /// + /// The frontend not installed. + /// + ErrorFrontendNotInstalled = -2012, + /// + /// The no license for the frontend. This code is deprecated ! + /// + ErrorFrontendNotLicensedDeprecated = -2013, + /// + /// The path to the project file is too long. + /// + ErrorFilePathTooLong = -2014, + /// + /// The selected nck scaling is invalid. + /// + ErrorInvalidNckscaling = -2015, + /// + /// The selected ncu number is invalid. + /// + ErrorInvalidNcunumber = -2016, + + // --------- Simulation Control --------- + /// + /// Starting the simulation failed. + /// + ErrorStartSimFailed = -3001, + /// + /// Stopping the simulation failed. + /// + ErrorStopSimFailed = -3002, + /// + /// Reseting the simulation failed. + /// + ErrorResetSimFailed = -3004, + /// + /// Reseting the simulation failed. + /// + ErrorSimSpeedInvalid = -3005, + /// + /// Simulation is not available. + /// + ErrorSimNotAvailable = -3006, + /// + /// Simulation is not running. + /// + ErrorSimNotRunning = -3007, + /// + /// Simulation is running. + /// + SimRunning = 3001, + /// + /// Simulation is not running. + /// + SimNotRunning = 3002, + + // --------- Synchronized Operation --------- + /// + /// The event is unknown. + /// + ErrorEventUnknown = -4001, + /// + /// No events are registered. + /// + ErrorNoEventsRegistered = -4002, + /// + /// The simulation got interrupted. + /// + ErrorSimInterrupted = -4003, + + // --------- Data Access --------- + /// + /// Unknown dictionary entry. + /// + ErrorUnknownElement = -5001, + /// + /// The dictionary id is invalid. + /// + ErrorInvalidDictId = -5002, + /// + /// Not enough memory for the data. + /// + ErrorInsufficientMemory = -5003, + /// + /// Elemente is not an array. + /// + ErrorNoarray = -5004, + /// + /// Wrong type for the data. + /// + ErrorWrongType = -5005, + /// + /// Wrong accesrights for the data. + /// + ErrorInsufficientRights = -5006, + /// + /// The application is not in the wait state + /// + ErrorNotInWait = -5007, + /// + /// No further data available. + /// + NoMoreData = 5001, + + // --------- File Operations --------- + /// + /// The domain for file system operation is invalid. + /// + ErrorFileOpInvalidDomain = -6001, + /// + /// The source path for file system operation is not absolute. + /// + ErrorFileOpSourcePathNotAbsolute = -6002, + /// + /// The source file for file system operation does not exist. + /// + ErrorFileOpSourceFileNotExists = -6003, + /// + /// The destination path for file system operation is not absolute. + /// + ErrorFileOpDestinationPathNotAbsolute = -6004, + /// + /// The destination file or directory for file system operation already exsists. + /// + ErrorFileOpDestinationAlreadyExists = -6005, + /// + /// The destination directory for file system operation does not exists. + /// + ErrorFileOpDestinationDirectoryNotExists = -6006, + /// + /// The directory for file system operation does not exists. + /// + ErrorFileOpDirectoryNotExists = -6007, + /// + /// The directory for file system operation is not empty. + /// + ErrorFileOpDirectoryNotEmpty = -6008, + /// + /// A file or a part program can't select. + /// + ErrorFileSelectNotPossible = -6009, + /// + /// The channel does not exists. + /// + ErrorChannelNotExists = -6010, + /// + /// The file is in edit mode. + /// + ErrorFileUsed = -6011, + + // --------- License handling --------- + /// + /// General error, licensing failed. + /// + ErrorLicenseNoLicense = -7001, + /// + /// The application mentioned in the license file, does not match any known application in the xMVM context. + /// + ErrorLicenseUnknownApplication = -7002, + /// + /// The frontend is not CMVM or RMVM. + /// + ErrorLicenseUnknownFrontend = -7003, + /// + /// The connection to the license server could not be established. + /// + ErrorLicenseNoConnection = -7004, + /// + /// The license handler could not be instantiated. + /// + ErrorLicenseNoLicenseHandler = -7005, + /// + /// The Server is busy, cant read, cant write. + /// + ErrorLicenseErrorAtServerSite = -7006, + /// + /// The license for a particular feature is not available. + /// + ErrorLicenseOptionalLicenseKeyNotAvailable = -7007, + /// + /// The license for a particular feature could not be granted. + /// + ErrorLicenseOptionalLicenseKeyNotGranted = -7008, + /// + /// The license for a particular feature could not be locked at the license server. + /// + ErrorLicenseOptionalLicenseNotAqcuired = -7009, + /// + /// The validation of the license file failed. + /// + ErrorLicenseOptionalLicenseCheckFailed = -7010, + /// + /// The acquistion of a license was not successfull. + /// + ErrorLicenseKeyNotAvailable = -7011, + /// + /// The main license key could not be granted. + /// + ErrorLicenseKeyGrantFailed = -7012, + /// + /// The main license key could not be released. + /// + ErrorLicenseKeyReleaseFailed = -7013, + /// + /// The main license key is invalid. + /// + ErrorLicenseInvalid = -7014, + /// + /// The license key is already in use. + /// + ErrorLicenseAlreadyInUse = -7015, + /// + /// The validation of the license key failed. + /// + ErrorLicenseCheckFailed = -7016, + /// + /// All licenses from the license pool are currently in use. + /// + ErrorLicenseAllLicensesInUse = -7017, + /// + /// The type of the used license is unknown. + /// + 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 + { + /// + /// axisMode undefined + /// + None = 0, + /// + /// interpolation mode + /// + Interpolation = 1, + /// + /// positioning mode + /// + Positioning = 2, + /// + /// speed mode turning left + /// + SpeedLeft = 3, + /// + /// speed mode turning right + /// + SpeedRight = 4, + /// + /// speed mode stopped + /// + SpeedStop = 5, + /// + /// following axis - no specified type + /// + Following = 6, + } + + public enum OpenAxisReferenceState + { + /// + /// reference state undefined + /// + None = 0, + /// + /// not referenced + /// + NotReferenced = 1, + /// + /// referenced + /// + Referenced = 2, + /// + /// referencing not required + /// + ReferenceNotRequired = 3, + } + + public enum OpenMotionType + { + /// + /// value undefined / OEMIPO1 / OEMIPO2 / Involute + /// + None = 0, + /// + /// rapid motion independent from $AC_G0MODE + /// + Rapid = 1, + /// + /// linear motion + /// + Linear = 2, + /// + /// circle motion G2 / G3 / CIP / CT + /// + Circle = 3, + /// + /// A/B/C-Spline / Poly + /// + Spline = 4, + /// + /// G33 / G331 / G332 / G34 / G35 + /// + Thread = 5, + /// + /// involute INVCW / INVCCW + /// + Involute = 6, + } + + public enum OpenCircleDirection + { + /// + /// value undefined + /// + None = 0, + /// + /// clockwise + /// + Cw = 1, + /// + /// counter clockwise + /// + Ccw = 2, + } + + public enum OpenOperatingMode + { + /// + /// no operating mode + /// + None = 0, + /// + /// operating mode auto + /// + Auto = 1, + /// + /// operating jog + /// + Jog = 2, + /// + /// operating mode mda + /// + Mda = 3, + } + + public enum OpenChannelState + { + /// + /// no channel state + /// + None = 0, + /// + /// channel state activated + /// + Activated = 1, + /// + /// channel state stopped + /// + Stopped = 2, + /// + /// channel state reseted + /// + Reseted = 3, + } + + public enum OpenAxisType + { + /// + /// axisType undefined + /// + None = 0, + /// + /// linear axis + /// + Linear = 1, + /// + /// round axis + /// + Rotatory = 2, + /// + /// modulo axis + /// + Modulo = 3, + /// + /// spindle axis + /// + 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); + + } +} diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..64121a7 --- /dev/null +++ b/build.rs @@ -0,0 +1,43 @@ +use std::{ + env, + fs, + io, + path::{Path, PathBuf}, +}; + +fn main() -> io::Result<()> { + let manifest_dir = + PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set")); + let dll_source_dir = manifest_dir.join("open_wrapper").join("lib"); + + if !dll_source_dir.exists() { + println!( + "cargo:warning=DLL source directory '{}' not found. Skipping copy.", + dll_source_dir.display() + ); + return Ok(()); + } + + let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR not set")); + // OUT_DIR = target/{profile}/build//out + let profile_dir = out_dir + .ancestors() + .nth(3) + .expect("Unable to compute profile dir from OUT_DIR"); + + let dest_dir = Path::new(profile_dir); + fs::create_dir_all(&dest_dir)?; + + for entry in fs::read_dir(&dll_source_dir)? { + let entry = entry?; + let path = entry.path(); + if path.extension().map_or(false, |ext| ext.eq_ignore_ascii_case("dll")) { + let file_name = entry.file_name(); + let dest_path = dest_dir.join(&file_name); + fs::copy(&path, &dest_path)?; + } + println!("cargo:rerun-if-changed={}", path.display()); + } + + Ok(()) +} diff --git a/open_wrapper/Cargo.toml b/open_wrapper/Cargo.toml new file mode 100644 index 0000000..3af9bf5 --- /dev/null +++ b/open_wrapper/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "open_wrapper" +version = "0.1.0" +edition.workspace = true +build = "build.rs" diff --git a/open_wrapper/build.rs b/open_wrapper/build.rs new file mode 100644 index 0000000..e937b4c --- /dev/null +++ b/open_wrapper/build.rs @@ -0,0 +1,20 @@ +use std::{env, path::PathBuf}; + +fn main() { + let manifest_dir = + PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR must be set")); + let lib_dir = manifest_dir.join("lib"); + + println!("cargo:rustc-link-search=native={}", lib_dir.display()); + println!("cargo:rerun-if-changed=build.rs"); + + let open_lib = lib_dir.join("open.lib"); + if open_lib.exists() { + println!("cargo:rerun-if-changed={}", open_lib.display()); + } else { + println!( + "cargo:warning=Expected to find open.lib in '{}'. Copy the vendor import library there.", + lib_dir.display() + ); + } +} diff --git a/open_wrapper/lib/commonutilities.dll b/open_wrapper/lib/commonutilities.dll new file mode 100644 index 0000000..d612e21 Binary files /dev/null and b/open_wrapper/lib/commonutilities.dll differ diff --git a/open_wrapper/lib/open.def b/open_wrapper/lib/open.def new file mode 100644 index 0000000..e7c2d6b --- /dev/null +++ b/open_wrapper/lib/open.def @@ -0,0 +1,75 @@ +LIBRARY open +EXPORTS +bootController +closeProject +connect +continueSimulation +createDirectory +createProject +createProjectWithScaling +createProjectWithScalingNCUNumber +deleteDirectory +deleteFile +disconnect +exportProjectSettings +getCardPath +getCardPaths +getCurrentProjectInformation +getCurrentProjectState +getDictionaryElementType +getDictionaryId +getFile +getNumArrayElements +getNumberOfNCUs +getProjectInformation +getSimulationSpeed +getVersionInformation +importProjectSettings +listDirectory +openProject +putFile +readBit +readBool +readBoolArray +readByte +readDouble +readDoubleArray +readDoubleWord +readLongWord +readNextEvent +readNextEventWithNcuIndex +readSignedInteger16Bit +readSignedInteger32Bit +readSignedInteger32BitArray +readSignedInteger64Bit +readString +readStringArray +readUnsignedInteger16Bit +readUnsignedInteger16BitArray +readUnsignedInteger32Bit +readUnsignedInteger32BitArray +readUnsignedInteger64Bit +readUnsignedInteger64BitArray +readUnsignedInteger8BitArray +readWord +registerForEvents +registerWatch +resetController +saveProject +selectFile +setSimulationSpeed +shutdownController +startApplication +stopApplication +unregisterEvents +unregisterWatch +waitForEvents +writeBit +writeBool +writeBoolArray +writeByte +writeDouble +writeDoubleWord +writeLongWord +writeUnsignedInteger8BitArray +writeWord diff --git a/open_wrapper/lib/open.dll b/open_wrapper/lib/open.dll new file mode 100644 index 0000000..9151c50 Binary files /dev/null and b/open_wrapper/lib/open.dll differ diff --git a/open_wrapper/lib/open.exp b/open_wrapper/lib/open.exp new file mode 100644 index 0000000..f360026 Binary files /dev/null and b/open_wrapper/lib/open.exp differ diff --git a/open_wrapper/lib/open.exports b/open_wrapper/lib/open.exports new file mode 100644 index 0000000..035d911 --- /dev/null +++ b/open_wrapper/lib/open.exports @@ -0,0 +1,99 @@ + +Dump of file C:\Users\chris\Downloads\vmx_open_api_examples_V1.5.1\11_Rust\rust_wrapper\open_wrapper\lib\open.dll + +File Type: DLL + + Section contains the following exports for open.dll + + 00000000 characteristics + FFFFFFFF time date stamp + 0.00 version + 1 ordinal base + 73 number of functions + 73 number of names + + ordinal hint RVA name + + 1 0 00002990 bootController + 2 1 00002720 closeProject + 72 2 000015A0 connect + 3 3 00003850 continueSimulation + 4 4 0000CCA0 createDirectory + 5 5 00001CF0 createProject + 6 6 00001F80 createProjectWithScaling + 7 7 00002210 createProjectWithScalingNCUNumber + 8 8 0000CA30 deleteDirectory + 9 9 0000C7C0 deleteFile + 10 A 00001810 disconnect + 11 B 0000DE30 exportProjectSettings + 12 C 0000BAF0 getCardPath + 13 D 0000BD80 getCardPaths + 14 E 0000D6C0 getCurrentProjectInformation + 15 F 0000D930 getCurrentProjectState + 16 10 00004250 getDictionaryElementType + 17 11 00003AC0 getDictionaryId + 18 12 0000C010 getFile + 19 13 00007FE0 getNumArrayElements + 20 14 0000E430 getNumberOfNCUs + 21 15 0000D430 getProjectInformation + 22 16 0000B610 getSimulationSpeed + 23 17 0000D1A0 getVersionInformation + 24 18 0000DBA0 importProjectSettings + 25 19 0000CF10 listDirectory + 26 1A 00001A80 openProject + 27 1B 0000C2A0 putFile + 28 1C 00008270 readBit + 29 1D 000085E0 readBool + 30 1E 000057A0 readBoolArray + 31 1F 00008950 readByte + 32 20 00008D70 readDouble + 33 21 00005B60 readDoubleArray + 34 22 00009410 readDoubleWord + 35 23 000096A0 readLongWord + 36 24 00009930 readNextEvent + 37 25 00009BA0 readNextEventWithNcuIndex + 38 26 00006B40 readSignedInteger16Bit + 39 27 00007380 readSignedInteger32Bit + 40 28 000048A0 readSignedInteger32BitArray + 41 29 00007BC0 readSignedInteger64Bit + 73 2A 00005F20 readString + 42 2B 000062B0 readStringArray + 43 2C 00006720 readUnsignedInteger16Bit + 44 2D 00005020 readUnsignedInteger16BitArray + 45 2E 00006F60 readUnsignedInteger32Bit + 46 2F 00004C60 readUnsignedInteger32BitArray + 47 30 000077A0 readUnsignedInteger64Bit + 48 31 000044E0 readUnsignedInteger64BitArray + 49 32 000053E0 readUnsignedInteger8BitArray + 50 33 00009180 readWord + 51 34 000030E0 registerForEvents + 52 35 00003D50 registerWatch + 53 36 00002E70 resetController + 54 37 000024B0 saveProject + 55 38 0000C530 selectFile + 56 39 0000B880 setSimulationSpeed + 57 3A 00002C00 shutdownController + 58 3B 000010C0 startApplication + 59 3C 00001330 stopApplication + 60 3D 00003370 unregisterEvents + 61 3E 00003FE0 unregisterWatch + 62 3F 000035E0 waitForEvents + 63 40 00009E30 writeBit + 64 41 0000A0C0 writeBool + 65 42 0000B250 writeBoolArray + 66 43 0000A350 writeByte + 67 44 0000A6F0 writeDouble + 68 45 0000AD30 writeDoubleWord + 69 46 0000AFC0 writeLongWord + 70 47 0000E0A0 writeUnsignedInteger8BitArray + 71 48 0000AAA0 writeWord + + Summary + + 1000 .btc + 11000 .data + 3000 .pdata + 32000 .rdata + 2000 .reloc + 1000 .rsrc + 52000 .text diff --git a/open_wrapper/lib/open.lib b/open_wrapper/lib/open.lib new file mode 100644 index 0000000..799d1f9 Binary files /dev/null and b/open_wrapper/lib/open.lib differ diff --git a/open_wrapper/lib/simutilities.dll b/open_wrapper/lib/simutilities.dll new file mode 100644 index 0000000..17f9d49 Binary files /dev/null and b/open_wrapper/lib/simutilities.dll differ diff --git a/open_wrapper/lib/svccoacommlib.dll b/open_wrapper/lib/svccoacommlib.dll new file mode 100644 index 0000000..e02085e Binary files /dev/null and b/open_wrapper/lib/svccoacommlib.dll differ diff --git a/open_wrapper/lib/xerces-c_3_2.dll b/open_wrapper/lib/xerces-c_3_2.dll new file mode 100644 index 0000000..3bb3434 Binary files /dev/null and b/open_wrapper/lib/xerces-c_3_2.dll differ diff --git a/open_wrapper/lib/zlib1.dll b/open_wrapper/lib/zlib1.dll new file mode 100644 index 0000000..9d0ffea Binary files /dev/null and b/open_wrapper/lib/zlib1.dll differ diff --git a/open_wrapper/src/lib.rs b/open_wrapper/src/lib.rs new file mode 100644 index 0000000..b7a0c44 --- /dev/null +++ b/open_wrapper/src/lib.rs @@ -0,0 +1,545 @@ +#![allow(non_snake_case)] + +/// Pointer to a UTF-16 string (wide char) terminated with `0`. +pub type PCWSTR = *const u16; +/// Mutable pointer to a UTF-16 buffer. +pub type PWSTR = *mut u16; +/// Pointer to an array of UTF-16 string pointers. +pub type PPWSTR = *mut PWSTR; +/// 32-bit boolean, mirrors the Win32 `BOOL` layout used by the C API. +pub type Bool32 = i32; + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenReturnCodes { + Ok = 0, + // --------- Application control and Connection --------- + ErrorInternal = -1001, + ErrorVcNotFound = -1002, + ErrorCreateProcess = -1003, + ErrorAlreadyRunning = -1004, + ErrorCloseFailed = -1005, + ErrorInstanceNotFound = -1006, + ErrorInstanceBusy = -1007, + ErrorNoConnection = -1008, + ErrorVcNotReady = -1009, + ErrorInvalidParameter = -1010, + ErrorNoLicenseDeprecated = -1011, + ErrorConnectionClosed = -1012, + ErrorS7DosSimulationActive = -1013, + ErrorVersionIncompatible = -1014, + ErrorNotSupportedByBackend = -1015, + WarningWindowEmbedding = 1002, + WarningVersionClientOld = 1003, + WarningVersionMiddlewareOld = 1004, + WarningConnectionCorrupted = 1005, + // --------- File handling (VCPs, startprofiles, etc.) --------- + ErrorFileNotFound = -2001, + ErrorProjectOpen = -2002, + ErrorLoadFailed = -2003, + ErrorNoProjectOpen = -2004, + ErrorWriteProtected = -2005, + ErrorSimRunning = -2006, + ErrorWriteFailed = -2007, + ErrorVcpCloseFailed = -2008, + ErrorInvalidFile = -2009, + ErrorCncSwUnavailable = -2010, + ErrorFileCreationFailed = -2011, + ErrorFrontendNotInstalled = -2012, + ErrorFrontendNotLicensedDeprecated = -2013, + ErrorFilePathTooLong = -2014, + ErrorInvalidNckscaling = -2015, + ErrorInvalidNcunumber = -2016, + // --------- Simulation Control --------- + ErrorStartSimFailed = -3001, + ErrorStopSimFailed = -3002, + ErrorResetSimFailed = -3004, + ErrorSimSpeedInvalid = -3005, + ErrorSimNotAvailable = -3006, + ErrorSimNotRunning = -3007, + SimRunning = 3001, + SimNotRunning = 3002, + // --------- Synchronized Operation --------- + ErrorEventUnknown = -4001, + ErrorNoEventsRegistered = -4002, + ErrorSimInterrupted = -4003, + // --------- Data Access --------- + ErrorUnknownElement = -5001, + ErrorInvalidDictId = -5002, + ErrorInsufficientMemory = -5003, + ErrorNoarray = -5004, + ErrorWrongType = -5005, + ErrorInsufficientRights = -5006, + ErrorNotInWait = -5007, + NoMoreData = 5001, + // --------- File Operations --------- + ErrorFileOpInvalidDomain = -6001, + ErrorFileOpSourcePathNotAbsolute = -6002, + ErrorFileOpSourceFileNotExists = -6003, + ErrorFileOpDestinationPathNotAbsolute = -6004, + ErrorFileOpDestinationAlreadyExists = -6005, + ErrorFileOpDestinationDirectoryNotExists = -6006, + ErrorFileOpDirectoryNotExists = -6007, + ErrorFileOpDirectoryNotEmpty = -6008, + ErrorFileSelectNotPossible = -6009, + ErrorChannelNotExists = -6010, + ErrorFileUsed = -6011, + // --------- License handling --------- + ErrorLicenseNoLicense = -7001, + ErrorLicenseUnknownApplication = -7002, + ErrorLicenseUnknownFrontend = -7003, + ErrorLicenseNoConnection = -7004, + ErrorLicenseNoLicenseHandler = -7005, + ErrorLicenseErrorAtServerSite = -7006, + ErrorLicenseOptionalLicenseKeyNotAvailable = -7007, + ErrorLicenseOptionalLicenseKeyNotGranted = -7008, + ErrorLicenseOptionalLicenseNotAqcuired = -7009, + ErrorLicenseOptionalLicenseCheckFailed = -7010, + ErrorLicenseKeyNotAvailable = -7011, + ErrorLicenseKeyGrantFailed = -7012, + ErrorLicenseKeyReleaseFailed = -7013, + ErrorLicenseInvalid = -7014, + ErrorLicenseAlreadyInUse = -7015, + ErrorLicenseCheckFailed = -7016, + ErrorLicenseAllLicensesInUse = -7017, + ErrorLicenseUnknownLicense = -7018, +} + +impl OpenReturnCodes { + /// Convenience helper that mirrors the old `Ok` check in the C# wrapper. + pub fn is_ok(self) -> bool { + matches!(self, OpenReturnCodes::Ok) + } +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub 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, +} + +#[repr(u64)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenEventMaskDefinition { + 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, +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenAxisMode { + None = 0, + Interpolation = 1, + Positioning = 2, + SpeedLeft = 3, + SpeedRight = 4, + SpeedStop = 5, + Following = 6, +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenAxisReferenceState { + None = 0, + NotReferenced = 1, + Referenced = 2, + ReferenceNotRequired = 3, +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenMotionType { + None = 0, + Rapid = 1, + Linear = 2, + Circle = 3, + Spline = 4, + Thread = 5, + Involute = 6, +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenCircleDirection { + None = 0, + Cw = 1, + Ccw = 2, +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenOperatingMode { + None = 0, + Auto = 1, + Jog = 2, + Mda = 3, +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenChannelState { + None = 0, + Activated = 1, + Stopped = 2, + Reseted = 3, +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenAxisType { + None = 0, + Linear = 1, + Rotatory = 2, + Modulo = 3, + Spindle = 4, +} + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum OpenProjectStates { + Closed = 1, + Opening = 2, + Open = 3, + Booting = 4, + RunningOrPaused = 5, + ShuttingDown = 6, + Closing = 7, + Resetting = 8, + Saving = 9, + Error = 10, +} + +#[link(name = "open")] +extern "C" { + #[link_name = "startApplication"] + pub fn start_application(str_profile_file_name: PCWSTR) -> OpenReturnCodes; + + #[link_name = "stopApplication"] + pub fn stop_application() -> OpenReturnCodes; + + #[link_name = "connect"] + pub fn connect() -> OpenReturnCodes; + + #[link_name = "disconnect"] + pub fn disconnect() -> OpenReturnCodes; + + #[link_name = "openProject"] + pub fn open_project(str_file_name: PCWSTR) -> OpenReturnCodes; + + #[link_name = "createProject"] + pub fn create_project(str_file_name: PCWSTR, str_version: PCWSTR) -> OpenReturnCodes; + + #[link_name = "createProjectWithScaling"] + pub fn create_project_with_scaling( + str_file_name: PCWSTR, + str_version: PCWSTR, + str_nck_scaling: PCWSTR + ) -> OpenReturnCodes; + + #[link_name = "createProjectWithScalingNCUNumber"] + pub fn create_project_with_scaling_ncu_number( + str_file_name: PCWSTR, + str_version: PCWSTR, + str_nck_scaling: PCWSTR, + ncu_number: u32 + ) -> OpenReturnCodes; + + #[link_name = "saveProject"] + pub fn save_project() -> OpenReturnCodes; + + #[link_name = "closeProject"] + pub fn close_project() -> OpenReturnCodes; + + #[link_name = "bootController"] + pub fn boot_controller() -> OpenReturnCodes; + + #[link_name = "shutdownController"] + pub fn shutdown_controller() -> OpenReturnCodes; + + #[link_name = "resetController"] + pub fn reset_controller() -> OpenReturnCodes; + + #[link_name = "registerForEvents"] + pub fn register_for_events( + event_list_length: u32, + event_list: *const OpenEventMaskDefinition + ) -> OpenReturnCodes; + + #[link_name = "unregisterEvents"] + pub fn unregister_events() -> OpenReturnCodes; + + #[link_name = "waitForEvents"] + pub fn wait_for_events() -> OpenReturnCodes; + + #[link_name = "continueSimulation"] + pub fn continue_simulation() -> OpenReturnCodes; + + #[link_name = "getDictionaryId"] + pub fn get_dictionary_id( + dictionary_element: PCWSTR, + dictionary_id: *mut u32 + ) -> OpenReturnCodes; + + #[link_name = "registerWatch"] + pub fn register_watch( + watch_list_length: u32, + dictionary_id_list: *const u32 + ) -> OpenReturnCodes; + + #[link_name = "unregisterWatch"] + pub fn unregister_watch() -> OpenReturnCodes; + + #[link_name = "getDictionaryElementType"] + pub fn get_dictionary_element_type(dictionary_id: u32, value: *mut u8) -> OpenReturnCodes; + + #[link_name = "readUnsignedInteger64BitArray"] + pub fn read_unsigned_integer_64_bit_array( + dictionary_id: u32, + value_list_max_length: u32, + value_list: *mut u64 + ) -> OpenReturnCodes; + + #[link_name = "readSignedInteger32BitArray"] + pub fn read_signed_integer_32_bit_array( + dictionary_id: u32, + value_list_max_length: u32, + value_list: *mut i32 + ) -> OpenReturnCodes; + + #[link_name = "readUnsignedInteger32BitArray"] + pub fn read_unsigned_integer_32_bit_array( + dictionary_id: u32, + value_list_max_length: u32, + value_list: *mut u32 + ) -> OpenReturnCodes; + + #[link_name = "readUnsignedInteger16BitArray"] + pub fn read_unsigned_integer_16_bit_array( + dictionary_id: u32, + value_list_max_length: u32, + value_list: *mut u16 + ) -> OpenReturnCodes; + + #[link_name = "readUnsignedInteger8BitArray"] + pub fn read_unsigned_integer_8_bit_array( + dictionary_id: u32, + value_list_max_length: u32, + value_list: *mut u8 + ) -> OpenReturnCodes; + + #[link_name = "readBoolArray"] + pub fn read_bool_array( + dictionary_id: u32, + value_list_max_length: u32, + value_list: *mut bool + ) -> OpenReturnCodes; + + #[link_name = "readDoubleArray"] + pub fn read_double_array( + dictionary_id: u32, + value_list_max_length: u32, + value_list: *mut f64 + ) -> OpenReturnCodes; + + #[link_name = "readString"] + pub fn read_string( + dictionary_id: u32, + string_max_length: u32, + string_buffer: PWSTR + ) -> OpenReturnCodes; + + #[link_name = "readStringArray"] + pub fn read_string_array( + dictionary_id: u32, + string_array_max_length: u32, + string_max_length: u32, + string_array: PPWSTR + ) -> OpenReturnCodes; + + #[link_name = "readUnsignedInteger16Bit"] + pub fn read_unsigned_integer_16_bit(dictionary_id: u32, value: *mut u16) -> OpenReturnCodes; + + #[link_name = "readSignedInteger16Bit"] + pub fn read_signed_integer_16_bit(dictionary_id: u32, value: *mut i16) -> OpenReturnCodes; + + #[link_name = "readUnsignedInteger32Bit"] + pub fn read_unsigned_integer_32_bit(dictionary_id: u32, value: *mut u32) -> OpenReturnCodes; + + #[link_name = "readSignedInteger32Bit"] + pub fn read_signed_integer_32_bit(dictionary_id: u32, value: *mut i32) -> OpenReturnCodes; + + #[link_name = "readUnsignedInteger64Bit"] + pub fn read_unsigned_integer_64_bit(dictionary_id: u32, value: *mut u64) -> OpenReturnCodes; + + #[link_name = "readSignedInteger64Bit"] + pub fn read_signed_integer_64_bit(dictionary_id: u32, value: *mut i64) -> OpenReturnCodes; + + #[link_name = "getNumArrayElements"] + pub fn get_num_array_elements( + dictionary_id: u32, + num_array_elements: *mut u32 + ) -> OpenReturnCodes; + + #[link_name = "readBit"] + pub fn read_bit(dictionary_id: u32, value: *mut Bool32) -> OpenReturnCodes; + + #[link_name = "readBool"] + pub fn read_bool(dictionary_id: u32, value: *mut Bool32) -> OpenReturnCodes; + + #[link_name = "readByte"] + pub fn read_byte(dictionary_id: u32, value: *mut u8) -> OpenReturnCodes; + + #[link_name = "readDouble"] + pub fn read_double(dictionary_id: u32, value: *mut f64) -> OpenReturnCodes; + + #[link_name = "readWord"] + pub fn read_word(dictionary_id: u32, value: *mut u16) -> OpenReturnCodes; + + #[link_name = "readDoubleWord"] + pub fn read_double_word(dictionary_id: u32, value: *mut u32) -> OpenReturnCodes; + + #[link_name = "readLongWord"] + pub fn read_long_word(dictionary_id: u32, value: *mut u64) -> OpenReturnCodes; + + #[link_name = "readNextEvent"] + pub fn read_next_event(event: *mut u64) -> OpenReturnCodes; + + #[link_name = "readNextEventWithNcuIndex"] + pub fn read_next_event_with_ncu_index(event: *mut u64, ncu_index: *mut i32) -> OpenReturnCodes; + + #[link_name = "writeBit"] + pub fn write_bit(dictionary_id: u32, value: Bool32) -> OpenReturnCodes; + + #[link_name = "writeBool"] + pub fn write_bool(dictionary_id: u32, value: Bool32) -> OpenReturnCodes; + + #[link_name = "writeByte"] + pub fn write_byte(dictionary_id: u32, value: u8) -> OpenReturnCodes; + + #[link_name = "writeDouble"] + pub fn write_double(dictionary_id: u32, value: f64) -> OpenReturnCodes; + + #[link_name = "writeWord"] + pub fn write_word(dictionary_id: u32, value: u16) -> OpenReturnCodes; + + #[link_name = "writeDoubleWord"] + pub fn write_double_word(dictionary_id: u32, value: u32) -> OpenReturnCodes; + + #[link_name = "writeLongWord"] + pub fn write_long_word(dictionary_id: u32, value: u64) -> OpenReturnCodes; + + #[link_name = "writeBoolArray"] + pub fn write_bool_array( + dictionary_id: u32, + value_list_length: u32, + value_list: *const bool + ) -> OpenReturnCodes; + + #[link_name = "getSimulationSpeed"] + pub fn get_simulation_speed(percent: *mut u32) -> OpenReturnCodes; + + #[link_name = "setSimulationSpeed"] + pub fn set_simulation_speed(percent: u32) -> OpenReturnCodes; + + #[link_name = "getCardPath"] + pub fn get_card_path(card_path_max_length: u32, card_path: PWSTR) -> OpenReturnCodes; + + #[link_name = "getCardPaths"] + pub fn get_card_paths( + card_paths_array_max_length: u32, + card_path_max_length: u32, + card_paths: PPWSTR + ) -> OpenReturnCodes; + + #[link_name = "getFile"] + pub fn get_file(source_file_path: PCWSTR, destination_file_path: PCWSTR) -> OpenReturnCodes; + + #[link_name = "putFile"] + pub fn put_file(source_file_path: PCWSTR, destination_file_path: PCWSTR) -> OpenReturnCodes; + + #[link_name = "selectFile"] + pub fn select_file(source_file_path: PCWSTR, channel_name: PCWSTR) -> OpenReturnCodes; + + #[link_name = "deleteFile"] + pub fn delete_file(file_path: PCWSTR) -> OpenReturnCodes; + + #[link_name = "deleteDirectory"] + pub fn delete_directory(directory_path: PCWSTR) -> OpenReturnCodes; + + #[link_name = "createDirectory"] + pub fn create_directory(directory_path: PCWSTR) -> OpenReturnCodes; + + #[link_name = "listDirectory"] + pub fn list_directory(directory_path: PCWSTR, result_file_path: PCWSTR) -> OpenReturnCodes; + + #[link_name = "getVersionInformation"] + pub fn get_version_information(destination_file_path: PCWSTR) -> OpenReturnCodes; + + #[link_name = "getProjectInformation"] + pub fn get_project_information( + vcp_file_path: PCWSTR, + destination_file_path: PCWSTR + ) -> OpenReturnCodes; + + #[link_name = "getCurrentProjectInformation"] + pub fn get_current_project_information(destination_file_path: PCWSTR) -> OpenReturnCodes; + + #[link_name = "getCurrentProjectState"] + pub fn get_current_project_state(project_state: *mut OpenProjectStates) -> OpenReturnCodes; + + #[link_name = "importProjectSettings"] + pub fn import_project_settings( + file_name: PCWSTR, + import_content_file_name: PCWSTR + ) -> OpenReturnCodes; + + #[link_name = "exportProjectSettings"] + pub fn export_project_settings(file_name: PCWSTR) -> OpenReturnCodes; + + #[link_name = "writeUnsignedInteger8BitArray"] + pub fn write_unsigned_integer_8_bit_array( + dictionary_id: u32, + value_list_max_length: u32, + value_list: *const u8 + ) -> OpenReturnCodes; + + #[link_name = "getNumberOfNCUs"] + pub fn get_number_of_ncus(number_of_ncus: *mut u32) -> OpenReturnCodes; +} diff --git a/scripts/generate_import_lib.ps1 b/scripts/generate_import_lib.ps1 new file mode 100644 index 0000000..8bcba6f --- /dev/null +++ b/scripts/generate_import_lib.ps1 @@ -0,0 +1,55 @@ +param( + [string]$DllPath = "open_wrapper/lib/open.dll", + [string]$OutputLibPath = "", + [ValidateSet("x64", "x86")] + [string]$Machine = "x64" +) + +$errorActionPreference = "Stop" + +function Resolve-Tool($name) { + $cmd = Get-Command $name -ErrorAction SilentlyContinue + if (-not $cmd) { + throw "Could not find '$name' on PATH. Run this script from the Visual Studio Developer Command Prompt or add $name.exe to PATH." + } + return $cmd.Path +} + +$dumpbin = Resolve-Tool "dumpbin.exe" +$libExe = Resolve-Tool "lib.exe" + +if (-not (Test-Path $DllPath)) { + throw "DLL not found: $DllPath" +} + +$dllFullPath = (Get-Item $DllPath).FullName +$workDir = Split-Path $dllFullPath -Parent + +if ([string]::IsNullOrWhiteSpace($OutputLibPath)) { + $dllBase = [System.IO.Path]::GetFileNameWithoutExtension($dllFullPath) + $OutputLibPath = [System.IO.Path]::Combine($workDir, "$dllBase.lib") +} + +$libName = [System.IO.Path]::GetFileNameWithoutExtension($OutputLibPath) +$exportsFile = Join-Path $workDir "$libName.exports" +$defFile = Join-Path $workDir "$libName.def" + +Write-Host "Generating exports list from $dllFullPath ..." +& $dumpbin /nologo /exports $dllFullPath | Set-Content -Encoding UTF8 $exportsFile + +$lines = Get-Content $exportsFile | Where-Object { $_ -match '^\s+\d+\s+[0-9A-F]+\s+[0-9A-F]+\s+\S+' } +$symbols = $lines | ForEach-Object { + ($_.Trim() -split '\s+')[3] +} + +if (-not $symbols) { + throw "Failed to parse exports from $dllFullPath. Inspect $exportsFile for details." +} + +$defContent = @("LIBRARY $libName", "EXPORTS") + $symbols +$defContent | Set-Content -Encoding ASCII $defFile + +Write-Host "Creating import library $OutputLibPath ..." +& $libExe /nologo /def:$defFile /machine:$Machine /out:$OutputLibPath + +Write-Host "Done." diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e8ee068 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,108 @@ +use std::io::{ self, Write }; + +use open_wrapper::{ self, OpenReturnCodes }; + +fn main() { + println!("Rust connect demo for open.dll"); + println!("(make sure open.dll is discoverable and open.lib is linked)\n"); + print_menu(); + + let stdin = io::stdin(); + let mut state = ConnectionState::default(); + + loop { + print!("> "); + if io::stdout().flush().is_err() { + eprintln!("Failed to flush stdout."); + break; + } + + let mut line = String::new(); + if stdin.read_line(&mut line).is_err() { + eprintln!("Failed to read input, exiting."); + break; + } + + let cmd = line.trim().to_lowercase(); + if cmd.is_empty() { + continue; + } + + match cmd.as_str() { + "1" | "c" | "connect" => handle_connect(&mut state), + "2" | "d" | "disconnect" => handle_disconnect(&mut state), + // "3" | "g" | "get-speed" => handle_get_speed(), + // "4" | "r" | "realtime" => handle_set_speed(100, "SetSimulationSpeed (100%)"), + // "5" | "m" | "max" => handle_set_speed(u32::MAX, "SetSimulationSpeed (u32::MAX)"), + "h" | "help" | "?" => print_menu(), + "q" | "quit" | "exit" => { + println!("Bye!"); + break; + } + _ => println!("Unknown command. Type `help` to see the list of commands."), + } + } +} + +#[derive(Default)] +struct ConnectionState { + connected: bool, +} + +fn handle_connect(state: &mut ConnectionState) { + if state.connected { + println!("Already connected. Run `disconnect` first if you need a fresh session."); + return; + } + + let rc = call_and_report("Connect", || unsafe { open_wrapper::connect() }); + if rc.is_ok() { + state.connected = true; + } +} + +fn handle_disconnect(state: &mut ConnectionState) { + if !state.connected { + println!("Not connected yet. Use `connect` first."); + return; + } + + let rc = call_and_report("Disconnect", || unsafe { open_wrapper::disconnect() }); + if rc.is_ok() { + state.connected = false; + } +} + +// fn handle_get_speed() { +// println!("GetSimulationSpeed called ..."); +// let mut sim_speed = 0u32; +// let rc = unsafe { open_wrapper::get_simulation_speed(&mut sim_speed) }; +// if rc.is_ok() { +// println!("Current simulation speed: {sim_speed}%"); +// } +// println!("GetSimulationSpeed returned: {rc:?}"); +// } + +// fn handle_set_speed(value: u32, label: &str) { +// println!("{label} called ..."); +// let rc = unsafe { open_wrapper::set_simulation_speed(value) }; +// println!("{label} returned: {rc:?}"); +// } + +fn call_and_report(action: &str, mut op: impl FnMut() -> OpenReturnCodes) -> OpenReturnCodes { + println!("{action} called ..."); + let rc = op(); + println!("{action} returned: {rc:?}"); + rc +} + +fn print_menu() { + println!("Commands:"); + println!(" (1) connect - connect to the running controller"); + println!(" (2) disconnect - disconnect the session"); + println!(" (3) get-speed - read the current simulation speed"); + println!(" (4) realtime - set speed to 100%"); + println!(" (5) max - set speed to u32::MAX"); + println!(" (h) help - show this list"); + println!(" (q) quit - exit the demo"); +}