Ejemplo n.º 1
0
        public async Task <ModuleInformation> ReadModuleInformation(IDeviceSpecification deviceSpecification, byte devicenumber, int i)
        {
            ModuleInformation moduleInformation = new ModuleInformation();

            try
            {
                ushort[] answer = await ConnectionManager.Connection.ModbusMasterController.ReadHoldingRegistersAsync(devicenumber, (ushort)(deviceSpecification.StartAddInfo + MODULE_INFO_SIZE * i),
                                                                                                                      MODULE_INFO_SIZE, "Чтение информации о модуле");

                byte[] answerBytes = Common.TOBYTES(answer, false);
                char[] str         = Common.GetChars(answerBytes).Select(o => o == '\0' ? ' ' : o).ToArray();
                string str1        = new string(str, 0, 16);
                string str2        = new string(str, 16, 16);
                string str3        = new string(str, 32, 16);
                var    addingInfo  = answerBytes.Skip(16).Select(o => (byte)o).Take(16).ToArray();
                moduleInformation = new ModuleInformation(str1, addingInfo, str3, (byte)i);
                moduleInformation.ModulePositionOnSpecification = deviceSpecification.ModuleTypes[i];
                moduleInformation.ControlType = deviceSpecification.ControlType;
            }
            catch (Exception e)
            {
                throw;
            }
            return(moduleInformation);
        }
Ejemplo n.º 2
0
 public static async Task ModuleToWork(ModuleInformation information)
 {
     if (information.State == ModuleStates.WORK)
     {
         return;
     }
     ushort[] data = new ushort[] { 0x35AA };
     try
     {
         await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsyncFunction12(DevicesManager.DeviceNumber, (ushort)(information.FlashSize + 1), information.ModulePosition,
                                                                                                          data, "запись сигнатуры");
     }
     catch (Exception e)
     {
         throw new Exception("Ошибка записи сигнатуры");
     }
 }
