private void ParseCmd(Pack pack) { }
private void ParseData(Pack pack) { var arr = new int[4]; var barr = pack.Data.ToArray(); // arr = pack.Data.ToArray(); for (int i = 0, j = 0; i < 4; i++, j += 2) { arr[i] = BitConverter.ToInt16(barr, j); arr[i] >>= 1; /* if (ExchangeConfig.CorrectRxMistakes) { if (arr[i] < 0x0F) arr[i] = arr_prev[i]; else arr_prev[i] = arr[i]; }*/ var vl = (arr[i] * 5.09 / 1024); if(ExchangeConfig.FilterType==InputFilterType.AlphaBeta) vl = ExchangeConfig.AlphaBetaKoefs[i] * vl + (1 - ExchangeConfig.AlphaBetaKoefs[i]) * vl_prev[i]; vl_prev[i] = vl; if (_zeroCorrection) { if (Math.Abs(vl - zeroAdcVals[i]) < 0.06) vl = 0.0; else if (vl > zeroAdcVals[i]) vl -= zeroAdcVals[i]; } if(ExchangeConfig.CorrectRxMistakes) vl = Math.Round(vl, 2); CurrAdcVals[i] = vl; WeightDoubles[i] = CurrAdcVals[i]*WeightKoefs[i]; } }
protected override void Parse(Pack pack) { switch (_mode) { case StabilityParseMode.ParseData: ParseData(pack); break; case StabilityParseMode.ParseCmd: ParseCmd(pack); break; } if(ParseDone != null) ParseDone.Invoke(this,null);//BeginInvoke(this, null, null, null); }
/// <summary> /// Выполняет отправку данных по интрефейсу RS232 /// </summary> public void SendData(Pack p) { SendData(p.Data.ToArray()); }
private void RxThreadHandler(object ev) { var stopEvent = (ManualResetEvent)ev; while (stopEvent.WaitOne()) { if (_rxBuf.Count > 0) //Если в буфере есть данные { Pack pack; if (UseSLIP) pack = SlipParser(); // то прогоняем их через SLIP протокол else { pack = new Pack(_rxBuf.GetRange(0,_threshold)); _rxBuf.RemoveRange(0,_threshold); } if (pack != null) { RxData.Enqueue(new Pack(pack.Data)); //Суем пакет в выходную очередь if (RxEvent != null) RxEvent.Invoke(this, null); //Дергаем Event } } Thread.Sleep(20); } }
protected virtual void Parse(Pack p) { throw new NotImplementedException(); }