Ejemplo n.º 1
0
        /// <summary>
        /// Поступили данные по TCP
        /// </summary>
        /// <param name="packet">поступивший по Tcp пакет</param>
        private void devTcpOld_OnPacket(string packet)
        {
            try
            {
                Packet pack = new Packet();

                pack.Com_Packet = PacketTranslater.TranslateToUnigueFormatTcpPacket(packet, crc);
                pack.Tcp_Packet = PacketTranslater.FromUnigueToTcp(pack.Com_Packet);

                pack.Wait = false;
                if (protocol.IsToDevice(pack.Tcp_Packet))
                {
                    if (protocol.IsRead(pack.Tcp_Packet))
                    {
                        pack.Wait = true;
                    }
                }
                else
                {
                    pack.Role = Role.Slave;
                    DisplayPacket[] packs = Display.Packets;

                    if (packs != null)
                    {
                        foreach (DisplayPacket _pack in packs)
                        {
                            int device = pack.Com_Packet[1] & 0x1F;
                            if (device == _pack.Device)
                            {
                                pack.PortType = _pack.TypePort;
                                break;
                            }
                        }
                    }
                }

                devTcpOld.Place.Insert(pack);
            }
            catch (Exception ex)
            {
                journal.Write(ex.Message + "Application -> devTcpOld_OnPacket", EventLogEntryType.Error);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Отправить пакет в порт
        /// </summary>
        /// <param name="packet">Пакет для отправки в COM порт. Версия TCP протокола обмена</param>
        public void ToCOM(string packet)
        {
            try
            {
                Packet pack = new Packet();

                pack.Com_Packet = PacketTranslater.TranslateToUnigueFormatTcpPacket(packet, app.TypeCRC);
                pack.Tcp_Packet = PacketTranslater.FromUnigueToTcp(pack.Com_Packet);

                pack.Wait = false;
                if (app.IProtocol.IsToDevice(pack.Tcp_Packet))
                {
                    if (app.IProtocol.IsRead(pack.Tcp_Packet))
                    {
                        pack.Wait = true;
                    }
                }
                place.Insert(pack);
            }
            catch { }
        }