Ejemplo n.º 3
0
        public static async Task ModuleMLKToWork(ModuleInformation information)
        {
            if (information.State == ModuleStates.WORK)
            {
                return;
            }
            string name = "Перевод модуля в рабочий режим";

            try
            {
                await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsync(DevicesManager.DeviceNumber,
                                                                                                       (ushort)(information.FlashSize + 1),
                                                                                                       new ushort[] { 0x8002 }, name);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 4
0
        public static void ModuleMLKToloader(ModuleInformation information)
        {
            if (information.State == ModuleStates.LOADER)
            {
                return;
            }
            string name = "Перевод модуля в режим загрузчика";

            try
            {
                byte[] buffer = new byte[] { 0x01, 0xff, 0x47, 0x4f, 0x20, 0x54, 0x4f, 0x20, 0x42, 0x4f, 0x4f, 0x54, 0x4c, 0x4f, 0x41, 0x44, 0x45, 0x52, 0x42, 0xef };

                ConnectionManager.Connection.Serialport.Write(buffer, 0, buffer.Length);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 5
0
        public static async Task ModuleToloader(ModuleInformation information)
        {
            if (information.State == ModuleStates.LOADER)
            {
                return;
            }
            string name           = "Перевод модуля в режим загрузчика";
            var    res            = Common.TOWORD(0, (byte)((Convert.ToByte(information.ModuleType) << 4) | information.ModulePosition));
            var    writePageArray = new ushort[] { res, };

            try
            {
                await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsync(DevicesManager.DeviceNumber, 0x3A0,
                                                                                                       writePageArray, name);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 6
0
        public static async Task ClearModule(ModuleInformation information)
        {
            ushort controlWord = 0;

            controlWord = Common.SetBits(controlWord, (ushort)information.ModuleType, 4, 5, 6, 7);
            controlWord = Common.SetBits(controlWord, information.ModulePosition, 0, 1, 2, 3);
            try
            {
                if (information.ControlType == ControlType.MRTYPE)
                {
                    await ModuleToloader(information);

                    await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsyncFunction12(DevicesManager.DeviceNumber, 0, information.ModulePosition,
                                                                                                                     new ushort[8] {
                        0, 0, 0, 0, 0, 0, 0, 0
                    }, "Очитска модуля 2-ый этап");

                    await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsyncFunction12(DevicesManager.DeviceNumber, (ushort)(information.FlashSize + 1), information.ModulePosition,
                                                                                                                     new ushort[1] {
                        0x8001
                    }, "Очитска модуля 2-ый этап");
                }
                else
                {
                    ModuleMLKToloader(information);
                    await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsync(DevicesManager.DeviceNumber, 0,
                                                                                                           new ushort[8] {
                        0, 0, 0, 0, 0, 0, 0, 0
                    }, "Очитска модуля 2-ый этап");

                    await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsync(DevicesManager.DeviceNumber, (ushort)(information.FlashSize + 1),
                                                                                                           new ushort[1] {
                        0x8001
                    }, "Очитска модуля 2-ый этап");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 7
0
        public static async Task WriteDevInfo(ModuleInformation information, string devinfo)
        {
            ushort controlWord = 0;

            controlWord = Common.SetBits(controlWord, (ushort)information.ModuleType, 4, 5, 6, 7);
            controlWord = Common.SetBits(controlWord, information.ModulePosition, 0, 1, 2, 3);
            var inBytes = Common.TOWORDS(devinfo.Select(o => (byte)o).ToArray(), false);

            try
            {
                if (information.ControlType == ControlType.MRTYPE)
                {
                    await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsyncFunction12(DevicesManager.DeviceNumber, 0, information.ModulePosition,
                                                                                                                     inBytes, "Очитска модуля 2-ый этап");

                    await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsyncFunction12(DevicesManager.DeviceNumber, (ushort)(information.FlashSize + 1), information.ModulePosition,
                                                                                                                     new ushort[1] {
                        0x8001
                    }, "Очитска модуля 2-ый этап");
                }
                else
                {
                    await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsync(DevicesManager.DeviceNumber, 0,
                                                                                                           inBytes, "Очитска модуля 2-ый этап");

                    await ConnectionManager.Connection.ModbusMasterController?.WriteMultipleRegistersAsync(DevicesManager.DeviceNumber, (ushort)(information.FlashSize + 1),
                                                                                                           new ushort[1] {
                        0x8001
                    }, "Очитска модуля 2-ый этап");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 8
0
        public ModuleWritterController(ModuleInformation moduleInformation, TypeOfMemory memoryType, byte devicenumber, byte[] data, ushort startpage = 0, ushort count = 0)
        {
            _moduleInformation = moduleInformation;
            _typeOfMemory      = memoryType;
            _deviceNumber      = devicenumber;
            Data = data;
            if (moduleInformation.ControlType == ControlType.MRTYPE)
            {
                _isMR = true;
            }
            else
            {
                _isMR = false;
            }
            switch (memoryType)
            {
            case TypeOfMemory.EEPROM:
            {
                if ((_moduleInformation.Processor == ProcessorType.AT_MEGA_128) || (_moduleInformation.Processor == ProcessorType.AT_MEGA_2561))
                {
                    this._pageCount = 4 * 1024 / 256;
                }

                if ((_moduleInformation.Processor == ProcessorType.AT_MEGA_16) || (_moduleInformation.Processor == ProcessorType.AT_MEGA_164))
                {
                    this._pageCount = 1 * 512 / 128;
                }


                if ((_moduleInformation.Processor == ProcessorType.AT_MEGA_32_U4) || (_moduleInformation.Processor == ProcessorType.AT_MEGA_328_P))
                {
                    this._pageCount = 1 * 1024 / 128;
                }


                break;
            }

            case TypeOfMemory.BOOT_FLASH:
            {
                this._pageCount = count;
                _startPage      = startpage;
                break;
            }

            case TypeOfMemory.RALAY_DISCRET:
            {
                this._pageCount = 1;
                this._startPage = 1020;
                break;
            }

            case TypeOfMemory.WORK:
            {
                if (_moduleInformation.Processor == ProcessorType.AT_MEGA_128)
                {
                    _pageCount = 480;
                    break;
                }
                if (_moduleInformation.Processor == ProcessorType.AT_MEGA_2561)
                {
                    _pageCount = 992;
                    break;
                }
                else
                {
                    _pageCount = 96;
                    break;
                }
            }
            }
        }