431 lines
15 KiB
C#
431 lines
15 KiB
C#
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
#pragma warning disable IDE1006 // Naming Styles
|
|
#pragma warning disable SYSLIB1054 // Type or member is obsolete
|
|
|
|
namespace Helpers.DAQmx;
|
|
|
|
internal class Interop
|
|
{ // cSpell:disable
|
|
|
|
private const string lib = "DAQmxBase";
|
|
private static IntPtr libHandle = IntPtr.Zero;
|
|
|
|
static Interop() =>
|
|
NativeLibrary.SetDllImportResolver(typeof(Interop).Assembly, ImportResolver);
|
|
|
|
private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
|
{
|
|
if (libraryName == "DAQmxBase" && !(libHandle != IntPtr.Zero))
|
|
{
|
|
bool loaded;
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
loaded = NativeLibrary.TryLoad("C:/Windows/System32/nicaiu.dll", assembly, searchPath, out libHandle);
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
{
|
|
loaded = NativeLibrary.TryLoad("/usr/local/lib64/libnidaqmxbase.so", assembly, searchPath, out libHandle);
|
|
if (!loaded)
|
|
loaded = NativeLibrary.TryLoad("/usr/local/lib/libnidaqmxbase.so", assembly, searchPath, out libHandle);
|
|
if (!loaded)
|
|
loaded = NativeLibrary.TryLoad("/usr/local/natinst/lib/libnidaqmx.so", assembly, searchPath, out libHandle);
|
|
if (!loaded)
|
|
loaded = NativeLibrary.TryLoad("/usr/lib/x86_64-linux-gnu/libnidaqmx.so", assembly, searchPath, out libHandle);
|
|
}
|
|
else
|
|
throw new PlatformNotSupportedException("Unsupported platform for DAQmx library.");
|
|
if (!loaded)
|
|
throw new DllNotFoundException($"Failed to load {lib} library.");
|
|
}
|
|
return libHandle;
|
|
}
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseGetSampClkRate(IntPtr taskHandle, ref double data);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseSetSampClkRate(IntPtr taskHandle, double data);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseGetSampClkMaxRate(IntPtr taskHandle, ref double data);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseSetWriteRegenMode(IntPtr taskHandle, int data);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCreateAIVoltageChan(
|
|
IntPtr taskHandle,
|
|
string physicalChannel,
|
|
string nameToAssignToChannel,
|
|
int terminalConfig,
|
|
double minVal,
|
|
double maxVal,
|
|
int units,
|
|
string customScaleName);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCreateAOVoltageChan(
|
|
IntPtr taskHandle,
|
|
string physicalChannel,
|
|
string nameToAssignToChannel,
|
|
double minVal,
|
|
double maxVal,
|
|
int units,
|
|
string customScaleName);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCreateDOChan(
|
|
IntPtr taskHandle,
|
|
string lines,
|
|
string nameToAssignToLines,
|
|
int lineGrouping);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseGetErrorString(
|
|
int errorCode,
|
|
StringBuilder errorString,
|
|
uint buffersize);
|
|
|
|
#if !unsafe
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern unsafe int DAQmxBaseReadAnalogF64(
|
|
IntPtr taskHandle,
|
|
int numSampsPerChan,
|
|
double timeout,
|
|
int fillMode,
|
|
double* readArray,
|
|
uint arraySizeInSamps,
|
|
out IntPtr sampsPerChanRead,
|
|
IntPtr reserved);
|
|
#endif
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseReadAnalogScalarF64(
|
|
IntPtr taskHandle,
|
|
double timeout,
|
|
out double value,
|
|
IntPtr reserved);
|
|
|
|
#if unsafe
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern unsafe int DAQmxBaseReadBinaryI16(
|
|
IntPtr taskHandle,
|
|
int numSampsPerChan,
|
|
double timeout,
|
|
int fillMode,
|
|
bool* readArray,
|
|
uint arraySizeInSamps,
|
|
out IntPtr sampsPerChanRead,
|
|
IntPtr reserved);
|
|
#endif
|
|
|
|
#if unsafe
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern unsafe int DAQmxBaseReadBinaryU16(
|
|
IntPtr taskHandle,
|
|
int numSampsPerChan,
|
|
double timeout,
|
|
int fillMode,
|
|
ushort* readArray,
|
|
uint arraySizeInSamps,
|
|
out IntPtr sampsPerChanRead,
|
|
IntPtr reserved);
|
|
#endif
|
|
|
|
#if unsafe
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern unsafe int DAQmxBaseReadBinaryI32(
|
|
IntPtr taskHandle,
|
|
int numSampsPerChan,
|
|
double timeout,
|
|
int fillMode,
|
|
int* readArray,
|
|
uint arraySizeInSamps,
|
|
out IntPtr sampsPerChanRead,
|
|
IntPtr reserved);
|
|
#endif
|
|
|
|
#if unsafe
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern unsafe int DAQmxBaseReadBinaryU32(
|
|
IntPtr taskHandle,
|
|
int numSampsPerChan,
|
|
double timeout,
|
|
int fillMode,
|
|
uint* readArray,
|
|
uint arraySizeInSamps,
|
|
out IntPtr sampsPerChanRead,
|
|
IntPtr reserved);
|
|
#endif
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseConfigureLogging(
|
|
IntPtr taskHandle,
|
|
string filePath,
|
|
int loggingMode,
|
|
string groupName,
|
|
int operation);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseLoadTask(string taskName, out IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCreateTask(string taskName, out IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseAddGlobalChansToTask(IntPtr taskHandle, string[] channelNames);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseStartTask(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseStopTask(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseClearTask(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseWaitUntilTaskDone(IntPtr taskHandle, double timeToWait);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseWaitForValidTimestamp(
|
|
IntPtr taskHandle,
|
|
int timestampEvent,
|
|
double timeout,
|
|
CVIAbsoluteTime timestamp);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseIsTaskDone(IntPtr taskHandle, out uint isTaskDone);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseTaskControl(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseGetNthTaskChannel(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseGetNthTaskDevice(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseGetTaskAttribute(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCfgSampClkTiming(
|
|
IntPtr taskHandle,
|
|
string source,
|
|
double rate,
|
|
int activeEdge,
|
|
int sampleMode,
|
|
ulong sampsPerChan);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCfgHandshakingTiming(
|
|
IntPtr taskHandle,
|
|
int sampleMode,
|
|
ulong sampsPerChan);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCfgBurstHandshakingTimingImportClock(
|
|
IntPtr taskHandle,
|
|
int sampleMode,
|
|
ulong sampsPerChan,
|
|
double sampleClkRate,
|
|
string sampleClkSrc,
|
|
int sampleClkActiveEdge,
|
|
int pauseWhen,
|
|
int readyEventActiveLevel);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCfgBurstHandshakingTimingExportClock(
|
|
IntPtr taskHandle,
|
|
int sampleMode,
|
|
ulong sampsPerChan,
|
|
double sampleClkRate,
|
|
string sampleClkOutpTerm,
|
|
int sampleClkPulsePolarity,
|
|
int pauseWhen,
|
|
int readyEventActiveLevel);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCfgChangeDetectionTiming(
|
|
IntPtr taskHandle,
|
|
string risingEdgeChan,
|
|
string fallingEdgeChan,
|
|
int sampleMode,
|
|
ulong sampsPerChan);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCfgImplicitTiming(
|
|
IntPtr taskHandle,
|
|
int sampleMode,
|
|
ulong sampsPerChan);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseCfgPipelinedSampClkTiming(
|
|
IntPtr taskHandle,
|
|
string source,
|
|
double rate,
|
|
int activeEdge,
|
|
int sampleMode,
|
|
ulong sampsPerChan);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseGetTimingAttribute(
|
|
IntPtr taskHandle,
|
|
int attribute,
|
|
out object value);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseSetTimingAttribute(
|
|
IntPtr taskHandle,
|
|
int attribute,
|
|
object value);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseResetTimingAttribute(IntPtr taskHandle, int attribute);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseGetTimingAttributeEx(
|
|
IntPtr taskHandle,
|
|
string deviceNames,
|
|
int attribute,
|
|
out object value);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseSetTimingAttributeEx(
|
|
IntPtr taskHandle,
|
|
string deviceNames,
|
|
int attribute,
|
|
object value);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern int DAQmxBaseResetTimingAttributeEx(
|
|
IntPtr taskHandle,
|
|
string deviceNames,
|
|
int attribute);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseDisableStartTrig(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgDigEdgeStartTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSource,
|
|
int triggerEdge);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgAnlgEdgeStartTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSource,
|
|
int triggerSlope,
|
|
double triggerLevel);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgAnlgMultiEdgeStartTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSources,
|
|
int[] triggerSlopeArray,
|
|
double[] triggerLevelArray,
|
|
uint arraySize);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgAnlgWindowStartTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSource,
|
|
int triggerWhen,
|
|
double windowTop,
|
|
double windowBottom);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgTimeStartTrig(
|
|
IntPtr taskHandle,
|
|
CVIAbsoluteTime when,
|
|
int timescale);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgDigPatternStartTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSource,
|
|
string triggerPattern,
|
|
int triggerWhen);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseDisableRefTrig(IntPtr taskHandle);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgDigEdgeRefTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSource,
|
|
int triggerEdge,
|
|
uint pretriggerSamples);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgAnlgEdgeRefTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSource,
|
|
int triggerSlope,
|
|
double triggerLevel,
|
|
uint pretriggerSamples);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgAnlgMultiEdgeRefTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSources,
|
|
int[] triggerSlopeArray,
|
|
double[] triggerLevelArray,
|
|
uint pretriggerSamples,
|
|
uint arraySize);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgAnlgWindowRefTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSource,
|
|
int triggerWhen,
|
|
double windowTop,
|
|
double windowBottom,
|
|
uint pretriggerSamples);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseCfgDigPatternRefTrig(
|
|
IntPtr taskHandle,
|
|
string triggerSource,
|
|
string triggerPattern,
|
|
int triggerWhen,
|
|
uint pretriggerSamples);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseGetTrigAttribute(
|
|
IntPtr taskHandle,
|
|
int attribute,
|
|
out object value);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseSetTrigAttribute(IntPtr taskHandle, int attribute, object value);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseResetTrigAttribute(IntPtr taskHandle, int attribute);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseWriteAnalogF64(
|
|
IntPtr taskHandle,
|
|
int numSampsPerChan,
|
|
bool autoStart,
|
|
double timeout,
|
|
bool dataLayout,
|
|
double[] writeArray,
|
|
out IntPtr sampsPerChanWritten,
|
|
IntPtr reserved);
|
|
|
|
[DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int DAQmxBaseWriteDigitalLines(
|
|
IntPtr taskHandle,
|
|
int numSampsPerChan,
|
|
bool autoStart,
|
|
double timeout,
|
|
bool dataLayout,
|
|
byte[] writeArray,
|
|
out IntPtr sampsPerChanWritten,
|
|
IntPtr reserved);
|
|
|
|
} |