Exemplo n.º 1
0
        protected ReaderWriterLockSlim is_slim;     // синхронизатор

        /// <summary>
        /// Пересчитать CRC пакетов
        /// </summary>
        public void ReCalculateCRC(TypeCRC typeCRC)
        {
            bool blocked = false;

            try
            {
                if (s_mutex.WaitOne(100, false))
                {
                    blocked = true;
                    foreach (Packet packet in static_list)
                    {
                        switch (typeCRC)
                        {
                        case TypeCRC.Cycled:

                            packet.Com_Packet[packet.Com_Packet.Length - 2] = 0x00;
                            ushort crcCyc = Application.GetCRC(packet.Com_Packet, typeCRC);

                            packet.Com_Packet[packet.Com_Packet.Length - 1] = (byte)crcCyc;
                            packet.Com_Packet[packet.Com_Packet.Length - 2] = 0x00;

                            break;

                        case TypeCRC.CycledTwo:

                            packet.Com_Packet[packet.Com_Packet.Length - 2] = 0x00;
                            ushort crc = Application.GetCRC(packet.Com_Packet, typeCRC);

                            packet.Com_Packet[packet.Com_Packet.Length - 1] = (byte)crc;

                            crc >>= 8;
                            packet.Com_Packet[packet.Com_Packet.Length - 2] = (byte)crc;
                            break;

                        case TypeCRC.CRC16:

                            packet.Com_Packet[packet.Com_Packet.Length - 2] = 0x00;
                            ushort crc16 = Application.GetCRC(packet.Com_Packet, typeCRC);

                            packet.Com_Packet[packet.Com_Packet.Length - 1] = (byte)crc16;

                            crc16 >>= 8;
                            packet.Com_Packet[packet.Com_Packet.Length - 2] = (byte)crc16;
                            break;

                        default:

                            break;
                        }
                    }
                }
            }
            finally
            {
                if (blocked)
                {
                    s_mutex.ReleaseMutex();
                }
            }
        }
        /// <summary>
        /// Сохранить конфишурацию приложения
        /// </summary>
        /// <param name="document">Докумен в который осуществляется запись настроек приложения</param>
        /// <param name="root">Элемент в который осуществлять сохранение параметров приложения</param>
        internal void SaveApplicationConfiguration(XmlDocument document, XmlNode root)
        {
            try
            {
                if (root != null)
                {
                    XmlNode typeCRCNode         = document.CreateElement(TypeCRCName);
                    XmlNode applicationModeNode = document.CreateElement(ApplicationModeName);

                    XmlNode autorunNode = document.CreateElement(AutorunName);
                    XmlNode notifyNode  = document.CreateElement(IsNotifyName);

                    typeCRCNode.InnerText         = TypeCRC.ToString();
                    applicationModeNode.InnerText = Mode.ToString();

                    autorunNode.InnerText = Autorun.ToString();
                    notifyNode.InnerText  = isNotify.ToString();

                    root.AppendChild(typeCRCNode);
                    root.AppendChild(applicationModeNode);

                    root.AppendChild(autorunNode);
                    root.AppendChild(notifyNode);
                }
            }
            catch
            {
            }
        }
Exemplo n.º 3
0
        private TypeCRC typeCRC       = TypeCRC.Cycled; // Тип используемой контрольной суммы

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        /// <param name="type">Тип используемой контрольной суммы</param>
        public CommList(TypeCRC type)
        {
            InitializeComponent();

            typeCRC = type;
            packets = new List <Packet>();
        }
Exemplo n.º 4
0
        private TypeCRC typeCRC = TypeCRC.Cycled; // Тип используемой контрольной суммы

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        /// <param name="type">Тип используемой контрольной суммы</param>
        public CommList(TypeCRC type)
        {
            InitializeComponent();

            typeCRC = type;
            packets = new List<Packet>();
        }
