using System.Threading; using DTS.Common.Interface.DASFactory; using DTS.DASLib.Command.SLICE; namespace DTS.DASLib.Service { public class SLICEBaseInputReader { private readonly ICommunication _comm; public SLICEBaseInputReader(DTS.Common.Interface.DASFactory.ICommunication comm) { _comm = comm; } public virtual double InputMilliVolts { get { var measure = new MeasureBaseDiagnosticChannel(_comm); measure.Channel = MeasureBaseDiagnosticChannel.BaseDiagnosticChannelList.InputVoltage; measure.DeviceGroup = 0; measure.DeviceID = 0; measure.SyncExecute(); return measure.Measurement * 1000.0; } } public virtual double TemperatureC { get { var measure = new MeasureBaseDiagnosticChannel(_comm); measure.Channel = MeasureBaseDiagnosticChannel.BaseDiagnosticChannelList.TemperatureC; measure.DeviceGroup = 0; measure.DeviceID = 0; measure.SyncExecute(); return measure.Measurement; } } public bool BatteryIsCharging { get { var setSwitch = new QuerySwitchImmediate(_comm); setSwitch.Switch = (byte)Switches.BaseSwitches.ChargeStatus; setSwitch.SwitchText = Switches.BaseSwitches.ChargeStatus.ToString(); setSwitch.SyncExecute(); return setSwitch.Setting == 1; } } public virtual double DirectBackupMilliVolts { get { if (!ShouldMeasureBackupPower()) { return 0D; } var measure = new MeasureBaseDiagnosticChannel(_comm); measure.Channel = MeasureBaseDiagnosticChannel.BaseDiagnosticChannelList.BackupVoltage; measure.DeviceGroup = 0; measure.DeviceID = 0; measure.SyncExecute(); return measure.Measurement * 1000.0; } } /// /// returns true if the unit should check/enable/disable backup power /// originally part of the S6 performance improvements /// note that S6 should not have battery power /// /// private bool ShouldEnableBackupPower() { switch (_comm) { case EthernetSlice6 _: case EthernetSlice2 _: case EthernetSlice6Air _: case EthernetSlice6AirBridge _: case EthernetTsrAir _: case WinUSBSlice6 _: case CDCUSBSlice _: return false; } return true; } /// /// previously there was no ShouldMeasureBackupPower /// and only ShouldEnableBackupPower existed, however /// TSR AIR SHOULD measure backup power and SHOULD NOT /// enable backup power ... /// /// public bool ShouldMeasureBackupPower() { switch (_comm) { case EthernetSlice6 _: case EthernetSlice6Air _: case EthernetSlice6AirBridge _: case WinUSBSlice6 _: case CDCUSBSlice _: return false; case EthernetSlice2 _: case EthernetTsrAir _: return true; } return true; } public double BackupMilliVolts { get { try { if (ShouldEnableBackupPower()) { EnableBackupPower(); // wait for a second Thread.Sleep(1500); } return DirectBackupMilliVolts; } finally { DisableBackupPower(); } } } private void EnableBackupPower() { if (!ShouldEnableBackupPower()) { return; } var setSwitch = new SetSwitchImmediate(_comm); setSwitch.Switch = (byte)Switches.BaseSwitches.BackupPower; setSwitch.SwitchText = Switches.BaseSwitches.BackupPower.ToString(); setSwitch.Setting = 1; setSwitch.SyncExecute(); } private void DisableBackupPower() { if (!ShouldEnableBackupPower()) { return; } var setSwitch = new SetSwitchImmediate(_comm); setSwitch.Switch = (byte)Switches.BaseSwitches.BackupPower; setSwitch.SwitchText = Switches.BaseSwitches.BackupPower.ToString(); setSwitch.Setting = 0; setSwitch.SyncExecute(); } } }