using System; using System.Runtime.InteropServices; namespace Bruker.API { [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TRTImageInfoEx { public int Magnification; public double PixelSizeX; // mü pro Pixel public double PixelSizeY; public double HighVoltage; // kV public double WorkingDistance; // mm } [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TSegment { public int Y; public int XStart; public int XCount; } // TSegmentList = array[0..8192] of TSegment; [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TSegmentList { public TSegment[] Segments; } [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TFeatureData // describes 1 scan feature { public int SegmentCount; public TSegmentList Segments; } // TFeatureDataList = array[0..0] of TFeatureData; [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TFeatureDataList { public TFeatureData[] FeatureDatas; } [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] public struct TRTEBSDCalibSettings { public int TiltAngle; public int TiltAzimuthAngle; public int ScanRotation; public int WD; public int DetectorAxis; public int DetectorTilt; public int PhosphorSize; } public class EspritFunctions { #if WIN32 const string rtdll = "Bruker.API.Esprit.DLL"; #else const string rtdll = "Bruker.API.Esprit64.DLL"; #endif /// /// Read current image device configuration /// /// Connection Id /// /// /// /// /// /// Function call sucessful or not( 0 = success, otherwise error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ImageGetConfiguration( uint CID, ref int Width, ref int Height, ref int Average, ref bool Ch1, ref bool Ch2); /// /// Write current image device configuration /// /// Connection Id /// /// /// /// /// /// Function call sucessful or not( 0 = success, otherwise error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ImageSetConfiguration( uint CID, int Width, int Height, int Average, bool Ch1, bool Ch2); /// /// Use external scan engine which triggers our scan generator trough an external signal /// /// Connection Id /// /// Function call sucessful or not( 0 = success, otherwise error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ImageSetExternalScan( uint CID, bool UseExternalScan); /// /// Aquire new image and read image data /// /// Connection Id /// /// /// /// /// /// Function call sucessful or not( 0 = success, otherwise error) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ImageAquireImage( uint CID, int Ch, bool ShowProgress, object Buffer, ref int BufSize, TRTImageInfoEx ImgInfo); /// /// Aquire new image and read image data (extended) /// /// Connection Id /// /// /// /// Bit combination of the following values /// cImgAcq_ShowProgress = 1; /// cImgAcq_UpdateSEMData = 2; /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ImageAquireImageEx( uint CID, int Ch, object Buffer, int Options, ref int BufSize, TRTImageInfoEx ImgInfo); /// /// Read the image field width from scan settings and SEM magnification, microns unit /// /// Connection Id /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ImageGetFieldWidth( uint CID, ref double FieldWidth); /// /// Set electron beam position in image /// /// Connection Id /// /// /// Function call sucessful or not( 0 = success, otherwise error ) // [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ImageSetPoint( uint CID, int X, int Y); // functions to deal with point lists /// /// Start PointList Measurement /// /// connection identifier /// spectrometer index (1..n) /// /// description of points to measure /// acquisition time in ms /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int StartPointListMeasurement( uint CID, int SPU, int SegmentCount, TSegmentList LineSegments, int RealTime); /// /// Start PointList Measurement direct /// /// connection identifier /// spectrometer index (1..n) /// /// description of points to measure /// acquisition time in ms /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int StartPointListMeasurementDirect( uint CID, int SPU, int SegmentCount, TSegmentList LineSegments, int RealTime, bool IsFirst); /// /// Get PointList Spectrum /// /// connection identifier /// spectrum index (1..n) /// buffer to hold complete spectrum with header (around 20kB), must be allocated by caller /// size of spectrum buffer /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetPointListSpectrum( uint CID, int Index, TRTSpectrumHeaderRec SpectrumBuf, int BufSize); /// /// Get PointList Spectrum direct /// /// connection identifier /// spectrum index (1..n) /// buffer to hold complete spectrum with header (around 20kB), must be allocated by caller /// size of spectrum buffer /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetPointListSpectrumDirect( uint CID, int Index, TRTSpectrumHeaderRec SpectrumBuf, int BufSize); /// /// Quantify PointList Spectrum /// /// connection identifier /// spectrum index (1..n) /// /// /// /// /// buffer to hold complete spectrum with header (around 20kB), must be allocated by caller /// size of spectrum buffer /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int QuantifyPointListSpectrum( uint CID, int Index, string MethodName, string Params, [MarshalAs(UnmanagedType.VBByRefStr)] ref string ResultBuf, int ResultBufSize, TRTSpectrumHeaderRec SpectrumBuf, int BufSize); /// /// Save PointList Spectrum /// /// connection identifier /// spectrum index (1..n) /// filename to save to /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SavePointListSpectrum( uint CID, int Buffer, string FileName); /// /// Start FeatureList Measurement /// /// connection identifier /// spectrometer index (1..n) /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) // functions to deal with object lists [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int StartFeatureListMeasurement( uint CID, int SPU, int FeatureCount, TFeatureDataList Features, int[] PixelTimes); /// /// Get FeatureList-Spectrum /// /// connection identifier /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetFeatureListSpectrum( uint CID, int Index, TRTSpectrumHeaderRec SpectrumBuf, int BufSize); /// /// Quantify FeatureList Spectrum /// /// connection identifier /// /// /// /// /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int QuantifyFeatureListSpectrum( uint CID, int Index, string MethodName, string Params, [MarshalAs(UnmanagedType.VBByRefStr)] ref string ResultBuf, int ResultBufSize, TRTSpectrumHeaderRec SpectrumBuf, int BufSize); /// /// Save FeatureList Spectrum /// /// connection identifier /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SaveFeatureListSpectrum( uint CID, int Buffer, string FileName); // functions to communicate with SEM /// /// Set SEM Data /// /// connection identifier /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSEMData( uint CID, double Magnification, double HighVoltage, double WorkingDistance); /// /// Get SEM Data /// /// connection identifier /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMData( uint CID, ref double Magnification, ref double HighVoltage, ref double WorkingDistance); /// /// Get SEM BC-Data /// /// connection identifier /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMBCData( uint CID, ref double Brightness, ref double Contrast); /// /// Set SEM BC-Data /// /// connection identifier /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSEMBCData( uint CID, double Brightness, double Contrast); /// /// Get SEM ProbeCurrent /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMProbeCurrent( uint CID, ref double ProbeCurrent); /// /// Set SEM ProbeCurrent /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSEMProbeCurrent( uint CID, double ProbeCurrent); /// /// Get SEM SpotSize /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMSpotSize( uint CID, ref double SpotSize); /// /// Set SEM SpotSize /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSEMSpotSize( uint CID, double SpotSize); /// /// Set SEM Detector /// /// connection identifier /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSEMDetector( uint CID, int Channel, string DetectorName); /// /// Get SEM Detector /// /// connection identifier /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMDetector( uint CID, int Channel, [MarshalAs(UnmanagedType.VBByRefStr)] ref string DetectorName, int BufSize); /// /// Set SEM Stage Data /// /// connection identifier /// /// /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSEMStageData( uint CID, double XPos, double YPos, double ZPos, double Tilt, double Rotation); /// /// Get SEM Stage Data /// /// connection identifier /// /// /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMStageData( uint CID, ref double XPos, ref double YPos, ref double ZPos, ref double Tilt, ref double Rotation); /// /// Get SEM Stage Range /// /// connection identifier /// /// /// /// /// /// /// /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMStageRange( uint CID, ref double Xmin, ref double Xmax, ref double Ymin, ref double Ymax, ref double Zmin, ref double Zmax, ref double Tmin, ref double Tmax, ref double Rmin, ref double Rmax); /// /// Get SEM Stage State /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMStageState( uint CID, ref int State); /// /// Get SEM Capabilities /// /// connection identifier /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMCapabilities( uint CID, [MarshalAs(UnmanagedType.VBByRefStr)] ref string Capabilities, int BufSize); /// /// Get SEM info /// /// connection identifier /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int GetSEMInfo( uint CID, [MarshalAs(UnmanagedType.VBByRefStr)] ref string Info, int BufSize); /// /// Set SEM External On /// /// connection identifier /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSEMExternalOn( uint CID); /// /// Set SEM External Off /// /// connection identifier /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SetSEMExternalOff( uint CID); /// /// Reset SEM Communication /// /// connection identifier /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int ResetSEMCommunication( uint CID); /// /// Switch SEM Off /// /// connection identifier /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int SwitchSEMOff( uint CID, bool HVOff, bool BeamCurrentOff, bool BeamBlank); // Move EDS detector /// /// Set Position of EDS-Detector /// /// connection identifier /// Detector to be moved ( 1 in most cases ) /// Position to move to ( 1 = Park position, 2 = Acquisition position ) /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EDSSetDetectorPosition( uint CID, int Detector, int Position); /// /// Get Position of EDS-Detector /// /// connection identifier /// Detector to ask for position ( 1 in most cases ) /// Current position ( 1 = Park position, 2 = Acquisition position ) /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EDSGetDetectorPosition( uint CID, int Detector, out int Position); // Mapping functions /// /// Start Hypermapping /// /// connection identifier /// /// Dwell time per Pixel in microseconds /// Acquisition time in s, RealTime=0 does exactly 1 scan /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapStart( uint CID, int SPU, int PixelTime, int RealTime); /// /// Start Hypermapping of Image region /// /// connection identifier /// /// Dwell time per Pixel in microseconds /// Acquisition time in s, RealTime=0 does exactly 1 scan /// Image region to be mapped /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapStartEx( uint CID, int SPU, int PixelTime, int RealTime, TFeatureData Region); /// /// Start Hypermap acquisition with selected setup /// /// connection identifier /// /// Dwell time per Pixel in microseconds /// Image region to be mapped /// Parameter setup /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int HyMapStartWithProfile( uint CID, int SPU, int PixelTime, TFeatureData Region, string Profile); //------------------------------------------------------------------------------------- // EBSD functions //------------------------------------------------------------------------------------- /// /// Retrieve the list of predefined acquisition setups /// /// connection identifier /// buffer to store the list information /// Size of buffer /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetAcquisitionProfiles( uint CID, [MarshalAs(UnmanagedType.VBByRefStr)] ref string Profiles, int BufSize); /// /// Load a predefined acquisition setup /// /// connection identifier /// buffer with profile name to select /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDSelectAcquisitionProfile( uint CID, string Profile); /// /// Start EBSD acquisition with selected setup /// /// connection identifier /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDStartAcquisition( uint CID); /// /// // Start EBSD acquisition with defined profile data /// /// connection identifier /// /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDStartAcquisitionWithProfile( uint CID, string Profile); /// /// Stop EBSD acquisition /// /// connection identifier /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDStopAcquisition( uint CID); /// /// Retrieve EBSD acquisition state /// /// connection identifier /// current acquisition Y -position /// Current state of Acquisition in % /// Current State of Indexing in % /// Is just giving the running state of the Acquisition /// Is just giving the running state of the Indexing /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetAcquisitionState( uint CID, out int CurrentLine, out int PercentReady, out int IndexingPercentReady, out bool AcquisitionRunning, out bool IndexingRunning); /// /// Save EBSD acquisition data to file in Bruker format /// /// connection identifier /// File name for the file to store information (*.bcf) /// Saves EDX Data /// Saves Patterns /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDSaveToFile( uint CID, string FileName, bool WithEdx, bool WithPatterns); // SaveOptions : Bit flags to specify which information has to be stored (frames, detected lines…) /// /// Export Data /// /// connection identifier /// Base file name for the result files to export (map images…) /// longint representation of export options (Phase=2,IPFX=3,IPFY=4,IPFZ=5,Euler=6) /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDExportData( uint CID, string BaseFileName, int ExportOptions); /// /// Export Data /// /// connection identifier /// Memory buffer provided by caller, must be large enough to handle image data /// Maximum size of buffer available, returns size which really used /// longint representation of export options (Phase=2,IPFX=3,IPFY=4,IPFZ=5,Euler=6) /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDExportDataBuffer( uint CID, IntPtr Buffer, ref int BufferSize, int ExportOptions); /// /// Export Results /// /// connection identifier /// Base file name for the result list (ctf-file) to export /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDExportResults( uint CID, string BaseFileName); /// /// Retrieve EBSD detector position /// /// connection identifier /// Detector position in mm /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetDetectorPosition( uint CID, out double Position); /// /// Move EBSD detector to specified position /// /// connection identifier /// Detector position in mm /// Detector speed in mm/s /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDSetDetectorPosition( uint CID, double Position, double Speed); /// /// Start EBSD-Calibration /// /// connection identifier /// /// Settings include: /// TiltAngle of the Detector /// TiltAzimuthAngle of the Detector /// ScanRotation /// WD /// DetectorAxis /// DetectorTilt /// PhosphorSize /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDStartCalibration( uint CID, TRTEBSDCalibSettings Settings); /// /// Stop EBSD Calibration /// /// connection identifier /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDStopCalibration( uint CID); /// /// Get Calibration State /// /// connection identifier /// not yet in use /// Calibration state in % /// Running state of calibration /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetCalibrationState( uint CID, out int CurrentLine, out int PercentReady, out bool Running); /// /// EBSD Save ImageFromPosition /// /// connection identifier /// /// /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDSaveEBSPImageFromPosition( uint CID, string aBaseFilename, int X, int Y); /// /// EBSD SetExposureTime /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDSetExposureTime( uint CID, int ExposureTime); /// /// EBDS Get Exposure Time /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetExposureTime( uint CID, out int ExposureTime); /// /// EBSD Get Image Configuration /// /// connection identifier /// Map width /// Map height /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetImageConfiguration( uint CID, out int Width, out int Height); /// /// Get Camera Configuration /// /// connection identifier /// Current camera width /// Current camera height /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetCameraConfiguration( uint CID, out int Width, out int Height); /// /// EDSB Set Gain /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDSetGain( uint CID, int Value); /// /// EBSD Get Gain /// /// connection identifier /// /// Function call sucessful or not( 0 = success, otherwise error ) [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetGain( uint CID, out int Value); /// /// EBSD Get Tilt /// /// connection identifier /// /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetTilt( uint CID, out double Value); /// /// EBSD Get Available Pattern Format Count /// /// connection identifier /// returns the amount of image format (binning) /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetAvailablePatternFormatCount( uint CID, out int Count); /// /// Get available Pattern Format /// /// connection identifier /// Seletion index of image format /// Camera Width /// Camera Height /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetAvailablePatternFormat( uint CID, int FormatIndex, out int Width, out int Height); /// /// Set Pattern Format /// /// connection identifier /// The choosen Index for Camera Format /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDSetPatternFormat( uint CID, int FormatIndex); /// /// EBSDSetPattern16bitMode /// /// connection identifier /// true (16bit Mode), false (8 bit Mode) /// [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDSetPattern16bitMode( uint CID, bool Value); [DllImport(rtdll, CharSet = CharSet.Ansi)] public static extern int EBSDGetEstimatedMappingTime( uint CID, out int Time); } }