예제 #1
0
        protected void OnScalesEventStatusChanged(object sender, NxDeviceState state)
        {
            DeviceState = state;

            /*
             * if ((state & NxDataFrame.NxDeviceState.DS_STEADY) == NxDataFrame.NxDeviceState.DS_STEADY)
             * {
             *  if (State == ChState.CH_MEASURING && MeasureValue > TriggerEmpty)
             *  {
             *      if (tokenSource == null)
             *      {
             *          tokenSource = new CancellationTokenSource();
             *          Task.Run(async delegate
             *          {
             *              bool exposured = true;
             *              exposuredWeight = MeasureValue;
             *
             *              DateTime expStart = DateTime.Now;
             *              State = ChState.CH_EXPOSURING;
             *              Program.Log.Info(string.Format("Канал {0} вес {1}. Ожидание подтверждения. Интервал [{2}]", Name, MeasureValue, Exposure.ToString(@"ss\.fff")));
             *              try
             *              {
             *                  await Task.Delay(Exposure, tokenSource.Token);
             *              }
             *              catch
             *              {
             *                  exposured = false;
             *                  if (State == ChState.CH_EXPOSURING)
             *                      State = ChState.CH_MEASURING;
             *              }
             *
             *              if (exposured && State == ChState.CH_EXPOSURING)
             *                  ExposureData(exposuredWeight, DateTime.Now);
             *              else
             *                  Program.Log.Info(string.Format("Канал {0} вес {1}. Подтверждение НЕ получено. Интервал [{2}]. Выдержан [{3}]", Name, exposuredWeight, Exposure.ToString(@"ss\.fff"), (DateTime.Now - expStart).ToString(@"ss\.fff")));
             *
             *              exposuredWeight = 0;
             *          });
             *      }
             *
             *      return;
             *  }
             *
             *  if (State == ChState.CH_WAITING_ZERO && MeasureValue <= TriggerEmpty)
             *  {
             *      State = ChState.CH_WAITING;
             *  }
             * }
             * else
             * {
             *  if (tokenSource != null)
             *  {
             *      tokenSource.Cancel();
             *      tokenSource.Dispose();
             *      tokenSource = null;
             *      exposuredWeight = 0;
             *  }
             * }*/
        }
예제 #2
0
        protected void OnDataReceived(Double newWeight, NxDeviceState newStatus)
        {
            hLastPacketTimestamp = DateTime.Now;
            bool bWeightChanged = hWeight != newWeight;

            hWeight = newWeight;

            if (OnScalesEventDataReceived != null)
            {
                try
                {
                    OnScalesEventDataReceived(this, Weight);
                }
                catch
                {
                }
            }

            if (bWeightChanged)
            {
                if (OnScalesEventWeightChanged != null)
                {
                    try
                    {
                        OnScalesEventWeightChanged(this, Weight);
                    }
                    catch
                    {
                    }
                }
            }

            if (hTerminalStatus != newStatus)
            {
                hTerminalStatus = newStatus;
                if (OnScalesEventStatusChanged != null)
                {
                    try
                    {
                        OnScalesEventStatusChanged(this, newStatus);
                    }
                    catch
                    {
                    }
                }
            }
        }