コード例 #1
0
        /// <summary>
        /// Send the speed and direction of the given loc towards the railway.
        /// </summary>
        protected override void OnSendLocSpeedAndDirection(ILocState loc)
        {
            Log.Trace("OnSendLocSpeedAndDirection: {0}", loc);
            var direction = (loc.Direction.Requested == LocDirection.Forward);
            var packet    = Packets.CreateSpeedAndDirection(loc.Address.ValueAsInt, (byte)loc.SpeedInSteps.Requested, direction, loc.SpeedSteps);
            var data      = PacketTranslater.Translate(packet);

            sender.SendSpeedAndDirection(loc.Address.ValueAsInt, data);
            loc.Direction.Actual = loc.Direction.Requested;
            loc.Speed.Actual     = loc.Speed.Requested;
        }
コード例 #2
0
 /// <summary>
 /// Поступил пакет от устройства
 /// </summary>
 /// <param name="sender">Источник события</param>
 /// <param name="args">Параметры события</param>
 void serial_OnPacket(object sender, SerialEventArgs args)
 {
     try
     {
         string packet = PacketTranslater.FromUnigueToTcp(args.Packet.Com_Packet);
         devTcpOld.Send(packet);
     }
     catch (Exception ex)
     {
         journal.Write(ex.Message, EventLogEntryType.Error);
     }
 }
コード例 #3
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);
            }
        }
コード例 #4
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 { }
        }
コード例 #5
0
        /// <summary>
        /// Установить CRC для пакета
        /// </summary>
        /// <param name="com_packet">Пакет</param>
        private void SetCRC(byte[] com_packet)
        {
            ushort crc = 0x0000;

            switch (app.TypeCRC)
            {
            case TypeCRC.Cycled:

                crc = PacketTranslater.CalculateOneByteCRC(com_packet);
                break;

            case TypeCRC.CycledTwo:

                crc = PacketTranslater.CalculateTwoByteCRC(com_packet);
                break;

            case TypeCRC.CRC16:

                crc = PacketTranslater.CalculateTwoByteCRC16(com_packet);
                break;
            }

            byte[] t_crc = BitConverter.GetBytes(crc);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(t_crc);
            }

            if (app.TypeCRC == TypeCRC.Cycled)
            {
                com_packet[com_packet.Length - 2] = 0x00;
            }
            else
            {
                com_packet[com_packet.Length - 2] = t_crc[0];
            }

            com_packet[com_packet.Length - 1] = t_crc[1];
        }
コード例 #6
0
        /// <summary>
        /// MEngine 객체를 초기화합니다.
        /// </summary>
        /// <param name="logicEntry"> 로직 처리를 담당하는 객체입니다. </param>
        /// <param name="translater"> 패킷을 구별해주는 객체입니다. </param>
        /// <param name="dispatcher"> 로직을 처리해주는 객체입니다. [기본값 : MLogicDispatcher] </param>
        /// <returns></returns>
        public bool Intialize(LogicEntry logicEntry, PacketTranslater translater, LogicDispatcher dispatcher = null)
        {
            if (logicEntry == null)
            {
                throw new NullReferenceException("MEngine Initialize Failed - logicEntry is null.");
            }

            if (dispatcher == null)
            {
                dispatcher = new MLogicDispatcher();
            }

            if (translater == null)
            {
                throw new NullReferenceException("MEngine Initialize Failed - distinctioner is null.");
            }

            if (NetworkEngine == null)
            {
                CreateEngine(true);
            }

            Dispatcher          = dispatcher;
            packetDistinctioner = translater;

            if (Dispatcher.CreateLogicSystem(logicEntry) == false)
            {
                throw new Exceptions.InitializeException("MEngine Initialize Failed - Dispatcher.CreateLogicSystem() Failed");
            }

            if (NetworkEngine.Initialize() == false)
            {
                throw new Exceptions.InitializeException("MEngine Initialize Failed - NetworkEngine.Initialize() Failed");
            }

            return(true);
        }
コード例 #7
0
 public void SetPacketDistinctioner(PacketTranslater distinctioner)
 {
     MEngine.Instance.packetDistinctioner = distinctioner;
 }