Esempio n. 1
0
 /// <summary>
 /// Получает пакет для обработки
 /// </summary>
 /// <param name="packet">Пакет который необходимо обработать</param>
 public void Packet(Packet packet)
 {
     if (binder != null)
     {
         binder.Packet(packet.packet);
     }
 }
Esempio n. 2
0
        public void SetPacket(Packet packet)
        {
            string n = packet.packet.Substring(2, 2);

            try
            {

                int index = int.Parse(n, System.Globalization.NumberStyles.AllowHexSpecifier) - 1;
                byte b = (byte)int.Parse(n[0].ToString(), System.Globalization.NumberStyles.AllowHexSpecifier);

                int lb = b & 0x8;
                if (lb == 0) return;

                index = index - 128;
                if (index > 31) return;

                lock (mstr)
                {
                    mstr[index].dt = packet.dateReceived;
                    mstr[index].mLabel.BackColor = Color.LimeGreen;
                }

            }
            catch (Exception)
            {
            }
        }
Esempio n. 3
0
 public void Process(Packet packet)
 {
 }
Esempio n. 4
0
        /// <summary>
        /// Формирование строки синхронизации с последующей отсылкой в сеть устройств
        /// Может сопровождаться отсылкой дополнительной строки рестарта
        /// </summary>
        /// <param name="param">Номер команды</param>
        private void SendString(int param)
        {
            int Addr = par.getAdrBO(param);
            string cmdBody = par.getNameCMD(param);
            int Lngth = (cmdBody.Length / 2) + 4;
            string packetStr = "";
            {
                packetStr = string.Format("@JOB#000#{0:X2}{1:X2}{2:S}00$", Addr, Lngth, cmdBody);
            }

            Packet pak = new Packet(packetStr, DateTime.Now, null);
            app.SendPacket(pak);
        }
Esempio n. 5
0
        /// <summary>
        /// Формирование строки синхронизации с последующей отсылкой в сеть устройств
        /// Может сопровождаться отсылкой дополнительной строки рестарта
        /// </summary>
        /// <param name="param">Адрес Блока Отображения</param>
        private void SendString(int param)
        {
            DateTime data = DateTime.Now;

            string packetStr = "";

            if (par.OldFormatCMD)
            {
                packetStr = string.Format(
                    "@JOB#000#{0:X2}1001200AB50000{1:D2}{2:D2}{3:D2}00{4:D2}{5:D2}{6:D2}$",
                    param,
                    data.Second, data.Minute, data.Hour,
                    data.Day, data.Month, data.Year - 2000);
            }
            else
            {
                packetStr = string.Format(
                    "@JOB#000#{0:X2}1101200AB50000{1:D2}{2:D2}{3:D2}00{4:D2}{5:D2}{6:D2}00$",
                    param,
                    data.Second, data.Minute, data.Hour,
                    data.Day, data.Month, data.Year - 2000);
            }

            Packet pak = new Packet(packetStr, DateTime.Now, null);
            app.SendPacket(pak);

            if (par.ResetBOAfterSet) SendResetString(param);
        }
Esempio n. 6
0
 /// <summary>
 /// Получает пакет для обработки
 /// </summary>
 /// <param name="packet">Пакет</param>
 public void Process(Packet packet)
 {
     if (isWorking)
     {
         frm.Packet(packet);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Работаем
        /// </summary>
        protected override void Start()
        {
            string sending = string.Empty;
            if (binder.OperationType == OperationType.Read)
            {
                sending = "@JOB#000#3F0722101000$";
            }
            else
            {
                string d_byte = "FF";
                string _data = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8:X2}{9:X2}{10}{11}{12}{13:X2}{14}{15}",
                    d_byte, d_byte, d_byte, d_byte, d_byte, d_byte, d_byte, d_byte, binder.DeviceNumber,
                    binder.AnswerDeviceNumber, d_byte, d_byte, d_byte, binder.AnswerTimeout, d_byte, d_byte);

                sending = binder.Proto.CreateCommand(Device.D3F, Command.ReadWrite, PageNumber.P1, 0x10, 0x10, _data);

                if (binder.Options.Algorithm)
                {
                    // --- разрешить запись в устройство ---

                    Packet pa = new Packet("@JOB#000#3F09012002A00100$", DateTime.Now, null);
                    binder.App.SendPacket(pa);
                }
            }

            binder.onPacket += new BinderPacketHandler(binder_onPacket);
            binder.LastOperation = ResultOperation.Default;

            for (int check = 0; check <= binder.Options.CountDataCheck; check++)
            {
                switch (ChekerToReadEprom(sending))
                {
                    case ResultOperation.Succes:

                        datas.Add(binder.Proto.GetData(data));
                        data = CheckDatas(datas);

                        if (data != string.Empty)
                        {
                            datas.Clear();

                            binder.LastOperation = ResultOperation.Succes;
                            binder.ResultString = data;

                            if (binder.OperationType == OperationType.Write)
                            {
                                if (binder.Options.Algorithm)
                                {
                                    // ---- рестарт устройуства ----

                                    Packet pa = new Packet("@JOB#000#3F0705100100$", DateTime.Now, null);
                                    binder.App.SendPacket(pa);
                                }
                            }
                            return;
                        }
                        break;

                    case ResultOperation.Timeout:

                        return;

                    case ResultOperation.MorePopit:

                        return;
                }
            }
        }
