using File_Watcher.Models; using Helpers.DAQmx; namespace File_Watcher.Helpers; internal static partial class NationalInstrumentsHelper { private static Dictionary? _DataAcquisitionTasks = null; internal static bool WriteData(AppSettings appSettings, ILogger logger) { double value; LogNetToHoursSince(logger); if (_DataAcquisitionTasks is null) { string name; _DataAcquisitionTasks = []; DAQmxTask dataAcquisitionTask; const DAQmxUnits volts = DAQmxUnits.Volts; NationalInstrumentsConfiguration ni = appSettings.NationalInstrumentsConfiguration; const DAQmxInputTerminalConfiguration differential = DAQmxInputTerminalConfiguration.Differential; const DAQmxInputTerminalConfiguration referencedSingleEnded = DAQmxInputTerminalConfiguration.ReferencedSingleEnded; foreach (string physicalChannel in appSettings.NationalInstrumentsConfiguration.DifferentialPhysicalChannels.Distinct()) { name = !physicalChannel.Contains('/') ? physicalChannel : physicalChannel.Split('/')[1]; dataAcquisitionTask = DAQmxTask.Create(name); dataAcquisitionTask.CreateAnalogInputVoltageChannel(physicalChannel, name, differential, ni.MiniumValue, ni.MaximumValue, volts, ni.CustomScaleName); _DataAcquisitionTasks.Add(name, dataAcquisitionTask); } foreach (string physicalChannel in appSettings.NationalInstrumentsConfiguration.ReferencedSingleEndedPhysicalChannels.Distinct()) { name = !physicalChannel.Contains('/') ? physicalChannel : physicalChannel.Split('/')[1]; dataAcquisitionTask = DAQmxTask.Create(name); dataAcquisitionTask.CreateAnalogInputVoltageChannel(physicalChannel, name, referencedSingleEnded, ni.MiniumValue, ni.MaximumValue, volts, ni.CustomScaleName); _DataAcquisitionTasks.Add(name, dataAcquisitionTask); } } 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); logger.LogInformation("{key}-{read}: {value}", keyValuePair.Key, keyValuePair.Value.TotalSamplesRead, value); } return true; } private static void LogNetToHoursSince(ILogger? logger) { double secondsInAHour = 3600f; long epoch = new DateTime(1970, 1, 1).Ticks; long net8ReleaseDate = new DateTime(2023, 11, 14).Ticks; long net9ReleaseDate = new DateTime(2024, 11, 12).Ticks; long net10ReleaseDate = new DateTime(2026, 01, 01).Ticks; long framework48ReleaseDate = new DateTime(2019, 04, 18).Ticks; double net8TotalSeconds = new TimeSpan(net8ReleaseDate - epoch).TotalSeconds; double net9TotalSeconds = new TimeSpan(net9ReleaseDate - epoch).TotalSeconds; double net10TotalSeconds = new TimeSpan(net10ReleaseDate - epoch).TotalSeconds; double framework48TotalSeconds = new TimeSpan(framework48ReleaseDate - epoch).TotalSeconds; logger?.LogInformation("It has been {net8TotalSeconds} seconds since net8 was released", net8TotalSeconds); logger?.LogInformation("It has been {net9TotalSeconds} seconds since net9 was released", net9TotalSeconds); logger?.LogInformation("It has been {net10TotalSeconds} seconds since net10 was released", net10TotalSeconds); logger?.LogInformation("It has been {framework48TotalSeconds} seconds since framework48 was released", framework48TotalSeconds); double net8TotalHours = Math.Floor((DateTimeOffset.UtcNow.ToUnixTimeSeconds() - net8TotalSeconds) / secondsInAHour); double net9TotalHours = Math.Floor((DateTimeOffset.UtcNow.ToUnixTimeSeconds() - net9TotalSeconds) / secondsInAHour); double net10TotalHours = Math.Floor((DateTimeOffset.UtcNow.ToUnixTimeSeconds() - net10TotalSeconds) / secondsInAHour); double framework48TotalHours = Math.Floor((DateTimeOffset.UtcNow.ToUnixTimeSeconds() - framework48TotalSeconds) / secondsInAHour); logger?.LogInformation("It has been {net8TotalHours} hours since net8 was released", net8TotalHours); logger?.LogInformation("It has been {net9TotalHours} hours since net9 was released", net9TotalHours); logger?.LogInformation("It has been {net10TotalHours} hours since net10 was released", net10TotalHours); logger?.LogInformation("It has been {framework48TotalHours} hours since framework48 was released", framework48TotalHours); } }