protected void t_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (!working)
     {
         return;
     }
     for (int i = 0; i < 2; i++)
     {
         string s;
         SystemListenerEventArgs.EventType evT = SystemListenerEventArgs.EventType.RESULT;
         int k = r.Next(10);
         if (k < 3)
         {
             evT = SystemListenerEventArgs.EventType.FALL;
             s   = "FALL";
         }
         else if (k < 4)
         {
             evT = SystemListenerEventArgs.EventType.FALSTART;
             s   = "FALSTART";
         }
         else
         {
             s = "0:" + (r.Next(49) + 10).ToString("00") + "." + r.Next(99).ToString("00");
         }
         SystemListenerEventArgs args = new SystemListenerEventArgs(
             evT, (i + 1), s);
         CommitEvent(this, args);
     }
     if (!t.Enabled)
     {
         t.Start();
     }
 }
        protected void processDataOld()
        {
            if (unprocessed.Count < 8)
            {
                ShowMessage("Неправильный/неполный пакет", true);
                unprocessed.Clear();
                return;
            }
            byte[] data = new byte[6];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = unprocessed[i + 1];
            }
            int[]  res = getFromByteArray(data);
            string s1  = res[0].ToString("0") + ":" + res[1].ToString("00") + "." + res[2].ToString("00");
            string s2  = res[3].ToString("0") + ":" + res[4].ToString("00") + "." + res[5].ToString("00");

            unprocessed.RemoveRange(0, 8);
            SystemListenerEventArgs sa1 = new SystemListenerEventArgs(
                SystemListenerEventArgs.EventType.RESULT, 1, s1);
            SystemListenerEventArgs sa2 = new SystemListenerEventArgs(
                SystemListenerEventArgs.EventType.RESULT, 2, s2);

            CommitEvent(this, sa1);
            CommitEvent(this, sa2);
        }
 protected void CommitEvent(object sender, SystemListenerEventArgs e)
 {
     if (SystemListenerEvent != null)
     {
         SystemListenerEvent(sender, e);
     }
 }
        protected void processData()
        {
            mBuffer.WaitOne();
            try
            {
                if (useOld)
                {
                    processDataOld();
                    return;
                }
                byte        length = 0, type = 0xff;
                byte[]      crc = new byte[TAIL_LENGTH], data = null;
                List <byte> d   = new List <byte>();


                for (int i = 0; i < crc.Length; i++)
                {
                    crc[i] = 0x00;
                }


                ReadToStart(unprocessed);
                if (unprocessed.Count < SERV_LENGTH)
                {
                    return;
                }
                for (int i = 0; i < SERV_LENGTH; i++)
                {
                    d.Add(unprocessed[i]);
                }
                length = d[d.Count - 1];
                if (unprocessed.Count < (length + SERV_LENGTH + TAIL_LENGTH))
                {
                    return;
                }
                type = d[d.Count - 2];
                if (length > 0)
                {
                    data = new byte[length];
                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i] = unprocessed[i + SERV_LENGTH];
                        d.Add(unprocessed[i + SERV_LENGTH]);
                    }
                }
                for (int i = 0; i < crc.Length; i++)
                {
                    crc[i] = unprocessed[i + SERV_LENGTH + data.Length];
                }

                for (int i = 0; i < 2; i++)
                {
                    unprocessed.RemoveAt(0);
                }

                int nCrc = 0x00;
                for (int i = 0; i < crc.Length; i++)
                {
                    nCrc += crc[i] << (8 * (crc.Length - 1 - i));
                }
                //int nCrct = (crc[0] << 8) + crc[1];
                int rC = 0;
                for (int i = 0; i < d.Count; i++)
                {
                    rC += d[i];
                }
                //if (nCrc != rC) //проверка на контрольную сумму
                //{
                //    ShowMessage("Неверная контрольная сумма");
                //    return;
                //}
                int[] res;
                if (data != null && data.Length > 0)
                {
                    res = getFromByteArray(data);
                }
                else
                {
                    res = null;
                }
                if (res != null && (type == 0x00 || type == 0x01) && res.Length > 2)
                {
                    string s = res[0].ToString("0") + ":" + res[1].ToString("00") + "." + res[2].ToString("00");
                    SystemListenerEventArgs earg = new SystemListenerEventArgs(SystemListenerEventArgs.EventType.RESULT, 1, s);
                    CommitEvent(this, earg);
                    if (res.Length > 5)
                    {
                        s = res[3].ToString("0") + ":" + res[4].ToString("00") + "." + res[5].ToString("00");
                        SystemListenerEventArgs earg2 = new SystemListenerEventArgs(SystemListenerEventArgs.EventType.RESULT, 2, s);
                        CommitEvent(this, earg2);
                    }
                }
                else if (res != null && res.Length == 2)
                {
                    CommitEvent(this, new SystemListenerEventArgs(res[0], res[1]));
                }
                else
                {
                    ShowMessage("Неверный пакет");
                }
            }
            catch (Exception ex)
            {
                Thread thrLM = new Thread(new ParameterizedThreadStart(delegate(object arg)
                {
                    string toShow;
                    if (arg == null || !(arg is string))
                    {
                        toShow = "";
                    }
                    else
                    {
                        toShow = (string)arg;
                    }
                    ShowMessage("Ошибка обработки данных с системы:\r\n" +
                                toShow, true);
                }));
                thrLM.Start(ex.Message);
            }
            finally { mBuffer.ReleaseMutex(); }
        }