Exemplo n.º 5
0
        public MyPacket(TypeCRC TypeCrc)
        {
            fl     = 0;
            ladd   = 0;
            lpak   = 0;
            cmd    = 0;
            adr    = 0;
            ldata  = 0;
            data   = null;
            status = 0;
            crc    = 0;

            typeCRC = TypeCrc;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Преобразует пакет в унифицированный формат из формата пакета пришедшего по Tcp
        /// </summary>
        /// <param name="packet">Пакет</param>
        /// <param name="typeCRC">Тип CRC</param>
        /// <returns>Пакет в унифицированном формате</returns>
        public static byte[] TranslateToUnigueFormatTcpPacket(string packet, TypeCRC typeCRC)
        {
            Regex regex = new Regex("[0-9a-fA-F]*[\\$]");
            Match match = regex.Match(packet);

            string totalString = match.Value.Substring(0, match.Value.Length - 1);

            byte[] pack = new byte[(totalString.Length / 2) + 2];
            for (int i = 1; i < pack.Length - 1; i++)
            {
                string val = totalString.Substring((i - 1) * 2, 2);
                pack[i] = (byte)int.Parse(val, System.Globalization.NumberStyles.AllowHexSpecifier);
            }

            pack[0] = 0x7e;
            switch (typeCRC)
            {
            case TypeCRC.Cycled:

                ushort crcCyc = CalculateOneByteCRC(pack);

                pack[pack.Length - 1] = (byte)crcCyc;
                pack[pack.Length - 2] = 0x00;

                break;

            case TypeCRC.CycledTwo:

                ushort crc = CalculateTwoByteCRC(pack);
                pack[pack.Length - 1] = (byte)crc;

                crc >>= 8;
                pack[pack.Length - 2] = (byte)crc;
                break;

            case TypeCRC.CRC16:

                ushort crc16 = CalculateTwoByteCRC16(pack);
                pack[pack.Length - 1] = (byte)crc16;

                crc16 >>= 8;
                pack[pack.Length - 2] = (byte)crc16;
                break;

            default:

                break;
            }
            return(pack);
        }
Exemplo n.º 7
0
        public MyPacket(TypeCRC TypeCrc)
        {
            fl = 0;
            ladd = 0;
            lpak = 0;
            cmd = 0;
            adr = 0;
            ldata = 0;
            data = null;
            status = 0;
            crc = 0;

            typeCRC = TypeCrc;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Вычислить контрольную сумму
        /// </summary>
        /// <param name="packet">Пакет для которого вычислить CRC</param>
        /// <param name="Type">Тип контрольной суммы, которую вычислить</param>
        /// <returns>CRC</returns>
        public static ushort GetCRC(byte[] packet, TypeCRC Type)
        {
            switch (Type)
            {
                case TypeCRC.Cycled:

                    return CalculateOneByteCRC(packet);

                case TypeCRC.CycledTwo:

                    return CalculateTwoByteCRC(packet);

                case TypeCRC.CRC16:

                    return CalculateTwoByteCRC16(packet);
            }

            return 0x0000;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Вычислить контрольную сумму
        /// </summary>
        /// <param name="packet">Пакет для которого вычислить CRC</param>
        /// <param name="Type">Тип контрольной суммы, которую вычислить</param>
        /// <returns>CRC</returns>
        public static ushort GetCRC(byte[] packet, TypeCRC Type)
        {
            switch (Type)
            {
            case TypeCRC.Cycled:

                return(CalculateOneByteCRC(packet));

            case TypeCRC.CycledTwo:

                return(CalculateTwoByteCRC(packet));

            case TypeCRC.CRC16:

                return(CalculateTwoByteCRC16(packet));
            }

            return(0x0000);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        protected Application()
        {
            signals = new Float[size];
            results = new Float[size];

            repository          = new Repository();
            repository.onError += new ApplicationErrorHandler(ErrorHandler);

            for (int i = 0; i < size; i++)
            {
                signals[i] = new Float();
                results[i] = new Float();
            }

            journal = Journal.CreateInstance();

            p_locker = new ReaderWriterLock();

            crc  = TypeCRC.Cycled;
            mode = ApplicationMode.Active;

            serial           = new Serial(repository);
            serial.Secondary = new SecondaryPort(repository);

            stock = new Stock(signals);

            display   = new DisplayUnit(repository);
            converter = new Converter(stock, results);

            devTcpOld = new TcpDevManager();

            t_mutex = new Mutex();
            timer   = new Timer(TimerElapsed, null, Timeout.Infinite, period);

            devTcpOld.Place = repository.InstancePlace();

            saver   = new Saver();
            service = new Service();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Преобразовать в унифицированный формат пакет пришедший из COM порта
        /// </summary>
        /// <param name="packet">Пакет</param>
        /// <param name="typeCRC">Тип CRC</param>
        /// <returns></returns>
        public static byte[] TranslateToUnigueFormatPortPacket(byte[] packet, TypeCRC typeCRC)
        {
            byte[] unigue = new byte[packet.Length];
            Array.Copy(packet, unigue, packet.Length);

            unigue[0] = 0x7e;
            switch (typeCRC)
            {
            case TypeCRC.Cycled:

                unigue[unigue.Length - 1] = (byte)CalculateOneByteCRC(unigue);
                break;

            case TypeCRC.CycledTwo:

                ushort crc = CalculateTwoByteCRC(unigue);
                unigue[unigue.Length - 1] = (byte)crc;

                crc >>= 8;
                unigue[unigue.Length - 2] = (byte)crc;
                break;

            case TypeCRC.CRC16:

                ushort crc16 = CalculateTwoByteCRC16(unigue);
                unigue[unigue.Length - 1] = (byte)crc16;

                crc16 >>= 8;
                unigue[unigue.Length - 2] = (byte)crc16;
                break;

            default:

                break;
            }
            return(unigue);
        }
Exemplo n.º 12
0
        private Mutex t_mutex = null; // синхронизатор таймера

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        protected Application()
        {
            signals = new Float[size];
            results = new Float[size];

            repository = new Repository();
            repository.onError += new ApplicationErrorHandler(ErrorHandler);

            for (int i = 0; i < size; i++)
            {
                signals[i] = new Float();
                results[i] = new Float();
            }

            journal = Journal.CreateInstance();

            p_locker = new ReaderWriterLock();

            crc = TypeCRC.Cycled;
            mode = ApplicationMode.Active;

            serial = new Serial(repository);
            serial.Secondary = new SecondaryPort(repository);

            stock = new Stock(signals);

            display = new DisplayUnit(repository);
            converter = new Converter(stock, results);

            devTcpOld = new TcpDevManager();

            t_mutex = new Mutex();
            timer = new Timer(TimerElapsed, null, Timeout.Infinite, period);

            devTcpOld.Place = repository.InstancePlace();

            saver = new Saver();
            service = new Service();
        }
Exemplo n.º 13
0
 private void radioButtonTwoByte_CheckedChanged(object sender, EventArgs e)
 {
     crc = global::DeviceManager.TypeCRC.CycledTwo;
 }
Exemplo n.º 14
0
 private void radioButtonCRC16_CheckedChanged(object sender, EventArgs e)
 {
     crc = global::DeviceManager.TypeCRC.CRC16;
 }
Exemplo n.º 15
0
 public CalculaterCRC()
     : base()
 {
     typeCRC = TypeCRC.Cycled;
 }
Exemplo n.º 16
0
 private void radioButtonTwoByte_CheckedChanged(object sender, EventArgs e)
 {
     crc = global::DeviceManager.TypeCRC.CycledTwo;
 }
Exemplo n.º 17
0
        /// <summary>
        /// Пересчитать CRC пакетов
        /// </summary>
        public void ReCalculateCRC(TypeCRC typeCRC)
        {
            bool blocked = false;
            try
            {
                if (s_mutex.WaitOne(100, false))
                {
                    blocked = true;
                    foreach (Packet packet in static_list)
                    {
                        switch (typeCRC)
                        {
                            case TypeCRC.Cycled:

                                packet.Com_Packet[packet.Com_Packet.Length - 2] = 0x00;
                                ushort crcCyc = Application.GetCRC(packet.Com_Packet, typeCRC);

                                packet.Com_Packet[packet.Com_Packet.Length - 1] = (byte)crcCyc;
                                packet.Com_Packet[packet.Com_Packet.Length - 2] = 0x00;

                                break;

                            case TypeCRC.CycledTwo:

                                packet.Com_Packet[packet.Com_Packet.Length - 2] = 0x00;
                                ushort crc = Application.GetCRC(packet.Com_Packet, typeCRC);

                                packet.Com_Packet[packet.Com_Packet.Length - 1] = (byte)crc;

                                crc >>= 8;
                                packet.Com_Packet[packet.Com_Packet.Length - 2] = (byte)crc;
                                break;

                            case TypeCRC.CRC16:

                                packet.Com_Packet[packet.Com_Packet.Length - 2] = 0x00;
                                ushort crc16 = Application.GetCRC(packet.Com_Packet, typeCRC);

                                packet.Com_Packet[packet.Com_Packet.Length - 1] = (byte)crc16;

                                crc16 >>= 8;
                                packet.Com_Packet[packet.Com_Packet.Length - 2] = (byte)crc16;
                                break;

                            default:

                                break;

                        }
                    }
                }
            }
            finally
            {
                if (blocked) s_mutex.ReleaseMutex();
            }
        }
Exemplo n.º 18
0
 private void radioButtonCRC16_CheckedChanged(object sender, EventArgs e)
 {
     crc = global::DeviceManager.TypeCRC.CRC16;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Преобразовать в унифицированный формат пакет пришедший из COM порта
        /// </summary>
        /// <param name="packet">Пакет</param>
        /// <param name="typeCRC">Тип CRC</param>
        /// <returns>Пакет в унифицированном формате</returns>
        public static byte[] TranslateToUnigueFormatPortPacket(byte[] packet, TypeCRC typeCRC)
        {
            byte[] unigue = new byte[packet.Length];
            Array.Copy(packet, unigue, packet.Length);

            unigue[0] = 0x7e;
            switch (typeCRC)
            {
                case TypeCRC.Cycled:

                    unigue[unigue.Length - 1] = (byte)CalculateOneByteCRC(unigue);
                    break;

                case TypeCRC.CycledTwo:

                    ushort crc = CalculateTwoByteCRC(unigue);
                    unigue[unigue.Length - 1] = (byte)crc;

                    crc >>= 8;
                    unigue[unigue.Length - 2] = (byte)crc;
                    break;

                case TypeCRC.CRC16:

                    ushort crc16 = CalculateTwoByteCRC16(unigue);
                    unigue[unigue.Length - 1] = (byte)crc16;

                    crc16 >>= 8;
                    unigue[unigue.Length - 2] = (byte)crc16;
                    break;

                default:

                    break;
            }
            return unigue;
        }
Exemplo n.º 20
0
 public CalculaterCRC()
     : base()
 {
     typeCRC = TypeCRC.Cycled;
 }
Exemplo n.º 21
0
        /// <summary>
        /// Преобразует пакет в унифицированный формат из формата пакета пришедшего по Tcp
        /// </summary>
        /// <param name="packet">Пакет</param>
        /// <param name="typeCRC">Тип CRC</param>
        /// <returns>Пакет в унифицированном формате</returns>
        public static byte[] TranslateToUnigueFormatTcpPacket(string packet, TypeCRC typeCRC)
        {
            Regex regex = new Regex("[0-9a-fA-F]*[\\$]");
            Match match = regex.Match(packet);

            string totalString = match.Value.Substring(0, match.Value.Length - 1);

            byte[] pack = new byte[(totalString.Length / 2) + 2];
            for (int i = 1; i < pack.Length - 1; i++)
            {
                string val = totalString.Substring((i - 1) * 2, 2);
                pack[i] = (byte)int.Parse(val, System.Globalization.NumberStyles.AllowHexSpecifier);
            }

            pack[0] = 0x7e;
            switch (typeCRC)
            {
                case TypeCRC.Cycled:

                    ushort crcCyc = CalculateOneByteCRC(pack);

                    pack[pack.Length - 1] = (byte)crcCyc;
                    pack[pack.Length - 2] = 0x00;

                    break;

                case TypeCRC.CycledTwo:

                    ushort crc = CalculateTwoByteCRC(pack);
                    pack[pack.Length - 1] = (byte)crc;

                    crc >>= 8;
                    pack[pack.Length - 2] = (byte)crc;
                    break;

                case TypeCRC.CRC16:

                    ushort crc16 = CalculateTwoByteCRC16(pack);
                    pack[pack.Length - 1] = (byte)crc16;

                    crc16 >>= 8;
                    pack[pack.Length - 2] = (byte)crc16;
                    break;

                default:

                    break;
            }
            return pack;
        }