diff --git a/.vscode/launch.json b/.vscode/launch.json index 8c66bab..8c55eb3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "Build", - "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Watcher.dll", + "program": "${workspaceFolder}/bin/Debug/net8.0/linux-x64/File-Watcher.dll", "args": [ "s" ], diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3ff7286..62b99f4 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -64,7 +64,7 @@ "args": [ "publish", "-r", - "win-x64", + "linux-x64", "-c", "Release", "-p:PublishAot=true" @@ -74,7 +74,7 @@ { "label": "File-Folder-Helper AOT s X Day-Helper-2025-03-20", "type": "shell", - "command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe", + "command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/linux-x64/publish/File-Folder-Helper.exe", "args": [ "s", "X", diff --git a/File-Watcher.csproj b/File-Watcher.csproj index 96f74e1..88a3715 100644 --- a/File-Watcher.csproj +++ b/File-Watcher.csproj @@ -3,8 +3,9 @@ enable enable Exe - win-x64 + linux-x64 net8.0 + true true b6f34b8e-5026-41d4-9c28-6516d19d6569 6062c774-99a9-4f4a-b42d-a9cb7fcbd8be @@ -20,7 +21,6 @@ - diff --git a/Helpers/DAQmx/DAQmx.cs b/Helpers/DAQmx/DAQmx.cs index 05c5640..24b4e99 100644 --- a/Helpers/DAQmx/DAQmx.cs +++ b/Helpers/DAQmx/DAQmx.cs @@ -7,7 +7,7 @@ public static class DAQmx public static string GetErrorString(int errorCode) { StringBuilder errorString = new(256); - _ = Interop.DAQmxGetErrorString(errorCode, errorString, (uint)(errorString.Capacity + 1)); + _ = Interop.DAQmxBaseGetErrorString(errorCode, errorString, (uint)(errorString.Capacity + 1)); return errorString.ToString(); } } \ No newline at end of file diff --git a/Helpers/DAQmx/DAQmxTask.cs b/Helpers/DAQmx/DAQmxTask.cs index 0bed946..97c7a67 100644 --- a/Helpers/DAQmx/DAQmxTask.cs +++ b/Helpers/DAQmx/DAQmxTask.cs @@ -26,7 +26,7 @@ public class DAQmxTask { DAQmxTask result; IntPtr taskHandle; - int task = Interop.DAQmxCreateTask(taskName, out taskHandle); + int task = Interop.DAQmxBaseCreateTask(taskName, out taskHandle); if (task < 0) throw new DAQmxException(task, "Could not create Task"); result = new() { taskHandle = taskHandle, Channels = 0 }; @@ -35,14 +35,14 @@ public class DAQmxTask public void ConfigureLoggingTechnicalDataManagementStreaming(string filePath, DAQmxLoggingMode loggingMode, string groupName, DAQmxLoggingTDMSOperation operation) { - int errorCode = Interop.DAQmxConfigureLogging(taskHandle, filePath, (int)loggingMode, groupName, (int)operation); + int errorCode = Interop.DAQmxBaseConfigureLogging(taskHandle, filePath, (int)loggingMode, groupName, (int)operation); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not configure technical data management streaming logging"); } public void CreateAnalogInputVoltageChannel(string physicalChannel, string nameToAssignToChannel, DAQmxInputTerminalConfiguration terminalConfig, double minVal, double maxVal, DAQmxUnits units, string customScaleName) { - int analogInputVoltageChan = Interop.DAQmxCreateAIVoltageChan(taskHandle, physicalChannel, nameToAssignToChannel, (int)terminalConfig, minVal, maxVal, (int)units, customScaleName); + int analogInputVoltageChan = Interop.DAQmxBaseCreateAIVoltageChan(taskHandle, physicalChannel, nameToAssignToChannel, (int)terminalConfig, minVal, maxVal, (int)units, customScaleName); if (analogInputVoltageChan < 0) throw new DAQmxException(analogInputVoltageChan, "Could not create analog input voltage channel"); ++Channels; @@ -50,7 +50,7 @@ public class DAQmxTask public void CreateAnalogOutputVoltageChan(string physicalChannel, string nameToAssignToChannel, double minVal, double maxVal, DAQmxUnits units, string customScaleName) { - int analogOutputVoltageChan = Interop.DAQmxCreateAOVoltageChan(taskHandle, physicalChannel, nameToAssignToChannel, minVal, maxVal, (int)units, customScaleName); + int analogOutputVoltageChan = Interop.DAQmxBaseCreateAOVoltageChan(taskHandle, physicalChannel, nameToAssignToChannel, minVal, maxVal, (int)units, customScaleName); if (analogOutputVoltageChan < 0) throw new DAQmxException(analogOutputVoltageChan, "Could not create analog output voltage channel"); ++Channels; @@ -58,13 +58,13 @@ public class DAQmxTask public void CreateDigitalOutputChanel(string lines, string nameToAssignToLines, DAQmxLineGrouping lineGrouping) { - int doChan = Interop.DAQmxCreateDOChan(taskHandle, lines, nameToAssignToLines, (int)lineGrouping); + int doChan = Interop.DAQmxBaseCreateDOChan(taskHandle, lines, nameToAssignToLines, (int)lineGrouping); if (doChan < 0) throw new DAQmxException(doChan, "Could not create digital output channel"); ++Channels; } -#if unsafe +#if !unsafe public unsafe void ReadAnalogF64(int numSamplesPerChan, double timeout, DAQmxFillMode fillMode, Span data) { int arraySizeInSamples = numSamplesPerChan * Channels; @@ -73,7 +73,7 @@ public class DAQmxTask fixed (double* readArray = &data.GetPinnableReference()) { IntPtr samplesPerChanRead; - int errorCode = Interop.DAQmxReadAnalogF64(taskHandle, numSamplesPerChan, timeout, (int)fillMode, readArray, (uint)arraySizeInSamples, out samplesPerChanRead, IntPtr.Zero); + int errorCode = Interop.DAQmxBaseReadAnalogF64(taskHandle, numSamplesPerChan, timeout, (int)fillMode, readArray, (uint)arraySizeInSamples, out samplesPerChanRead, IntPtr.Zero); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not read samples"); int int32 = samplesPerChanRead.ToInt32(); @@ -88,14 +88,14 @@ public class DAQmxTask public double ReadAnalogScalarF64(double timeout) { double result; - int errorCode = Interop.DAQmxReadAnalogScalarF64(taskHandle, timeout, out result, IntPtr.Zero); + int errorCode = Interop.DAQmxBaseReadAnalogScalarF64(taskHandle, timeout, out result, IntPtr.Zero); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not read samples"); ++TotalSamplesRead; return result; } -#if unsafe +#if !unsafe public double ReadAnalogF64(double timeout) { double result = DAQmxReadAnalogF64(timeout); @@ -103,7 +103,7 @@ public class DAQmxTask } #endif -#if unsafe +#if !unsafe private unsafe double DAQmxReadAnalogF64(double timeout) { double results; @@ -112,7 +112,7 @@ public class DAQmxTask IntPtr samplesPerChanRead = IntPtr.Zero; double* readArray = stackalloc double[1]; int fillMode = (int)DAQmxFillMode.GroupByChannel; - int errorCode = Interop.DAQmxReadAnalogF64(taskHandle, + int errorCode = Interop.DAQmxBaseReadAnalogF64(taskHandle, numSamplesPerChan, timeout, fillMode, @@ -129,7 +129,7 @@ public class DAQmxTask public void Start() { - int errorCode = Interop.DAQmxStartTask(taskHandle); + int errorCode = Interop.DAQmxBaseStartTask(taskHandle); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not start Task"); TaskStartedUtc = DateTime.UtcNow; @@ -137,21 +137,21 @@ public class DAQmxTask public void Stop() { - int errorCode = Interop.DAQmxStopTask(taskHandle); + int errorCode = Interop.DAQmxBaseStopTask(taskHandle); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not stop Task"); } public void Clear() { - int errorCode = Interop.DAQmxClearTask(taskHandle); + int errorCode = Interop.DAQmxBaseClearTask(taskHandle); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not clear Task"); } public void CfgSampleClkTiming(string source, double rate, DAQmxActiveEdge activeEdge, DAQmxSampleMode sampleMode, ulong samplesPerChan) { - int errorCode = Interop.DAQmxCfgSampClkTiming(taskHandle, source, rate, (int)activeEdge, (int)sampleMode, samplesPerChan); + int errorCode = Interop.DAQmxBaseCfgSampClkTiming(taskHandle, source, rate, (int)activeEdge, (int)sampleMode, samplesPerChan); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgSampleClkTiming failed."); DT = 1.0 / SampleClockRate; @@ -159,42 +159,42 @@ public class DAQmxTask public void DAQmxCfgHandshakingTiming(DAQmxSampleMode sampleMode, ulong samplesPerChan) { - int errorCode = Interop.DAQmxCfgHandshakingTiming(taskHandle, (int)sampleMode, samplesPerChan); + int errorCode = Interop.DAQmxBaseCfgHandshakingTiming(taskHandle, (int)sampleMode, samplesPerChan); if (errorCode < 0) throw new DAQmxException(errorCode, "DAQmxCfgHandshakingTiming failed."); } public void DAQmxCfgBurstHandshakingTimingImportClock(DAQmxSampleMode sampleMode, ulong samplesPerChan, double sampleClkRate, string sampleClkSrc, DAQmxPolarity sampleClkActiveEdge, DAQmxLevel pauseWhen, DAQmxPolarity readyEventActiveLevel) { - int errorCode = Interop.DAQmxCfgBurstHandshakingTimingImportClock(taskHandle, (int)sampleMode, samplesPerChan, sampleClkRate, sampleClkSrc, (int)sampleClkActiveEdge, (int)pauseWhen, (int)readyEventActiveLevel); + int errorCode = Interop.DAQmxBaseCfgBurstHandshakingTimingImportClock(taskHandle, (int)sampleMode, samplesPerChan, sampleClkRate, sampleClkSrc, (int)sampleClkActiveEdge, (int)pauseWhen, (int)readyEventActiveLevel); if (errorCode < 0) throw new DAQmxException(errorCode, "DAQmxCfgBurstHandshakingTimingImportClock failed."); } public void DAQmxCfgBurstHandshakingTimingExportClock(DAQmxSampleMode sampleMode, ulong samplesPerChan, double sampleClkRate, string sampleClkOutputTerm, DAQmxPolarity sampleClkPulsePolarity, DAQmxLevel pauseWhen, DAQmxPolarity readyEventActiveLevel) { - int errorCode = Interop.DAQmxCfgBurstHandshakingTimingExportClock(taskHandle, (int)sampleMode, samplesPerChan, sampleClkRate, sampleClkOutputTerm, (int)sampleClkPulsePolarity, (int)pauseWhen, (int)readyEventActiveLevel); + int errorCode = Interop.DAQmxBaseCfgBurstHandshakingTimingExportClock(taskHandle, (int)sampleMode, samplesPerChan, sampleClkRate, sampleClkOutputTerm, (int)sampleClkPulsePolarity, (int)pauseWhen, (int)readyEventActiveLevel); if (errorCode < 0) throw new DAQmxException(errorCode, "DAQmxCfgBurstHandshakingTimingExportClock failed."); } public void DAQmxCfgChangeDetectionTiming(string risingEdgeChan, string fallingEdgeChan, DAQmxSampleMode sampleMode, ulong samplesPerChan) { - int errorCode = Interop.DAQmxCfgChangeDetectionTiming(taskHandle, risingEdgeChan, fallingEdgeChan, (int)sampleMode, samplesPerChan); + int errorCode = Interop.DAQmxBaseCfgChangeDetectionTiming(taskHandle, risingEdgeChan, fallingEdgeChan, (int)sampleMode, samplesPerChan); if (errorCode < 0) throw new DAQmxException(errorCode, "DAQmxCfgChangeDetectionTiming failed."); } public void DAQmxCfgImplicitTiming(DAQmxSampleMode sampleMode, ulong samplesPerChan) { - int errorCode = Interop.DAQmxCfgImplicitTiming(taskHandle, (int)sampleMode, samplesPerChan); + int errorCode = Interop.DAQmxBaseCfgImplicitTiming(taskHandle, (int)sampleMode, samplesPerChan); if (errorCode < 0) throw new DAQmxException(errorCode, "DAQmxCfgImplicitTiming failed."); } public void DAQmxCfgPipelinedSampleClkTiming(string source, double rate, DAQmxActiveEdge activeEdge, DAQmxSampleMode sampleMode, ulong samplesPerChan) { - int errorCode = Interop.DAQmxCfgPipelinedSampClkTiming(taskHandle, source, rate, (int)activeEdge, (int)sampleMode, samplesPerChan); + int errorCode = Interop.DAQmxBaseCfgPipelinedSampClkTiming(taskHandle, source, rate, (int)activeEdge, (int)sampleMode, samplesPerChan); if (errorCode < 0) throw new DAQmxException(errorCode, "DAQmxCfgPipelinedSampleClkTiming failed."); } @@ -204,14 +204,14 @@ public class DAQmxTask get { double result = 0.0; - int sampleClkRate = Interop.DAQmxGetSampClkRate(taskHandle, ref result); + int sampleClkRate = Interop.DAQmxBaseGetSampClkRate(taskHandle, ref result); if (sampleClkRate < 0) throw new DAQmxException(sampleClkRate, "Could not get SampleClockRate"); return result; } set { - int errorCode = Interop.DAQmxSetSampClkRate(taskHandle, value); + int errorCode = Interop.DAQmxBaseSetSampClkRate(taskHandle, value); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not set SampleClockRate"); } @@ -222,7 +222,7 @@ public class DAQmxTask get { double result = 0.0; - int sampleClkMaxRate = Interop.DAQmxGetSampClkMaxRate(taskHandle, ref result); + int sampleClkMaxRate = Interop.DAQmxBaseGetSampClkMaxRate(taskHandle, ref result); if (sampleClkMaxRate < 0) throw new DAQmxException(sampleClkMaxRate, "Could not get SampleClockMaxRate"); return result; @@ -231,21 +231,21 @@ public class DAQmxTask public void DisableStartTrig() { - int errorCode = Interop.DAQmxDisableStartTrig(taskHandle); + int errorCode = Interop.DAQmxBaseDisableStartTrig(taskHandle); if (errorCode < 0) throw new DAQmxException(errorCode, "DisableStartTrig failed."); } public void CfgDigEdgeStartTrig(string triggerSource, DAQmxEdge triggerEdge) { - int errorCode = Interop.DAQmxCfgDigEdgeStartTrig(taskHandle, triggerSource, (int)triggerEdge); + int errorCode = Interop.DAQmxBaseCfgDigEdgeStartTrig(taskHandle, triggerSource, (int)triggerEdge); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgDigEdgeStartTrig failed."); } public void CfgAnalogEdgeStartTrig(string triggerSource, DAQmxEdge triggerSlope, double triggerLevel) { - int errorCode = Interop.DAQmxCfgAnlgEdgeStartTrig(taskHandle, triggerSource, (int)triggerSlope, triggerLevel); + int errorCode = Interop.DAQmxBaseCfgAnlgEdgeStartTrig(taskHandle, triggerSource, (int)triggerSlope, triggerLevel); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgAnalogEdgeStartTrig failed."); } @@ -255,42 +255,42 @@ public class DAQmxTask public void CfgAnalogWindowStartTrig(string triggerSource, DAQmxWindowTriggerWhen triggerWhen, double windowTop, double windowBottom) { - int errorCode = Interop.DAQmxCfgAnlgWindowStartTrig(taskHandle, triggerSource, (int)triggerWhen, windowTop, windowBottom); + int errorCode = Interop.DAQmxBaseCfgAnlgWindowStartTrig(taskHandle, triggerSource, (int)triggerWhen, windowTop, windowBottom); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgAnalogWindowStartTrig failed."); } public void CfgTimeStartTrig(CVIAbsoluteTime when, DAQmxTimescale timescale) { - int errorCode = Interop.DAQmxCfgTimeStartTrig(taskHandle, when, (int)timescale); + int errorCode = Interop.DAQmxBaseCfgTimeStartTrig(taskHandle, when, (int)timescale); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgTimeStartTrig failed."); } public void CfgDigPatternStartTrig(string triggerSource, string triggerPattern, DAQmxDigitalPatternTriggerWhen triggerWhen) { - int errorCode = Interop.DAQmxCfgDigPatternStartTrig(taskHandle, triggerSource, triggerPattern, (int)triggerWhen); + int errorCode = Interop.DAQmxBaseCfgDigPatternStartTrig(taskHandle, triggerSource, triggerPattern, (int)triggerWhen); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgDigPatternStartTrig failed."); } public void DisableRefTrig() { - int errorCode = Interop.DAQmxDisableRefTrig(taskHandle); + int errorCode = Interop.DAQmxBaseDisableRefTrig(taskHandle); if (errorCode < 0) throw new DAQmxException(errorCode, "DisableRefTrig failed."); } public void CfgDigEdgeRefTrig(string triggerSource, DAQmxEdge triggerEdge, uint pretriggerSamples) { - int errorCode = Interop.DAQmxCfgDigEdgeRefTrig(taskHandle, triggerSource, (int)triggerEdge, pretriggerSamples); + int errorCode = Interop.DAQmxBaseCfgDigEdgeRefTrig(taskHandle, triggerSource, (int)triggerEdge, pretriggerSamples); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgDigEdgeRefTrig failed."); } public void CfgAnalogEdgeRefTrig(string triggerSource, DAQmxEdge triggerSlope, double triggerLevel, uint pretriggerSamples) { - int errorCode = Interop.DAQmxCfgAnlgEdgeRefTrig(taskHandle, triggerSource, (int)triggerSlope, triggerLevel, pretriggerSamples); + int errorCode = Interop.DAQmxBaseCfgAnlgEdgeRefTrig(taskHandle, triggerSource, (int)triggerSlope, triggerLevel, pretriggerSamples); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgAnalogEdgeRefTrig failed."); } @@ -300,14 +300,14 @@ public class DAQmxTask public void CfgAnalogWindowRefTrig(string triggerSource, DAQmxWindowTriggerWhen triggerWhen, double windowTop, double windowBottom, uint pretriggerSamples) { - int errorCode = Interop.DAQmxCfgAnlgWindowRefTrig(taskHandle, triggerSource, (int)triggerWhen, windowTop, windowBottom, pretriggerSamples); + int errorCode = Interop.DAQmxBaseCfgAnlgWindowRefTrig(taskHandle, triggerSource, (int)triggerWhen, windowTop, windowBottom, pretriggerSamples); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgAnalogWindowRefTrig failed."); } public void CfgDigPatternRefTrig(string triggerSource, string triggerPattern, DAQmxDigitalPatternTriggerWhen triggerWhen, uint pretriggerSamples) { - int errorCode = Interop.DAQmxCfgDigPatternRefTrig(taskHandle, triggerSource, triggerPattern, (int)triggerWhen, pretriggerSamples); + int errorCode = Interop.DAQmxBaseCfgDigPatternRefTrig(taskHandle, triggerSource, triggerPattern, (int)triggerWhen, pretriggerSamples); if (errorCode < 0) throw new DAQmxException(errorCode, "CfgDigPatternRefTrig failed."); } @@ -318,7 +318,7 @@ public class DAQmxTask if (data.Length < num) throw new DAQmxMemoryException("Span length too short. (Span length: " + data.Length.ToString() + ", required length: " + num.ToString() + ")"); IntPtr samplesPerChanWritten; - int errorCode = Interop.DAQmxWriteAnalogF64(taskHandle, numSamplesPerChan, autoStart, timeout, dataLayout > DAQmxDataLayout.GroupByChannel, data.ToArray(), out samplesPerChanWritten, IntPtr.Zero); + int errorCode = Interop.DAQmxBaseWriteAnalogF64(taskHandle, numSamplesPerChan, autoStart, timeout, dataLayout > DAQmxDataLayout.GroupByChannel, data.ToArray(), out samplesPerChanWritten, IntPtr.Zero); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not write samples"); int int32 = samplesPerChanWritten.ToInt32(); @@ -334,7 +334,7 @@ public class DAQmxTask if (data.Length < num) throw new DAQmxMemoryException("Span length too short. (Span length: " + data.Length.ToString() + ", required length: " + num.ToString() + ")"); IntPtr samplesPerChanWritten; - int errorCode = Interop.DAQmxWriteDigitalLines(taskHandle, numSamplesPerChan, autoStart, timeout, dataLayout > DAQmxDataLayout.GroupByChannel, data.ToArray(), out samplesPerChanWritten, IntPtr.Zero); + int errorCode = Interop.DAQmxBaseWriteDigitalLines(taskHandle, numSamplesPerChan, autoStart, timeout, dataLayout > DAQmxDataLayout.GroupByChannel, data.ToArray(), out samplesPerChanWritten, IntPtr.Zero); if (errorCode < 0) throw new DAQmxException(errorCode, "Could not write samples"); int int32 = samplesPerChanWritten.ToInt32(); diff --git a/Helpers/DAQmx/Interop.cs b/Helpers/DAQmx/Interop.cs index e53ad85..a671609 100644 --- a/Helpers/DAQmx/Interop.cs +++ b/Helpers/DAQmx/Interop.cs @@ -10,7 +10,7 @@ namespace Helpers.DAQmx; internal class Interop { // cSpell:disable - private const string lib = "DAQmx"; + private const string lib = "DAQmxBase"; private static IntPtr libHandle = IntPtr.Zero; static Interop() => @@ -18,7 +18,7 @@ internal class Interop private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) { - if (libraryName == "DAQmx" && !(libHandle != IntPtr.Zero)) + if (libraryName == "DAQmxBase" && !(libHandle != IntPtr.Zero)) { bool loaded; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -41,20 +41,20 @@ internal class Interop return libHandle; } - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxGetSampClkRate(IntPtr taskHandle, ref double data); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseGetSampClkRate(IntPtr taskHandle, ref double data); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxSetSampClkRate(IntPtr taskHandle, double data); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseSetSampClkRate(IntPtr taskHandle, double data); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxGetSampClkMaxRate(IntPtr taskHandle, ref double data); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseGetSampClkMaxRate(IntPtr taskHandle, ref double data); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxSetWriteRegenMode(IntPtr taskHandle, int data); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseSetWriteRegenMode(IntPtr taskHandle, int data); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCreateAIVoltageChan( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCreateAIVoltageChan( IntPtr taskHandle, string physicalChannel, string nameToAssignToChannel, @@ -64,8 +64,8 @@ internal class Interop int units, string customScaleName); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCreateAOVoltageChan( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCreateAOVoltageChan( IntPtr taskHandle, string physicalChannel, string nameToAssignToChannel, @@ -74,22 +74,22 @@ internal class Interop int units, string customScaleName); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCreateDOChan( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCreateDOChan( IntPtr taskHandle, string lines, string nameToAssignToLines, int lineGrouping); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxGetErrorString( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseGetErrorString( int errorCode, StringBuilder errorString, uint buffersize); -#if unsafe - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern unsafe int DAQmxReadAnalogF64( +#if !unsafe + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern unsafe int DAQmxBaseReadAnalogF64( IntPtr taskHandle, int numSampsPerChan, double timeout, @@ -100,16 +100,16 @@ internal class Interop IntPtr reserved); #endif - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxReadAnalogScalarF64( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseReadAnalogScalarF64( IntPtr taskHandle, double timeout, out double value, IntPtr reserved); #if unsafe - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern unsafe int DAQmxReadBinaryI16( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern unsafe int DAQmxBaseReadBinaryI16( IntPtr taskHandle, int numSampsPerChan, double timeout, @@ -121,8 +121,8 @@ internal class Interop #endif #if unsafe - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern unsafe int DAQmxReadBinaryU16( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern unsafe int DAQmxBaseReadBinaryU16( IntPtr taskHandle, int numSampsPerChan, double timeout, @@ -134,8 +134,8 @@ internal class Interop #endif #if unsafe - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern unsafe int DAQmxReadBinaryI32( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern unsafe int DAQmxBaseReadBinaryI32( IntPtr taskHandle, int numSampsPerChan, double timeout, @@ -147,8 +147,8 @@ internal class Interop #endif #if unsafe - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern unsafe int DAQmxReadBinaryU32( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern unsafe int DAQmxBaseReadBinaryU32( IntPtr taskHandle, int numSampsPerChan, double timeout, @@ -159,59 +159,59 @@ internal class Interop IntPtr reserved); #endif - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxConfigureLogging( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseConfigureLogging( IntPtr taskHandle, string filePath, int loggingMode, string groupName, int operation); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxLoadTask(string taskName, out IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseLoadTask(string taskName, out IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCreateTask(string taskName, out IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCreateTask(string taskName, out IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxAddGlobalChansToTask(IntPtr taskHandle, string[] channelNames); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseAddGlobalChansToTask(IntPtr taskHandle, string[] channelNames); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxStartTask(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseStartTask(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxStopTask(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseStopTask(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxClearTask(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseClearTask(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxWaitUntilTaskDone(IntPtr taskHandle, double timeToWait); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseWaitUntilTaskDone(IntPtr taskHandle, double timeToWait); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxWaitForValidTimestamp( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseWaitForValidTimestamp( IntPtr taskHandle, int timestampEvent, double timeout, CVIAbsoluteTime timestamp); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxIsTaskDone(IntPtr taskHandle, out uint isTaskDone); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseIsTaskDone(IntPtr taskHandle, out uint isTaskDone); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxTaskControl(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseTaskControl(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxGetNthTaskChannel(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseGetNthTaskChannel(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxGetNthTaskDevice(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseGetNthTaskDevice(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxGetTaskAttribute(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseGetTaskAttribute(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCfgSampClkTiming( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCfgSampClkTiming( IntPtr taskHandle, string source, double rate, @@ -219,14 +219,14 @@ internal class Interop int sampleMode, ulong sampsPerChan); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCfgHandshakingTiming( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCfgHandshakingTiming( IntPtr taskHandle, int sampleMode, ulong sampsPerChan); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCfgBurstHandshakingTimingImportClock( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCfgBurstHandshakingTimingImportClock( IntPtr taskHandle, int sampleMode, ulong sampsPerChan, @@ -236,8 +236,8 @@ internal class Interop int pauseWhen, int readyEventActiveLevel); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCfgBurstHandshakingTimingExportClock( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCfgBurstHandshakingTimingExportClock( IntPtr taskHandle, int sampleMode, ulong sampsPerChan, @@ -247,22 +247,22 @@ internal class Interop int pauseWhen, int readyEventActiveLevel); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCfgChangeDetectionTiming( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCfgChangeDetectionTiming( IntPtr taskHandle, string risingEdgeChan, string fallingEdgeChan, int sampleMode, ulong sampsPerChan); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCfgImplicitTiming( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCfgImplicitTiming( IntPtr taskHandle, int sampleMode, ulong sampsPerChan); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxCfgPipelinedSampClkTiming( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseCfgPipelinedSampClkTiming( IntPtr taskHandle, string source, double rate, @@ -270,106 +270,106 @@ internal class Interop int sampleMode, ulong sampsPerChan); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxGetTimingAttribute( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseGetTimingAttribute( IntPtr taskHandle, int attribute, out object value); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxSetTimingAttribute( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseSetTimingAttribute( IntPtr taskHandle, int attribute, object value); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxResetTimingAttribute(IntPtr taskHandle, int attribute); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseResetTimingAttribute(IntPtr taskHandle, int attribute); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxGetTimingAttributeEx( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseGetTimingAttributeEx( IntPtr taskHandle, string deviceNames, int attribute, out object value); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxSetTimingAttributeEx( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseSetTimingAttributeEx( IntPtr taskHandle, string deviceNames, int attribute, object value); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - internal static extern int DAQmxResetTimingAttributeEx( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + internal static extern int DAQmxBaseResetTimingAttributeEx( IntPtr taskHandle, string deviceNames, int attribute); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxDisableStartTrig(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseDisableStartTrig(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgDigEdgeStartTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgDigEdgeStartTrig( IntPtr taskHandle, string triggerSource, int triggerEdge); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgAnlgEdgeStartTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgAnlgEdgeStartTrig( IntPtr taskHandle, string triggerSource, int triggerSlope, double triggerLevel); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgAnlgMultiEdgeStartTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgAnlgMultiEdgeStartTrig( IntPtr taskHandle, string triggerSources, int[] triggerSlopeArray, double[] triggerLevelArray, uint arraySize); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgAnlgWindowStartTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgAnlgWindowStartTrig( IntPtr taskHandle, string triggerSource, int triggerWhen, double windowTop, double windowBottom); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgTimeStartTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgTimeStartTrig( IntPtr taskHandle, CVIAbsoluteTime when, int timescale); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgDigPatternStartTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgDigPatternStartTrig( IntPtr taskHandle, string triggerSource, string triggerPattern, int triggerWhen); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxDisableRefTrig(IntPtr taskHandle); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseDisableRefTrig(IntPtr taskHandle); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgDigEdgeRefTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgDigEdgeRefTrig( IntPtr taskHandle, string triggerSource, int triggerEdge, uint pretriggerSamples); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgAnlgEdgeRefTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgAnlgEdgeRefTrig( IntPtr taskHandle, string triggerSource, int triggerSlope, double triggerLevel, uint pretriggerSamples); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgAnlgMultiEdgeRefTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgAnlgMultiEdgeRefTrig( IntPtr taskHandle, string triggerSources, int[] triggerSlopeArray, @@ -377,8 +377,8 @@ internal class Interop uint pretriggerSamples, uint arraySize); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgAnlgWindowRefTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgAnlgWindowRefTrig( IntPtr taskHandle, string triggerSource, int triggerWhen, @@ -386,28 +386,28 @@ internal class Interop double windowBottom, uint pretriggerSamples); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxCfgDigPatternRefTrig( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseCfgDigPatternRefTrig( IntPtr taskHandle, string triggerSource, string triggerPattern, int triggerWhen, uint pretriggerSamples); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxGetTrigAttribute( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseGetTrigAttribute( IntPtr taskHandle, int attribute, out object value); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxSetTrigAttribute(IntPtr taskHandle, int attribute, object value); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseSetTrigAttribute(IntPtr taskHandle, int attribute, object value); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxResetTrigAttribute(IntPtr taskHandle, int attribute); + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseResetTrigAttribute(IntPtr taskHandle, int attribute); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxWriteAnalogF64( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseWriteAnalogF64( IntPtr taskHandle, int numSampsPerChan, bool autoStart, @@ -417,8 +417,8 @@ internal class Interop out IntPtr sampsPerChanWritten, IntPtr reserved); - [DllImport("DAQmx", CallingConvention = CallingConvention.StdCall)] - public static extern int DAQmxWriteDigitalLines( + [DllImport("DAQmxBase", CallingConvention = CallingConvention.StdCall)] + public static extern int DAQmxBaseWriteDigitalLines( IntPtr taskHandle, int numSampsPerChan, bool autoStart, diff --git a/Helpers/NationalInstrumentsHelper.cs b/Helpers/NationalInstrumentsHelper.cs index 9a586b3..5c16ef9 100644 --- a/Helpers/NationalInstrumentsHelper.cs +++ b/Helpers/NationalInstrumentsHelper.cs @@ -39,8 +39,9 @@ internal static partial class NationalInstrumentsHelper foreach (KeyValuePair keyValuePair in _DataAcquisitionTasks) { if (appSettings.NationalInstrumentsConfiguration.UsePointerMethod) - throw new NotSupportedException("Pointer method is not supported in this implementation."); - value = keyValuePair.Value.ReadAnalogScalarF64(appSettings.NationalInstrumentsConfiguration.ReadTimeout); + value = keyValuePair.Value.ReadAnalogF64(appSettings.NationalInstrumentsConfiguration.ReadTimeout); + else + value = keyValuePair.Value.ReadAnalogScalarF64(appSettings.NationalInstrumentsConfiguration.ReadTimeout); logger.LogInformation("{key}-{read}: {value}", keyValuePair.Key, keyValuePair.Value.TotalSamplesRead, value); } return true; diff --git a/Worker.cs b/Worker.cs index dd9ce5e..0b107f5 100644 --- a/Worker.cs +++ b/Worker.cs @@ -43,11 +43,6 @@ public partial class Worker : BackgroundService private async Task Body(CancellationToken cancellationToken) { - if (!_IsWindowsService) - { - _Logger.LogInformation("Set break point and skip to run {_AppSettings.FileWatcherConfiguration.Helper}!", _AppSettings.FileWatcherConfiguration.Helper); - throw new EvaluateException($"Set break point and skip to run {_AppSettings.FileWatcherConfiguration.Helper}!"); - } if (!_IsWindowsService) { for (int i = 0; i < int.MaxValue; i++)