Esempio n. 8
0
 public void Process(Packet packet)
 {
     lock (share)
     {
         if (!started)
         {
             timer.Change(0, 50);
             started = true;
         }
         share.Add(packet);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        private bool CheckOneToRWEprom(Packet packet)
        {
            bool result = false;
            foreach (string pack in working)
            {
                string total = string.Empty;

                if (template == string.Empty)
                {
                    total = pack.Substring(4, 8);
                }
                else
                    total = template;

                if (total == answer)
                {
                    data = pack;
                    return true;
                }
            }
            return result;
        }
Esempio n. 10
0
        private ResultOperation ChekerToWriteEprom(Packet packet)
        {
            try
            {
                for (int count = 0; count < workHandle.countDo; count++)
                {
                    app.SendPacket(packet);
                    long baseTime = DateTime.Now.Ticks;
                m:
                    if (mevent.WaitOne(workHandle.commonTimeout))
                    {
                        lock (share)
                        {
                            if (share.Count > 0)
                            {
                                working.AddRange(share);
                                share.Clear();
                            }
                        }

                        if (CheckOneToWriteEprom(packet))
                        {
                            return ResultOperation.Succes;
                        }
                        else
                        {
                            long time = (long)((DateTime.Now.Ticks - baseTime) * 1E-4);
                            if (time > workHandle.commonTimeout)
                            {
                                return ResultOperation.Timeout;
                            }
                            else
                                goto m;
                        }
                    }
                }
                return ResultOperation.MorePopit;
            }
            finally
            {
                working.Clear();
            }
        }
Esempio n. 11
0
        public void Process(Packet packet)
        {
            string mils = packet.dateReceived.Millisecond.ToString();
            if (mils.Length < 2) mils = "00" + mils;
            else if (mils.Length < 3) mils = "0" + mils;
            string date = packet.dateReceived.ToLongTimeString() + "." + mils + " > ";

            builder.Append(date + packet.packet);

            string total = builder.ToString();
            builder.Remove(0, builder.Length);

            lock (forms)
            {
                foreach (var f in forms)
                {
                    f.InsertPacket(total);
                }
            }
        }
Esempio n. 12
0
 private bool CheckOneToWriteEprom(Packet packet)
 {
     bool result = false;
     foreach (Packet pack in working)
     {
         if (isAnswerOnWriteEprom(packet.packet, pack.packet) || rInfo.UseBroadcast)
         {
             data = pack.packet;
             return true;
         }
     }
     return result;
 }
Esempio n. 13
0
 private bool CheckOneToWrite(Packet packet)
 {
     bool result = false;
     foreach (Packet pack in working)
     {
         if (isAnswerOnWrite(packet.packet, pack.packet) || workHandle.useBroadcast)
         {
             Invoke(incer, 1);
             (packet.Token as DataGridViewCell).Value = app.GetProtocol(ProtocolVersion.x100).GetData(pack.packet);
             return true;
         }
     }
     return result;
 }
Esempio n. 14
0
 public void Packet(Packet packet)
 {
     lock (workHandle)
     {
         if (workHandle.need == NeedTolk.Yes)
         {
             if (app.GetProtocol(ProtocolVersion.x100).IsFromDevice(packet.packet))
             {
                 if (workHandle.useBroadcast || app.GetProtocol(ProtocolVersion.x100).GetNumberDevice(packet.packet) ==
                     workHandle.deviceNumber)
                 {
                     lock (share)
                     {
                         share.Add(packet);
                     }
                     lock (mevent) mevent.Set();
                 }
             }
         }
     }
 }
Esempio n. 15
0
 // ---------- обработка поступившего пакета --------
 /// <summary>
 /// Обработка поступившего пакета
 /// </summary>
 /// <param name="packet">Пакет</param>
 public void Process(Packet packet)
 {
     lock (share)
     {
         if (plugins != null)
         {
             if (plugins.Count > 0)
             {
                 if (!started)
                 {
                     started = true;
                     timer.Change(0, SpeedSurvey);
                 }
                 share.Add(packet);
             }
         }
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Читаем конфигурацию
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        private ResultOperation ChekerToRWEprom(Packet packet)
        {
            try
            {
                for (int count = 0; count < options.AttemptsToReadWriteEntries; count++)
                {
                    app.SendPacket(packet);
                    long baseTime = DateTime.Now.Ticks;
                m:
                    if (mevent.WaitOne(options.TimeoutForResponseFromDevice))
                    {
                        lock (sharing)
                        {
                            if (sharing.Count > 0)
                            {
                                working.AddRange(sharing);
                                sharing.Clear();
                            }
                        }

                        if (CheckOneToRWEprom(packet))
                        {
                            return ResultOperation.Succes;
                        }
                        else
                        {
                            long time = (long)((DateTime.Now.Ticks - baseTime) * 1E-4);
                            if (time > options.TimeoutForResponseFromDevice)
                            {
                                return ResultOperation.Timeout;
                            }
                            else
                                goto m;
                        }
                    }
                }
                return ResultOperation.MorePopit;
            }
            finally
            {
                working.Clear();
            }
        }
Esempio n. 17
0
 // ------- отправка пакета от плагина ------
 public void SendPacket(Packet packet)
 {
     form.SendPacket(packet);
 }
Esempio n. 18
0
        // ------ реализация интерфейса -------
        public void SendPacket(Packet packet)
        {
            lock (share)
            {
                if (client == null) return;
                if (!client.Connected) return;

                if (!started)
                {
                    started = true;
                    timer.Change(0, 50);
                }
                share.Add(packet);
            }
        }
Esempio n. 19
0
 public void Process(Packet packet)
 {
     lock (sync)
     {
         if (started)
         {
             if (proto.IsFromDevice(packet.packet) &&
                 proto.GetNumberDevice(packet.packet) == mForm.Device)
             {
                 mForm.Packet(packet.packet);
             }
         }
     }
 }
Esempio n. 20
0
 void paker_OnPacket(string packet)
 {
     Packet item = new Packet(packet, DateTime.Now, null);
     m.Process(item);
 }
Esempio n. 21
0
        /// <summary>
        /// Читаем конфигурацию
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        private ResultOperation ChekerToReadEprom(string packet)
        {
            Packet pack = new Packet(packet, DateTime.Now, null);
            for (int count = 0; count < binder.Options.CountAttemptIo; count++)
            {
                binder.App.SendPacket(pack);
                flag.Flag = true;

                if (mevent.WaitOne(binder.Options.DeviceAnswerTimeout))
                {
                    return ResultOperation.Succes;
                }

                Thread.Sleep(binder.Options.TimeoutBeetwenQuestions);
            }
            return ResultOperation.MorePopit;
        }
Esempio n. 22
0
 // ------ пришел пакет -----------
 public void Process(Packet packet)
 {
     lock (frm)
     {
         if (frm != null)
         {
             frm.SetPacket(packet);
         }
     }
 }
Esempio n. 23
0
 public void Process(Packet packet)
 {
     lock (sync)
     {
         if (protocol.IsFromDevice(packet.packet))
         {
             mForm.Packet(packet.packet);
         }
     }
 }
Esempio n. 24
0
        /// <summary>
        /// Формирование строки рестарт с последующей отсылкой в сеть устройств
        /// </summary>
        /// <param name="param">Адрес Блока Отображения</param>
        private void SendResetString(int param)
        {
            string packetStr = string.Format("@JOB#000#{0:X2}0705100100$", param);

            Packet pak = new Packet(packetStr, DateTime.Now, null);
            app.SendPacket(pak);
        }