예제 #1
0
        void NewDataRecieved(byte[] data)
        {
            hLastPacketTimestamp = DateTime.Now;
            hFreeze = TimeSpan.MinValue;

            if (ConnectionStatus == ScalesComponent.ConnectionStatus.CS_OFFLINE)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Warming up, Terminal STATE was {0}", TerminalStatus));
            }

            ConnectionStatus = ScalesComponent.ConnectionStatus.CS_ONLINE;

            bool decoded = false;

            try
            {
                decoded = nxFrame.Decode(data);
            }
            catch (Exception ex)
            {
                LogManager.GetCurrentClassLogger().Debug("Ошибка декодирования данных", ex);
                System.Diagnostics.Trace.TraceError("Ошибка декодирования данных {0}", ex.Message);
                decoded = false;
            }

            if (decoded)
            {
                bool bWeightChanged = hWeight != nxFrame.Weight;
                hWeight = nxFrame.Weight;

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

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

                if (hTerminalStatus != nxFrame.State)
                {
                    hTerminalStatus = nxFrame.State;

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

            if (OnScalesEventRawDataReceived != null)
            {
                try
                {
                    String rawData = Encoding.ASCII.GetString(data);
                    OnScalesEventRawDataReceived(this, rawData);
                }
                catch
                {
                }
            }
        }
예제 #2
0
        void portManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
        {
            hLastPacketTimestamp = DateTime.Now;

            ConnectionStatus = ScalesComponent.ConnectionStatus.CS_ONLINE;

            bool decoded = false;

            try
            {
                decoded = nxFrame.Decode(e.Data);
            }
            catch
            {
                decoded = false;
            }

            if (decoded)
            {
                bool bWeightChanged = hWeight != nxFrame.Weight;
                hWeight = nxFrame.Weight;

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

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

                if (hTerminalStatus != nxFrame.State)
                {
                    hTerminalStatus = nxFrame.State;

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

            if (OnScalesEventRawDataReceived != null)
            {
                try
                {
                    String rawData = Encoding.ASCII.GetString(e.Data);
                    OnScalesEventRawDataReceived(this, rawData);
                }
                catch
                {
                }
            }
        }