diff --git a/OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs b/OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs index 1ccd955..f9c0275 100644 --- a/OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs +++ b/OpenEphys.Onix1/NeuropixelsV1eRegisterContext.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.IO; using System.Linq; namespace OpenEphys.Onix1 @@ -33,22 +34,36 @@ public NeuropixelsV1eRegisterContext(DeviceContext deviceContext, uint i2cAddres bool apFilter, string gainCalibrationFile, string adcCalibrationFile) : base(deviceContext, i2cAddress) { - if (gainCalibrationFile == null || adcCalibrationFile == null) + if (!File.Exists(gainCalibrationFile)) { - throw new ArgumentException("Calibration files must be specified."); + throw new ArgumentException($"A gain calibration file must be specified for the probe with serial number " + + $"{probeSerialNumber}"); } - System.IO.StreamReader gainFile = new(gainCalibrationFile); - var calSerialNumber = ulong.Parse(gainFile.ReadLine()); + if (!File.Exists(adcCalibrationFile)) + { + throw new ArgumentException($"An ADC calibration file must be specified for the probe with serial number " + + $"{probeSerialNumber}"); + } + + + var gainFile = new StreamReader(gainCalibrationFile); + var sn = ulong.Parse(gainFile.ReadLine()); - if (calSerialNumber != probeSerialNumber) - throw new ArgumentException("Gain calibration file serial number does not match probe serial number."); + if (sn != probeSerialNumber) + { + throw new ArgumentException($"The probe serial number ({probeSerialNumber}) does not " + + $"match the gain calibration file serial number: {sn}."); + } - System.IO.StreamReader adcFile = new(adcCalibrationFile); - var adcSerialNumber = ulong.Parse(adcFile.ReadLine()); + var adcFile = new StreamReader(adcCalibrationFile); + sn = ulong.Parse(adcFile.ReadLine()); - if (adcSerialNumber != probeSerialNumber) - throw new ArgumentException("ADC calibration file serial number does not match probe serial number."); + if (sn != probeSerialNumber) + { + throw new ArgumentException($"The probe serial number ({probeSerialNumber}) does not " + + $"match the ADC calibration file serial number: {sn}."); + } // parse gain correction file var gainCorrections = gainFile.ReadLine().Split(',').Skip(1); diff --git a/OpenEphys.Onix1/NeuropixelsV2.cs b/OpenEphys.Onix1/NeuropixelsV2.cs index ccf7aec..af5b9ac 100644 --- a/OpenEphys.Onix1/NeuropixelsV2.cs +++ b/OpenEphys.Onix1/NeuropixelsV2.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.IO; namespace OpenEphys.Onix1 { @@ -116,13 +117,13 @@ internal static BitArray[] GenerateBaseBits(NeuropixelsV2QuadShankProbeConfigura internal static double ReadGainCorrection(string gainCalibrationFile, ulong probeSerialNumber, NeuropixelsV2Probe probe) { - if (gainCalibrationFile == null) + if (!File.Exists(gainCalibrationFile) ) { throw new ArgumentException($"A calibration file must be specified for {probe} with serial number " + - $"{probeSerialNumber})"); + $"{probeSerialNumber}"); } - System.IO.StreamReader gainFile = new(gainCalibrationFile); + var gainFile = new StreamReader(gainCalibrationFile); var sn = ulong.Parse(gainFile.ReadLine()); if (probeSerialNumber != sn)