|
1 | 1 | using System; |
2 | 2 | using System.Collections; |
| 3 | +using System.IO; |
3 | 4 | using System.Linq; |
4 | 5 |
|
5 | 6 | namespace OpenEphys.Onix1 |
@@ -33,22 +34,36 @@ public NeuropixelsV1eRegisterContext(DeviceContext deviceContext, uint i2cAddres |
33 | 34 | bool apFilter, string gainCalibrationFile, string adcCalibrationFile) |
34 | 35 | : base(deviceContext, i2cAddress) |
35 | 36 | { |
36 | | - if (gainCalibrationFile == null || adcCalibrationFile == null) |
| 37 | + if (!File.Exists(gainCalibrationFile)) |
37 | 38 | { |
38 | | - throw new ArgumentException("Calibration files must be specified."); |
| 39 | + throw new ArgumentException($"A gain calibration file must be specified for the probe with serial number " + |
| 40 | + $"{probeSerialNumber}"); |
39 | 41 | } |
40 | 42 |
|
41 | | - System.IO.StreamReader gainFile = new(gainCalibrationFile); |
42 | | - var calSerialNumber = ulong.Parse(gainFile.ReadLine()); |
| 43 | + if (!File.Exists(adcCalibrationFile)) |
| 44 | + { |
| 45 | + throw new ArgumentException($"An ADC calibration file must be specified for the probe with serial number " + |
| 46 | + $"{probeSerialNumber}"); |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + var gainFile = new StreamReader(gainCalibrationFile); |
| 51 | + var sn = ulong.Parse(gainFile.ReadLine()); |
43 | 52 |
|
44 | | - if (calSerialNumber != probeSerialNumber) |
45 | | - throw new ArgumentException("Gain calibration file serial number does not match probe serial number."); |
| 53 | + if (sn != probeSerialNumber) |
| 54 | + { |
| 55 | + throw new ArgumentException($"The probe serial number ({probeSerialNumber}) does not " + |
| 56 | + $"match the gain calibration file serial number: {sn}."); |
| 57 | + } |
46 | 58 |
|
47 | | - System.IO.StreamReader adcFile = new(adcCalibrationFile); |
48 | | - var adcSerialNumber = ulong.Parse(adcFile.ReadLine()); |
| 59 | + var adcFile = new StreamReader(adcCalibrationFile); |
| 60 | + sn = ulong.Parse(adcFile.ReadLine()); |
49 | 61 |
|
50 | | - if (adcSerialNumber != probeSerialNumber) |
51 | | - throw new ArgumentException("ADC calibration file serial number does not match probe serial number."); |
| 62 | + if (sn != probeSerialNumber) |
| 63 | + { |
| 64 | + throw new ArgumentException($"The probe serial number ({probeSerialNumber}) does not " + |
| 65 | + $"match the ADC calibration file serial number: {sn}."); |
| 66 | + } |
52 | 67 |
|
53 | 68 | // parse gain correction file |
54 | 69 | var gainCorrections = gainFile.ReadLine().Split(',').Skip(1); |
|
0 commit comments