private bool CheckSetCurrentRange(string config, int value, CurrentUnitsEnum unit) { try { const string key = "\"CURR "; const string endKey = "\""; int firstPos = config.IndexOf(key); if (firstPos < 0) { return(false); } if (unit != CurrentUnitsEnum.AUTO) { int lastPos = config.LastIndexOf(endKey); long val = (long)(value * Math.Pow(10, (double)(unit - 1) * 3)); int valuePosition = firstPos + key.Length; string rec = config.Substring(valuePosition, lastPos - valuePosition); long receiveVal = (long)(ParseReceivedData(rec) * 1E+6); return(val == receiveVal); } else { // В этом случае посмотреть, что конфигурация правильно записалась нельзя - в зависимости от значения на входе // предел измерений меняется return(true); } } catch { return(false); } }
public Ammetr(string ip, CurrentTypeEnum currentType, CurrentUnitsEnum units, int range) { this.ip = ip; CurrentType = currentType; Units = units; multipler = Units == CurrentUnitsEnum.A ? 1 : 1000; Range = range; }
public void SetCurrentRange(CurrentTypeEnum currentType, int value, CurrentUnitsEnum unit) { string send = "CONF:CURR:" + currentType + " "; send += (unit == CurrentUnitsEnum.AUTO) ? unit.ToString() : (value.ToString() + unit.ToString()); transport.Send(send); for (int i = 0; i < 5; i++) { Pause(1000); string config = WriteRead("CONF?"); if (CheckSetCurrentRange(config, value, unit)) { return; } } throw new SDM_ErrException(Properties.Resources.SetCurrentMeasureModeError); }