using System; using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Bruker.API { [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)] public struct TRTHardwareConfiguration { [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.I4, SizeConst = 4)] public int[] EDSDetector; // [0..3] is SPU [MarshalAs(UnmanagedType.I1)] public bool EBSD; // EBSD present [MarshalAs(UnmanagedType.I1)] public bool Raster; // Scan engine present public int XrayTubes; // Number of Xray tubes } [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TRTSpectrumHeaderRec { [MarshalAs(UnmanagedType.ByValTStr, SizeConst=25)] public string Identifier; // 'Rontec XRay spectrum' public int Version; // Version information public int Size; // Size in byte public double DateTime; // Delphi 5.0 version of date and time public int ChannelCount; // public int ChannelOffset; // First channel index public double CalibrationAbs; // Energy of first channel public double CalibrationLin; // keV per channel public double SigmaAbs; // Sigma^2 energy calibration public double SigmaLin; public int RealTime; // real measure time in ms public int LifeTime; // life time in ms } [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TRTCalibSettings { public int Version; // Version of record structure, should be '1' at the moment public int Element1; public string Line1; public double Energy1; public int Element2; public string Line2; public double Energy2; public int MaxTime; // Maximum time to calibrate in ms, '0' indicates to use a internal statistics to decide to stop public bool ShowProgress; // Show progress information } [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TRTCalibResults { public int Version; // Version of record structure, should be '1' at the moment public double CalibLin; // Channel with in keV public double CalibAbs; // Energy offset in keV public double FWHM; // Mn FWHM in keV public double Fano; // Fano factor } [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TRTSpectrometerRanges { [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.I4, SizeConst = 8)] public int[] MaxEnergy; [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.I4, SizeConst = 8)] public int[] PulseThroughPut; public int EnergyIndexCount; public int PulseIndexCount; } // structure to describe Quantax start options in 'OpenClientEx' [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TOpenClientOptions { public int Version; // Version of record structure, should be '1' at the moment public int GUIMode; // '0'=no GUI, '1'=full GUI, '2'=reduced GUI (spectrum chart only) public bool StartNew; // start new instance of Quantax } // structure for Delphi's TPoint [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TPoint { public int X; public int Y; } // structure for Delphi's TPointArray [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TPointArray { public TPoint[] Points; } // structure for Delphi's TPointerArray [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TPointerArray { public TRTSpectrumHeaderRec[] Pointers; } /// /// BrukerException-Class /// public class BrukerException : Exception { public BrukerException(string message) : base(message) { } } /// /// CommonFunctions-Class /// public class CommonFunctions { #if WIN32 const string rtdll = "Bruker.API.Esprit.DLL"; #else const string rtdll = "Bruker.API.Esprit64.DLL"; #endif // Error constants generated from client program public const int IFC_ERROR_IN_EXECUTION = -1; public const int IFC_ERROR_WRONG_PARAMETER = -2; public const int IFC_ERROR_SPECTRUM_BUFFER_EMPTY = -3; public const int IFC_ERROR_PARAMETER_MISSED = -4; public const int IFC_ERROR_TOO_MANY_PARAMETERS = -5; public const int IFC_ERROR_USER_TERMINATED = -6; public const int IFC_ERROR_TIMEOUT = -7; public const int IFC_ERROR_UNKNOWN_VALUE_NAME = -8; public const int IFC_ERROR_WRONG_VALUE_TYPE = -9; public const int IFC_ERROR_WRONG_LICENCE = -10; public const int IFC_ERROR_RESULT_BUFFER_INSUFFICIENT= -11; public const int IFC_ERROR_HARDWARE_LOCKED = -12; public const int IFC_ERROR_PARAMETER_MISSED_1 = -51; public const int IFC_ERROR_FUNCTION_NOT_IMPLEMENTED = -52; // Errors coming from OpenClient() public const int CONN_ERROR_UNKNOWN = -21; public const int CONN_ERROR_INTERFACE_NOT_CONNECTED = -22; public const int CONN_ERROR_PARAMETER_MISSED = -23; public const int CONN_ERROR_ANSWER_TIMEOUT = -24; public const int CONN_ERROR_SERVER_NOT_RESPONDING = -25; public const int CONN_ERROR_RESULT_MISSED = -26; public const int CONN_ERROR_NO_INTERFACE = -27; public const int CONN_ERROR_INVALID_LOGIN = -28; public const int CONN_ERROR_NO_CONNECTION_TO_SERVER = -29; public const int CONN_ERROR_SERVER = -30; public const int CONN_ERROR_ACTION_ABORTED = -31; // Error constants generated from Bruker.API.XXX.dll public const int ERROR_WRONG_PARAMETER = -101; public const int ERROR_FILE_NOT_EXIST = -102; public const int ERROR_NO_CONNECTION = -103; public const int ERROR_NO_ANSWER = -104; public const int ERROR_CAN_NOT_START_PROCESS = -105; public const int ERROR_INVALID_RESULT_DATA = -106; public const int ERROR_SETTINGS_NOT_FOUND = -107; public const int ERROR_NO_SERVER_CONNECTION = -108; // no direct call to server possible (used in '..Direct' calls public const int ERROR_IN_EXECUTION = -109; // State constants generated from Bruker.API.XXX.dll public const int STATE_WAS_RUNNING_BEFORE = -201; //Element Names public static string[] ElementName = { "null", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Uut", "Fl", "Uup", "Lv", "Uus", "Uuo" }; /// /// Handler for BrukerApiReturnValues /// if BrukerApiReturnValue <> 0, an BrukerException will be generated. /// /// the Return Value of BrukerApi-Function-Call /// BrukerApiCallReturnValue public static int HandleReturnValue(int BrukerApiCallReturnValue) { if (BrukerApiCallReturnValue == -1) throw new BrukerException("Bruker.API: IFC_ERROR_IN_EXECUTION"); else if (BrukerApiCallReturnValue == -2) throw new BrukerException("Bruker.API: IFC_ERROR_WRONG_PARAMETER"); else if (BrukerApiCallReturnValue == -3) throw new BrukerException("Bruker.API: IFC_ERROR_SPECTRUM_BUFFER_EMPTY"); else if (BrukerApiCallReturnValue == -4) throw new BrukerException("Bruker.API: FC_ERROR_PARAMETER_MISSED"); else if (BrukerApiCallReturnValue == -5) throw new BrukerException("Bruker.API: IFC_ERROR_TOO_MANY_PARAMETERS"); else if (BrukerApiCallReturnValue == -6) throw new BrukerException("Bruker.API: IFC_ERROR_USER_TERMINATED"); else if (BrukerApiCallReturnValue == -7) throw new BrukerException("Bruker.API: IFC_ERROR_TIMEOUT"); else if (BrukerApiCallReturnValue == -8) throw new BrukerException("Bruker.API: IFC_ERROR_UNKNOWN_VALUE_NAME"); else if (BrukerApiCallReturnValue == -9) throw new BrukerException("Bruker.API: IFC_ERROR_WRONG_VALUE_TYPE"); else if (BrukerApiCallReturnValue == -10) throw new BrukerException("Bruker.API: IFC_ERROR_WRONG_LICENCE"); else if (BrukerApiCallReturnValue == -11) throw new BrukerException("Bruker.API: IFC_ERROR_RESULT_BUFFER_INSUFFICIENT"); else if (BrukerApiCallReturnValue == -12) throw new BrukerException("Bruker.API: IFC_ERROR_HARDWARE_LOCKED"); else if (BrukerApiCallReturnValue == -51) throw new BrukerException("Bruker.API: IFC_ERROR_PARAMETER_MISSED_1"); else if (BrukerApiCallReturnValue == -52) throw new BrukerException("Bruker.API: IFC_ERROR_FUNCTION_NOT_IMPLEMENTED"); else if (BrukerApiCallReturnValue == -21) throw new BrukerException("Bruker.API: CONN_ERROR_UNKNOWN"); else if (BrukerApiCallReturnValue == -22) throw new BrukerException("Bruker.API: CONN_ERROR_INTERFACE_NOT_CONNECTED"); else if (BrukerApiCallReturnValue == -23) throw new BrukerException("Bruker.API: CONN_ERROR_PARAMETER_MISSED"); else if (BrukerApiCallReturnValue == -24) throw new BrukerException("Bruker.API: CONN_ERROR_ANSWER_TIMEOUT"); else if (BrukerApiCallReturnValue == -25) throw new BrukerException("Bruker.API: CONN_ERROR_SERVER_NOT_RESPONDING"); else if (BrukerApiCallReturnValue == -26) throw new BrukerException("Bruker.API: CONN_ERROR_RESULT_MISSED"); else if (BrukerApiCallReturnValue == -27) throw new BrukerException("Bruker.API: CONN_ERROR_NO_INTERFACE"); else if (BrukerApiCallReturnValue == -28) throw new BrukerException("Bruker.API: CONN_ERROR_INVALID_LOGIN"); else if (BrukerApiCallReturnValue == -29) throw new BrukerException("Bruker.API: CONN_ERROR_NO_CONNECTION_TO_SERVER"); else if (BrukerApiCallReturnValue == -30) throw new BrukerException("Bruker.API: CONN_ERROR_SERVER"); else if (BrukerApiCallReturnValue == -31) throw new BrukerException("Bruker.API: CONN_ERROR_ACTION_ABORTED"); else if (BrukerApiCallReturnValue == -101) throw new BrukerException("Bruker.API: ERROR_WRONG_PARAMETER"); else if (BrukerApiCallReturnValue == -102) throw new BrukerException("Bruker.API: ERROR_FILE_NOT_EXIST"); else if (BrukerApiCallReturnValue == -103) throw new BrukerException("Bruker.API: ERROR_NO_CONNECTION"); else if (BrukerApiCallReturnValue == -104) throw new BrukerException("Bruker.API: ERROR_NO_ANSWER"); else if (BrukerApiCallReturnValue == -105) throw new BrukerException("Bruker.API: ERROR_CAN_NOT_START_PROCESS"); else if (BrukerApiCallReturnValue == -106) throw new BrukerException("Bruker.API: ERROR_INVALID_RESULT_DATA"); else if (BrukerApiCallReturnValue == -107) throw new BrukerException("Bruker.API: ERROR_SETTINGS_NOT_FOUND"); else if (BrukerApiCallReturnValue == -108) throw new BrukerException("Bruker.API: ERROR_NO_SERVER_CONNECTION"); else if (BrukerApiCallReturnValue == -109) throw new BrukerException("ERROR_IN_EXECUTION"); else if (BrukerApiCallReturnValue == -201) throw new BrukerException("Bruker.API: STATE_WAS_RUNNING_BEFORE"); else if (BrukerApiCallReturnValue != 0) throw new BrukerException("Bruker.API: Unknown Bruker Error #" + BrukerApiCallReturnValue.ToString()); return BrukerApiCallReturnValue; } public static string RclCommand(int Device, string Command) { string s = "".PadRight(1000); int r = SendRCLCommand(FCID, Device, Command, ref s, 1000); return s; } //---------------------------------------------------------------------------------- // Interface functions of Bruker.API.XXX library //---------------------------------------------------------------------------------- /// /// Set log level for internal API logging /// 0 : no logging /// 1 : Error logging /// 2 : Warning logging /// 3 : All logging /// /// /// Error code (0 = no error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetLogLevel( int Value); /// /// Ask for log data, transfered log data are removed from internal API log after this call /// /// /// Error code (0 = no error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetLogData( [MarshalAs(UnmanagedType.VBByRefStr)] ref string Buffer, ref uint BufferSize); /// /// Clear API log data /// /// Error code (0 = no error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ClearLogData(); /// /// Save API log data to file /// /// /// Error code (0 = no error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SaveLogData( [MarshalAs(UnmanagedType.LPWStr)] string FileName); /// /// Set active language for interface, 'ge' for german, any other for english /// /// /// Error code (0 = no error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetLanguage( string Language); /// /// Query all known servers for which can be used by client program /// /// /// /// Error code (0 = no error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int QueryServers( [MarshalAs(UnmanagedType.VBByRefStr)] ref string pServerList, int BufSize); /// /// Query all running client programs for connected servers /// /// /// /// /// Error code (0 = no error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int QueryUser( string pServer, [MarshalAs(UnmanagedType.VBByRefStr)] ref string pClientBuf, int BufSize); /// /// Start Quantax program and login automatically /// /// Server name /// User name /// Password of user with User Name /// /// Whether to start the user interface or not /// Connection Id /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int OpenClient( string pServer, string pUser, string pPassword, bool StartNew, bool GUI, ref uint CID); /// /// Start Quantax programm and login automatically /// /// Server name /// User Name /// Password of User with User Name /// TOpenClientOptions Structur /// Connection Id /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int OpenClientEx( string pServer, string pUser, string pPassword, ref TOpenClientOptions Options, ref uint CID); /// /// Start Quantax programm and login automatically /// /// Server name /// User Name /// Password of User with User Name /// TOpenClientOptions Structur /// Connection Id /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int OpenClientTCP( string pServer, string pUser, string pPassword, string pHost, ushort pPort, ref TOpenClientOptions Options, ref uint CID); /// /// query some information about a specific connection /// /// Connection Id /// StringBuffer (contains informations about connection /// Size of Buffer /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int QueryInfo( uint CID, [MarshalAs(UnmanagedType.VBByRefStr)] ref string pInfo, int BufSize); /// /// Close corrent connection /// /// Connection Id /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int CloseConnection( uint CID); /// /// Stop Quantax /// /// Connection Id /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int CloseClient( uint CID); /// /// Is a specific client connection ok? /// /// Connection Id /// 0, if connection ok, otherwise error-no [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int CheckConnection( uint CID); /// /// Combine Spectrometer /// /// Connection Id /// bit combination of spectrometers to combine /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int CombineSpectrometer( uint CID, int Devices); /// /// Starts Realtime Measurement /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Measure time in ms ( 0 means endless measurement ) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int StartSpectrumMeasurement( uint CID, int Device, int RealTime); /// /// Starts Lifetime Measurement /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Life time in ms ( > 0 ) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int StartSpectrumLifeTimeMeasurement( uint CID, int Device, int LifeTime); /// /// Starts Counter Measuremnet /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Spectrum region low border for counter measurement (in keV) /// Spectrum region high border for counter measurement (in keV) /// Counter value for automatic measurement stop /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int StartSpectrumCounterMeasurement( uint CID, int SPU, double StartEnergy, double EndEnergy, int Counts); /// /// Stops current Measurement /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int StopSpectrumMeasurement( uint CID, int Device); /// /// Read some values about current aquisition /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Aquisition active or not /// State of aquisition in % ( 100 % means ready ) /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSpectrumMeasureState( uint CID, int Device, ref bool Running, ref double State, ref double PulseRate); /// /// Read some more values about current aquisition /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Aquisition active or not /// State of aquisition in % ( 100 % means ready ) /// current input pulse rate in cps /// current measure time in ms /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSpectrumMeasureStateEx( uint CID, int Device, ref bool Running, ref double State, ref double PulseRate, ref int RealTime); /// /// Read current spectrum from spectrometer to buffer /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ReadSpectrum( uint CID, int Device); /// /// Get Spectrometer Configuration /// /// Connection Id /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSpectrometerConfiguration( uint CID, int SPU, ref uint MaxEnergy, ref uint PulseThroughput); /// /// Get Spectrometer Configuration /// /// Connection Id /// /// Detector-Number /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSpectrometerConfigurationEx( uint CID, int SPU, int Det, ref uint MaxEnergy, ref uint PulseThroughput); /// /// Sets Spectrometer Configuration /// /// Connection Id /// /// Detector-Number /// /// /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSpectrometerConfiguration( uint CID, int SPU, int Det, uint MaxEnergyIndex, uint PulseThroughputIndex); /// /// Sets active Detectors /// /// /// /// Active Detectors as bitmask (1 shl 0, etc.) /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetActiveDetectors( uint CID, int SPU, int Detectors); /// /// Get active Detectors /// /// /// /// Active Detectors as bitmask (1 shl 0, etc.) /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetActiveDetectors( uint CID, int SPU, out int Detectors); /// /// Get active Detectors /// /// /// /// Available Detectors as bitmask (1 shl 0, etc.) /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetAvailableDetectors( uint CID, int SPU, out int Detectors); /// /// Get active Detectors /// /// /// /// Available WDS Detectors as bitmask (1 shl 0, etc.) /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetAvailableWDSDetectors( uint CID, int SPU, out int Detectors); /// /// Get Hardware Configuration /// /// /// /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetHardwareConfiguration( uint CID, out TRTHardwareConfiguration aHardwareConfiguration); /// /// Calibrates the Spectrometer /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int CalibrateSpectrometer( uint CID, int Device, bool ShowProgress, TRTCalibSettings Settings, TRTCalibResults Results); /// /// Get Spectrometer Parameter /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// /// Name of the parameter to read /// Current implemented names: 'MaxEnergy', 'PulseThroughput', 'DetectorTemperature' as 'longint' or 'Double' /// /// Type of the parameter to read (Byte,Boolean,Word,longint,Double,Memory) /// Pointer to variable of that type /// if ParamType is Memory than BufSize if size of the memory block described by 'Buffer' /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSpectrometerParam( uint CID, int Device, string ParamName, string ParamType, object Buffer, int BufSize); /// /// Read full parameter block of current spectrometer params (needed to create full Bruker spectrum) /// /// Connection Id /// /// /// /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSpectrometerParams( uint CID, int SPU, [MarshalAs(UnmanagedType.VBByRefStr)] ref string Buffer, ref int BufSize); /// /// /// /// Connection Id /// Buffer index ( 0 for loaded spectrum buffer, > 0 for spectrometer buffers ) /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSpectrum( uint CID, int Buffer, TRTSpectrumHeaderRec pSpectrumBuf, int BufSize); /// /// Quantifies Spectrum /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int QuantifySpectrum( uint CID, int Buffer, string pMethodName, string pParams, [MarshalAs(UnmanagedType.VBByRefStr)] ref string pResultBuf, int ResultBufSize); /// /// Sends a RCL 2.2 command to spectrometer and returns the answer( see RCL 2.2 description of commands ) /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SendRCLCommand( uint CID, int Device, string pCommand, [MarshalAs(UnmanagedType.VBByRefStr)] ref string pAnswer, int AnswerBufSize); /// /// Sends a RCL 2.2 command to spectrometer, does not wait for answer ( see RCL 2.2 description of commands ) /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SendRCLCommandOnly( uint CID, int Device, string Command); /// /// Receives the answer of the SendRCLCommandOnly function /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) // [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ReceiveRCLAnswer( uint CID, int Device, [MarshalAs(UnmanagedType.VBByRefStr)] ref string Answer, int AnswerBufSize); /// /// Interupts QM100's communication to specified device until 'UnlockSpectrometer' is called /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int LockSpectrometer( uint CID, int Device); /// /// Starts QM100's communication to specified device after 'LockSpectrometer' was called /// /// Connection Id /// Number of spectrometer ( 1 in most cases ) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int UnlockSpectrometer( uint CID, int Device); /// /// Load spectrum from file to buffer /// /// Connection Id /// Complete filename for spectrum ( normally with *.spx extension ) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int LoadSpectrum( uint CID, string pFileName); /// /// Send spectrum back to 'loaded' buffer /// if one wants to use that function one has to build a complete Bruker spectrum with /// functions 'GetSpectrum', 'GetSpectrometerParams' and 'CreateSpectrum' /// /// Connection Id /// Bruker spectrum buffer /// size of spectrum buffer /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int PutSpectrum( uint CID, [MarshalAs(UnmanagedType.VBByRefStr)] ref string Spectrum, int BufSize); /// /// Save spectrum buffer to file /// /// Connection Id /// /// Complete filename for spectrum ( normally with *.spx extension ) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SaveSpectrum( uint CID, int Buffer, string pFileName); /// /// Create a complete Bruker spectrum from /// /// /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int CreateSpectrum( string SpectrometerParams, TRTSpectrumHeaderRec SpectrumData, [MarshalAs(UnmanagedType.VBByRefStr)] ref string ResultData, ref int ResultSize); /// /// Get Corrected Spectrum /// /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetCorrectedSpectrum( string SpectrometerParams, TRTSpectrumHeaderRec Spectrum, double ResultData); /// /// Shows Spectrum /// /// Connection Id /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ShowSpectrum( uint CID, int Buffer, string Name); /// /// Delete Spectrum /// /// Connection Id /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int DeleteSpectrum( uint CID, string aName); /// /// Get a list of avaliable hardware profiles from client /// /// Connection Id /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetHardwareProfiles( uint CID, [MarshalAs(UnmanagedType.VBByRefStr)] ref string pProfiles, int BufSize); /// /// Set a specific hardware profile /// /// Connection Id /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) // Set a specific hardware profile [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetHardwareProfile( uint CID, string pProfile); /// /// Get a list of avaliable quantification methods /// /// Connection Id /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetQuantificationMethods( uint CID, bool AutomaticOnly, [MarshalAs(UnmanagedType.VBByRefStr)] ref string pMethods, int BufSize); /// /// Get a list of predefined elements from a given quant method /// /// Connection Id /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetQuantificationMethodElements( uint CID, string MethodName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string ElementBuffer, int BufSize); /// /// Call method editor for a given quant method /// /// Connection Id /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EditQuantificationMethod( uint CID, string MethodName); /// /// Get a channel region for desired element and X ray line /// /// Connection Id /// /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetRegionForElement( uint CID, int Buffer, string Params, [MarshalAs(UnmanagedType.VBByRefStr)] ref string ResultBuf, int ResultBufSize); // Xray tube functions /// /// XRay Tube Set Configuration /// /// Connection Id /// /// tube voltage [Volt] /// tube current [µA] /// index of selected filter /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int XRayTubeSetConfiguration( uint CID, int Tube, int HighVoltage, int Current, int FilterIndex); /// /// XRay Tube Get State /// /// Connection Id /// /// tube voltate [Volt] /// tube current [µA] /// index of selected filter /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int XRayTubeGetState( uint CID, int Tube, out int HighVoltage, out int Current, out int FilterIndex, out bool ShutterOpen); /// /// XRay Tube Open Shutter /// /// Connection Id /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int XRayTubeOpenShutter( uint CID, int Tube); /// /// XRay Tube Close Shutter /// /// Connection Id /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int XRayTubeCloseShutter( uint CID, int Tube); /// /// XRay Set active tube /// /// Connection Id /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int XRaySetActiveTube( uint CID, int Tube); /// /// XRay Get active tube /// /// Connection Id /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int XRaySetActiveTube( uint CID, out int Tube); // Hypermap functions, function 'HyMapStart' is specific for Esprit/M4 /// /// Hypermap Stop /// /// Connection Id /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapStop( uint CID, bool WaitForFrameEnd); /// /// Clear Hypermap database structure /// /// Connection Id /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapClearDatabase( uint CID); /// /// Gets Hypermap State /// /// Connection Id /// acquisition active or not /// state of acquisition in % /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapGetState( uint CID, ref bool Running, ref double MeasureState); /// /// Gets more Informations about Hypermap State /// /// Connection Id /// acquisition active or not /// state of acquisition in % /// line which is currently scanned (0...map height-1) /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapGetStateEx( uint CID, ref bool Running, ref double MeasureState, ref int CurrentLine); /// /// Hypermap Get XY-Spectrum /// /// Connection Id /// /// /// /// SpectrumBuffer : pointer to memory, must have space for one full spectrum /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapGetXYSpectrum( uint CID, int X, int Y, bool Corrected, TRTSpectrumHeaderRec SpectrumBuffer, int BufferSize); /// /// Hypermap GetLineSpectra /// /// Connection Id /// /// /// /// /// pointer to array of pointers for spectra, must have space for 'Count' pointers, each with allocated space for a full spectrum /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapGetLineSpectra( uint CID, int X, int Y, int Count, bool Corrected, TPointerArray SpectrumBuffer, ref int BufferSize); /// /// Hypermap GetCompressedLineSpectra /// /// Connection Id /// /// /// /// /// pointer to array of pointers for spectra, must have space for 'Count' pointers, each with allocated space for a full spectrum /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapCompressedGetLineSpectra( uint CID, int X, int Y, int Count, bool Corrected, TPointerArray SpectrumBuffer, ref int BufferSize); /// /// Hypermap Quantifiy Spectra /// /// Connection Id /// /// /// /// /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapQuantifySpectra( uint CID, TPointArray Points, int PointCount, int Binning, string MethodName, string Params, [MarshalAs(UnmanagedType.VBByRefStr)] ref string ResultBuf, int ResultBufSize); /// /// Hapermap Save to File /// /// Connection Id /// file name /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapSaveToFile( uint CID, string aFileName); /// /// Hypermap Load from File /// /// Connection Id /// file name /// /// /// /// /// Function call sucessful or not ( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapLoadFromFile( uint CID, string aFileName, out int Width, out int Height, out int DetCount, out int ImgCount); /// /// Extract a mixed map image /// /// Image format which shell be used for image buffer creation, can be 'bmp','png','tif','jpg' /// Memory buffer provided by caller, must be large enough to handle image data /// Maximum size of buffer available, returns size which really used /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapGetMixedMapImage( uint CID, string Format, IntPtr Buffer, ref int BufferSize); /// /// Extract an element image for a predefined element /// /// Image format which shell be used for image buffer creation, can be 'bmp','png','tif','jpg' /// Index into list of previously defined elements from 'InitializeSpectrumDatabaseElementIntensities' /// Memory buffer provided by caller, must be large enough to handle image data /// Maximum size of buffer available, returns size which really used /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapGetElementImage( uint CID, string Format, int ElementIndex, object Buffer, ref int BufferSize); public static uint FCID = 0; public static string Servername = "Lokaler Server"; public static string Username = "edx"; public static string Password = "edx"; public static string TCPHost = "127.0.0.1"; public static int TCPPort = 5328; } }