Esempio n. 1
0
        private void FrmDevTemplate_Load(object sender, EventArgs e)
        {
            // перевод формы
            Translator.TranslateForm(this, "Scada.Comm.Devices.Modbus.UI.FrmDevTemplate");
            TranslateTree();

            // настройка элементов управления
            openFileDialog.InitialDirectory = appDirs.ConfigDir;
            saveFileDialog.InitialDirectory = appDirs.ConfigDir;
            ctrlElem.Top = ctrlCmd.Top = ctrlElemGroup.Top;

            if (saveOnly)
            {
                btnNew.Visible  = false;
                btnOpen.Visible = false;
            }

            if (string.IsNullOrEmpty(initialFileName))
            {
                saveFileDialog.FileName = NewFileName;
                template = new DeviceTemplate();
                FillTree();
            }
            else
            {
                saveFileDialog.FileName = initialFileName;
                LoadTemplate(initialFileName);
            }
        }
Esempio n. 2
0
        public static DeviceFile.DevicePartParams NewPart24r2(DeviceFile DevFile, string basePartName, string partName, DeviceTemplate template)
        {
            DeviceFile.DevicePartParams newPart = DevFile.PartsList.First(p => p.PartName == basePartName);

            // These can be easily found from the family programmer's manual
            newPart.PartName = partName;
            newPart.DeviceID = template.deviceId;
            newPart.ProgramMem = template.family.programSize / 2 + 1;   // Size of program FLASH. Not sure what units this is
            newPart.ConfigAddr = template.family.configAddr * 2;        // Address of the highest config register (ie. CONFIG4)
            newPart.ConfigWords = 4;                                    // Number of config registers

            // Mask out unused bits.
            // This can be found in the PIC datasheet. Reserved bits should be masked out.
            // Configuration registers are in reverse order, ie. { CONFIG4, CONFIG3, CONFIG2, CONFIG1 }, with the CONFIG4 at the LOWEST address.
            newPart.ConfigMasks = new ushort[8] { 0x0000, 0xFFFF, 0xFFF3, 0x7BFF, 0, 0, 0, 0 };
            newPart.ConfigBlank = new ushort[8] { 0xFFFF, 0xFFFF, 0xFFF3, 0x7BFF, 0, 0, 0, 0 }; // Default configuration (Check the datasheet to see what the reserved bits should be set to)
            //NOTE: Above only tested with PIC24FJ256DA206.

            // Code-protect detection (only used in PicKit2 GUI?)
            newPart.CPConfig = 4;       // Which config contains the code-protect bits. This corresponds to CONFIG1
            newPart.CPMask = 0x3000;    // There are two CP-config bits, if either are 0 then CP is active.

            // PIC Family
            newPart.Family = DevFile.Families.First(f => f.FamilyName == "PIC24r2").FamilyID;

            // Update scripts to PIC24r2
            newPart.ChipEraseScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ChpErase450ms.1").ScriptNumber;
            newPart.ProgMemAddrSetScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_SetAddr.1").ScriptNumber;
            newPart.ProgMemRdScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemRd32.1").ScriptNumber;
            newPart.ProgMemWrPrepScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemWrPrep.1").ScriptNumber;
            newPart.ProgMemWrScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemWr64.1").ScriptNumber;

            return newPart;
        }
Esempio n. 3
0
 public DeviceChangedEventArgs(DeviceType deviceType, DeviceTemplate oldDevice, DeviceTemplate newDevice, IReadonlyContext oldDeviceArgs)
 {
     DeviceType    = deviceType;
     OldDevice     = oldDevice;
     NewDevice     = newDevice;
     OldDeviceArgs = oldDeviceArgs ?? EmptyContext.Instance;
 }
Esempio n. 4
0
        public void DeviceTemplate_ReferenceEquals_DeviceTemplate()
        {
            DeviceTemplate template1 = new DeviceTemplate("file.odt|File||");
            DeviceTemplate template2 = template1;

            Assert.IsTrue(template1.Equals(template2));
        }
Esempio n. 5
0
        public void DeviceTemplate_StringEquals_DeviceTemplate()
        {
            DeviceTemplate template1 = new DeviceTemplate("file.odt|File||");
            DeviceTemplate template2 = new DeviceTemplate("file.odt|File||");

            Assert.AreEqual(template1.ToString(), template2.ToString());
        }
Esempio n. 6
0
        private void FrmDevTemplate_Load(object sender, EventArgs e)
        {
            // перевод формы
            Translator.TranslateForm(this, "Scada.Comm.Devices.Modbus.UI.FrmDevTemplate");
            openFileDialog.SetFilter(KpPhrases.TemplateFileFilter);
            saveFileDialog.SetFilter(KpPhrases.TemplateFileFilter);
            TranslateTree();

            // настройка элементов управления
            openFileDialog.InitialDirectory = appDirs.ConfigDir;
            saveFileDialog.InitialDirectory = appDirs.ConfigDir;
            btnEditSettingsExt.Visible      = uiCustomization.ExtendedSettingsAvailable;
            ctrlElem.Top = ctrlCmd.Top = ctrlElemGroup.Top;

            if (saveOnly)
            {
                btnNew.Visible  = false;
                btnOpen.Visible = false;
            }

            if (string.IsNullOrEmpty(initialFileName))
            {
                saveFileDialog.FileName = NewFileName;
                template = uiCustomization.TemplateFactory.CreateDeviceTemplate();
                FillTree();
            }
            else
            {
                saveFileDialog.FileName = initialFileName;
                LoadTemplate(initialFileName);
            }
        }
        private IEnumerable<DeviceBlueprint> Load(string manifest)
        {
            JToken root = JsonConvert.DeserializeObject(manifest) as JToken;

            var globalSettingsToken = root["globalSettings"];
            if (globalSettingsToken != null)
            {
                GlobalSettings.Instance.Load(globalSettingsToken);
            }

            var devices = new List<DeviceBlueprint>();

            var groups = root["deviceGroups"] as JArray;
            foreach (var group in groups)
            {
                var name = group.Value<string>("name");
                var jobs = group["jobs"] as JArray;
                var template = new DeviceTemplate(name, jobs);

                var deviceCredentials = group["devices"] as JArray;
                foreach (var deviceCredential in deviceCredentials)
                {
                    var deviceId = deviceCredential.Value<string>("deviceId");
                    var deviceSecret = deviceCredential.Value<string>("deviceSecret");
                    var device = new DeviceBlueprint(deviceId, deviceSecret, template);

                    devices.Add(device);
                }
            }

            return devices;
        }
Esempio n. 8
0
        /// <summary>
        /// Creates tag groups according to the specified template.
        /// </summary>
        protected virtual List <TagGroup> CreateTagGroups(DeviceTemplate deviceTemplate, ref int tagInd)
        {
            List <TagGroup> tagGroups = new List <TagGroup>();

            if (deviceTemplate != null)
            {
                foreach (ElemGroup elemGroup in deviceTemplate.ElemGroups)
                {
                    TagGroup tagGroup = new TagGroup(elemGroup.Name);
                    tagGroups.Add(tagGroup);
                    elemGroup.StartKPTagInd = tagInd;

                    foreach (Elem elem in elemGroup.Elems)
                    {
                        int signal = ++tagInd;
                        tagGroup.AddNewTag(signal, elem.Name);

                        if (elem.ElemType == ElemType.Float || elem.ElemType == ElemType.Double)
                        {
                            floatSignals.Add(signal);
                        }
                    }
                }
            }

            return(tagGroups);
        }
Esempio n. 9
0
 public Device(string id, string deviceId, DeviceTemplate deviceTemplate, string name, bool simulated)
 {
     this.id             = id;
     this.deviceId       = deviceId;
     this.deviceTemplate = deviceTemplate;
     this.name           = name;
     this.simulated      = simulated;
 }
Esempio n. 10
0
        private void InitializeDeviceConfigurationPanel(DeviceTemplate device)
        {
            _deviceViewModel.Current = device;
            _deviceViewModel.ParamPanel.SetDescriptors(device?.Factory as IParameterPresentAdapter, AsGroup(device?.Factory.GetParameters(device.Clz)));

            InvalidateScrollInfo();
            IsLayoutDirty = IsLoaded;
        }
Esempio n. 11
0
        public void DeviceTemplate_ValueEquals_DeviceTemplate()
        {
            DeviceTemplate template1 = new DeviceTemplate("file1.odt|File 1||");
            DeviceTemplate template2 = new DeviceTemplate("file1.odt|File 1||");
            DeviceTemplate template3 = new DeviceTemplate("file2.odt|File 2||");

            Assert.IsTrue(template1.Equals(template2));
            Assert.IsFalse(template1.Equals(template3));
        }
Esempio n. 12
0
        public void DeviceTemplate_HashCodeEquals_DeviceTemplate()
        {
            DeviceTemplate template1 = new DeviceTemplate("file.odt|File||");
            DeviceTemplate template2 = new DeviceTemplate("file.odt|File||");

            var template1Hash = template1.GetHashCode();
            var template2Hash = template2.GetHashCode();

            Assert.AreEqual(template1Hash, template2Hash);
        }
Esempio n. 13
0
 private void btnNew_Click(object sender, EventArgs e)
 {
     // создание шаблона устройства
     if (CheckChanges())
     {
         saveFileDialog.FileName = NewFileName;
         template = uiCustomization.TemplateFactory.CreateDeviceTemplate();
         fileName = "";
         SetFormTitle();
         FillTree();
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Creates channel prototypes based on the device template.
        /// </summary>
        protected virtual KPCnlPrototypes CreateCnlPrototypes(DeviceTemplate deviceTemplate)
        {
            KPCnlPrototypes         prototypes = new KPCnlPrototypes();
            List <InCnlPrototype>   inCnls     = prototypes.InCnls;
            List <CtrlCnlPrototype> ctrlCnls   = prototypes.CtrlCnls;

            // создание прототипов входных каналов
            int signal = 1;

            foreach (ElemGroup elemGroup in deviceTemplate.ElemGroups)
            {
                bool isTS =
                    elemGroup.TableType == TableType.DiscreteInputs ||
                    elemGroup.TableType == TableType.Coils;

                foreach (Elem elem in elemGroup.Elems)
                {
                    InCnlPrototype inCnl = isTS ?
                                           new InCnlPrototype(elem.Name, BaseValues.CnlTypes.TS) :
                                           new InCnlPrototype(elem.Name, BaseValues.CnlTypes.TI);
                    inCnl.Signal = signal++;

                    if (isTS)
                    {
                        inCnl.ShowNumber = false;
                        inCnl.UnitName   = BaseValues.UnitNames.OffOn;
                        inCnl.EvEnabled  = true;
                        inCnl.EvOnChange = true;
                    }

                    inCnls.Add(inCnl);
                }
            }

            // создание прототипов каналов управления
            foreach (ModbusCmd modbusCmd in deviceTemplate.Cmds)
            {
                CtrlCnlPrototype ctrlCnl = modbusCmd.TableType == TableType.Coils && modbusCmd.Multiple ?
                                           new CtrlCnlPrototype(modbusCmd.Name, BaseValues.CmdTypes.Binary) :
                                           new CtrlCnlPrototype(modbusCmd.Name, BaseValues.CmdTypes.Standard);
                ctrlCnl.CmdNum = modbusCmd.CmdNum;

                if (modbusCmd.TableType == TableType.Coils && !modbusCmd.Multiple)
                {
                    ctrlCnl.CmdValName = BaseValues.CmdValNames.OffOn;
                }

                ctrlCnls.Add(ctrlCnl);
            }

            return(prototypes);
        }
Esempio n. 15
0
        /// <summary>
        /// Загрузить шаблон устройства из файла
        /// </summary>
        private void LoadTemplate(string fname)
        {
            template = new DeviceTemplate();
            fileName = fname;
            SetFormTitle();
            string errMsg;

            if (!template.Load(fname, out errMsg))
            {
                ScadaUiUtils.ShowError(errMsg);
            }

            FillTree();
        }
Esempio n. 16
0
        /// <summary>
        /// Loads the device template from the specified file.
        /// </summary>
        private void LoadTemplate(string fileName)
        {
            template = customUi.CreateDeviceTemplate();

            if (!template.Load(fileName, out string errMsg))
            {
                ScadaUiUtils.ShowError(errMsg);
            }

            FileName = fileName;
            SetFormTitle();
            FillTree();
            Modified = false;
        }
Esempio n. 17
0
        /// <summary>
        /// Загрузить шаблон устройства из файла
        /// </summary>
        private void LoadTemplate(string fname)
        {
            template = uiCustomization.TemplateFactory.CreateDeviceTemplate();
            fileName = fname;
            SetFormTitle();
            string errMsg;

            if (!template.Load(fname, out errMsg))
            {
                ScadaUiUtils.ShowError(errMsg);
            }

            FillTree();
        }
Esempio n. 18
0
        public IActionResult GetDevice(string TemplateFolder,
                                       string DeviceId,
                                       string TemplateProperty = null,
                                       string Template         = null)
        {
            try {
                Device         device = _deviceRepository.GetDeviceById(DeviceId);
                DeviceTemplate model  = new DeviceTemplate();
                model.Device = device;
                model.ID     = DeviceId;
                model.Global = _config.GetSection("Global");

                Uri    uri     = new Uri(Request.GetEncodedUrl());
                String baseUrl = uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped).ToString();
                model.BaseUrl = baseUrl;

                String view = $"Views/{TemplateFolder}";

                if (!String.IsNullOrEmpty(Template))
                {
                    view += "/" + Template;
                }
                else if (!String.IsNullOrEmpty(TemplateProperty))
                {
                    if (!device.ContainsKey(TemplateProperty))
                    {
                        return(new UnprocessableEntityObjectResult($"The device did not contain a value for the TemplateProperty '{TemplateProperty}'"));
                    }
                    if (device[TemplateProperty] is ResultPropertyValueCollection)
                    {
                        view += "/" + ((ResultPropertyValueCollection)device[TemplateProperty])[0];
                    }
                    else
                    {
                        view += "/" + device[TemplateProperty];
                    }
                }
                view += ".cshtml";
                Response.ContentType = "text/plain";
                return(View(view, model));
            } catch (DeviceNotFoundException e) {
                return(NotFound(e.Message));
            } catch (Exception e) {
                return(View(new ErrorViewModel {
                    ErrorMessage = e.Message
                }));
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Loads a device template from the configuration file.
        /// </summary>
        protected DeviceTemplate LoadDeviceTemplate()
        {
            DeviceTemplate deviceTemplate = null;
            string         fileName       = DeviceConfig.PollingOptions.CmdLine.Trim();

            if (!string.IsNullOrEmpty(fileName))
            {
                deviceTemplate = customUi.CreateDeviceTemplate();

                if (!deviceTemplate.Load(Path.Combine(AppDirs.ConfigDir, fileName), out string errMsg))
                {
                    throw new ScadaException(errMsg);
                }
            }

            return(deviceTemplate);
        }
Esempio n. 20
0
        /// <summary>
        /// Загрузить шаблон устройства из файла
        /// </summary>
        private void LoadTemplate(string fname)
        {
            DeviceTemplate templ = new DeviceTemplate();
            string         errMsg;

            if (templ.Load(fname, out errMsg))
            {
                template = templ;
                fileName = fname;
                SetFormTitle();
                FillTree();
            }
            else
            {
                ScadaUiUtils.ShowError(errMsg);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public FrmDeviceTemplate(AppDirs appDirs, CustomUi customUi)
            : this()
        {
            this.appDirs   = appDirs ?? throw new ArgumentNullException(nameof(appDirs));
            this.customUi  = customUi ?? throw new ArgumentNullException(nameof(customUi));
            elemGroupsNode = treeView.Nodes["elemGroupsNode"];
            commandsNode   = treeView.Nodes["commandsNode"];

            template          = null;
            modified          = false;
            selectedNode      = null;
            selectedElemGroup = null;
            selectedElemTag   = null;
            selectedCmd       = null;

            SaveOnly = false;
            FileName = "";
        }
Esempio n. 22
0
        private TreeNode cmdsNode;               // узел дерева "Команды"


        /// <summary>
        /// Конструктор, ограничивающий создание формы без параметров
        /// </summary>
        private FrmDevTemplate()
        {
            InitializeComponent();

            appDirs         = null;
            initialFileName = "";
            fileName        = "";
            saveOnly        = false;

            template     = null;
            modified     = false;
            selElemGroup = null;
            selElemInfo  = null;
            selCmd       = null;
            selNode      = null;
            grsNode      = treeView.Nodes["grsNode"];
            cmdsNode     = treeView.Nodes["cmdsNode"];
        }
Esempio n. 23
0
        /// <summary>
        /// Gets existing or create a new device template.
        /// </summary>
        private void PrepareTemplate(string fileName)
        {
            deviceTemplate = null;

            if (string.IsNullOrEmpty(fileName))
            {
                WriteToLog(string.Format(Localization.UseRussian ?
                                         "{0} Ошибка: Не задан шаблон устройства для {1}" :
                                         "{0} Error: Template is undefined for the {1}", CommUtils.GetNowDT(), Caption));
            }
            else
            {
                TemplateDict templateDict = GetTemplateDictionary();

                if (templateDict.TryGetValue(fileName, out DeviceTemplate existingTemplate))
                {
                    if (existingTemplate != null)
                    {
                        deviceTemplate = GetTemplateFactory().CreateDeviceTemplate();
                        deviceTemplate.CopyFrom(existingTemplate);
                    }
                }
                else
                {
                    DeviceTemplate newTemplate = GetTemplateFactory().CreateDeviceTemplate();
                    WriteToLog(string.Format(Localization.UseRussian ?
                                             "{0} Загрузка шаблона устройства из файла {1}" :
                                             "{0} Load device template from file {1}", CommUtils.GetNowDT(), fileName));
                    string filePath = Path.IsPathRooted(fileName) ?
                                      fileName : Path.Combine(AppDirs.ConfigDir, fileName);

                    if (newTemplate.Load(filePath, out string errMsg))
                    {
                        deviceTemplate = newTemplate;
                    }
                    else
                    {
                        WriteToLog(errMsg);
                    }

                    templateDict.Add(fileName, deviceTemplate);
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Gets the device template from the shared dictionary.
        /// </summary>
        protected virtual DeviceTemplate GetDeviceTemplate()
        {
            DeviceTemplate deviceTemplate = null;
            string         fileName       = PollingOptions.CmdLine.Trim();

            if (string.IsNullOrEmpty(fileName))
            {
                Log.WriteLine(string.Format(Locale.IsRussian ?
                                            "Ошибка: Не задан шаблон устройства для {0}" :
                                            "Error: Device template is undefined for {0}", Title));
            }
            else
            {
                TemplateDict templateDict = GetTemplateDict();

                if (templateDict.TryGetValue(fileName, out DeviceTemplate existingTemplate))
                {
                    deviceTemplate = existingTemplate;
                }
                else
                {
                    Log.WriteLine(string.Format(Locale.IsRussian ?
                                                "Загрузка шаблона устройства из файла {0}" :
                                                "Load device template from file {0}", fileName));

                    DeviceTemplate newTemplate = CreateDeviceTemplate();
                    templateDict.Add(fileName, newTemplate);

                    if (newTemplate.Load(Storage, fileName, out string errMsg))
                    {
                        deviceTemplate = newTemplate;
                    }
                    else
                    {
                        Log.WriteLine(errMsg);
                    }
                }
            }

            return(deviceTemplate);
        }
Esempio n. 25
0
        /// <summary>
        /// Gets existing or create a new device template.
        /// </summary>
        private void PrepareTemplate(string fileName)
        {
            if (fileName == "")
            {
                WriteToLog(string.Format(Localization.UseRussian ?
                                         "{0} Ошибка: Не задан шаблон устройства для {1}" :
                                         "{0} Error: Template is undefined for the {1}", CommUtils.GetNowDT(), Caption));
                deviceTemplate = null;
            }
            else
            {
                deviceTemplate = GetTemplateFactory().CreateDeviceTemplate();
                Dictionary <string, DeviceTemplate> templates = GetTemplateDictionary();

                if (templates.ContainsKey(fileName))
                {
                    // копирование свойств шаблона, загруженного ранее
                    deviceTemplate.CopyFrom(templates[fileName]);
                }
                else
                {
                    WriteToLog(string.Format(Localization.UseRussian ?
                                             "{0} Загрузка шаблона устройства из файла {1}" :
                                             "{0} Load device template from file {1}", CommUtils.GetNowDT(), fileName));
                    string filePath = Path.IsPathRooted(fileName) ?
                                      fileName : Path.Combine(AppDirs.ConfigDir, fileName);

                    if (!deviceTemplate.Load(filePath, out string errMsg))
                    {
                        WriteToLog(errMsg);
                        deviceTemplate = null;
                    }

                    templates.Add(fileName, deviceTemplate);
                }
            }
        }
Esempio n. 26
0
        public static DeviceFile.DevicePartParams NewPart24r2(DeviceFile DevFile, string basePartName, string partName, DeviceTemplate template)
        {
            DeviceFile.DevicePartParams newPart = DevFile.PartsList.First(p => p.PartName == basePartName);

            // These can be easily found from the family programmer's manual
            newPart.PartName    = partName;
            newPart.DeviceID    = template.deviceId;
            newPart.ProgramMem  = template.family.programSize / 2 + 1;  // Size of program FLASH. Not sure what units this is
            newPart.ConfigAddr  = template.family.configAddr * 2;       // Address of the highest config register (ie. CONFIG4)
            newPart.ConfigWords = 4;                                    // Number of config registers

            // Mask out unused bits.
            // This can be found in the PIC datasheet. Reserved bits should be masked out.
            // Configuration registers are in reverse order, ie. { CONFIG4, CONFIG3, CONFIG2, CONFIG1 }, with the CONFIG4 at the LOWEST address.
            newPart.ConfigMasks = new ushort[8] {
                0x0000, 0xFFFF, 0xFFF3, 0x7BFF, 0, 0, 0, 0
            };
            newPart.ConfigBlank = new ushort[8] {
                0xFFFF, 0xFFFF, 0xFFF3, 0x7BFF, 0, 0, 0, 0
            };                                                                                  // Default configuration (Check the datasheet to see what the reserved bits should be set to)
            //NOTE: Above only tested with PIC24FJ256DA206.

            // Code-protect detection (only used in PicKit2 GUI?)
            newPart.CPConfig = 4;       // Which config contains the code-protect bits. This corresponds to CONFIG1
            newPart.CPMask   = 0x3000;  // There are two CP-config bits, if either are 0 then CP is active.

            // PIC Family
            newPart.Family = DevFile.Families.First(f => f.FamilyName == "PIC24r2").FamilyID;

            // Update scripts to PIC24r2
            newPart.ChipEraseScript      = DevFile.Scripts.First(s => s.ScriptName == "24r2_ChpErase450ms.1").ScriptNumber;
            newPart.ProgMemAddrSetScript = DevFile.Scripts.First(s => s.ScriptName == "24r2_SetAddr.1").ScriptNumber;
            newPart.ProgMemRdScript      = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemRd32.1").ScriptNumber;
            newPart.ProgMemWrPrepScript  = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemWrPrep.1").ScriptNumber;
            newPart.ProgMemWrScript      = DevFile.Scripts.First(s => s.ScriptName == "24r2_ProgMemWr64.1").ScriptNumber;

            return(newPart);
        }
Esempio n. 27
0
        /// <summary>
        /// 将RSJ的源数据转换
        /// </summary>
        /// <param name="resultData">源数据</param>
        /// <param name="project">项目名称</param>
        /// <param name="startAddress">数据起始地址</param>
        /// <param name="length">数据长度</param>
        /// <returns></returns>
        private static RSJ RSJConvertData(byte[] resultData, List <DeviceTemplate> deviceTemplateList)
        {
            RSJ rsj = new RSJ();

            #region 初始化染缸对象
            DeviceTemplate dvTemplate = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "染缸数量");
            int            gangNum    = rsj.RGSL = (short)ReadData.GetData(resultData, dvTemplate.Address, dvTemplate.Length);
            List <RG>      listRG     = new List <RG>();
            for (int i = 0; i < gangNum; i++)
            {
                RG rg = new RG();
                rg.RGBH = (short)(i + 1);
                listRG.Add(rg);
            }
            #endregion

            #region 染色机数据封装
            foreach (DeviceTemplate deviceTamplate in deviceTemplateList)
            {
                switch (deviceTamplate.Project)
                {
                case "设备型号":
                    rsj.SBXH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    break;

                case "设备诊断信息":
                    rsj.PLCZT = ReadData.GetIntArrayData(resultData, deviceTamplate.Address + 20, deviceTamplate.Length - 20, 1);
                    break;

                case "设备规格":
                    rsj.SBGG = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    break;

                case "设备编号":
                    rsj.SBBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    break;

                case "染缸数量":
                    rsj.RGSL = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    break;

                case "操作人编号":
                    rsj.CZRBH = ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    break;
                    #region
                    //case "设备运行状态1":
                    //    rsj.RG[1].SBYXZT = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "设备运行状态2":
                    //    rsj.RG[2].SBYXZT = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "设备运行状态3":
                    //    rsj.RG[3].SBYXZT = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "设备运行状态4":
                    //    rsj.RG[4].SBYXZT = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "设备运行状态5":
                    //    rsj.RG[5].SBYXZT = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;

                    //case "运行时间1":
                    //    rsj.RG[1].YXSJ = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "运行时间2":
                    //    rsj.RG[2].YXSJ = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "运行时间3":
                    //    rsj.RG[3].YXSJ = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "运行时间4":
                    //    rsj.RG[4].YXSJ = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "运行时间5":
                    //    rsj.RG[5].YXSJ = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺段号1":
                    //    rsj.RG[1].GYDH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺段号2":
                    //    rsj.RG[2].GYDH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺段号3":
                    //    rsj.RG[3].GYDH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺段号4":
                    //    rsj.RG[4].GYDH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺段号5":
                    //    rsj.RG[5].GYDH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺步号1":
                    //    rsj.RG[1].GYBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺步号2":
                    //    rsj.RG[2].GYBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺步号3":
                    //    rsj.RG[3].GYBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺步号4":
                    //    rsj.RG[4].GYBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺步号5":
                    //    rsj.RG[5].GYBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺名称1":
                    //    rsj.RG[1].GYMC = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺名称2":
                    //    rsj.RG[2].GYMC = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺名称3":
                    //    rsj.RG[3].GYMC = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺名称4":
                    //    rsj.RG[4].GYMC = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "工艺名称5":
                    //    rsj.RG[5].GYMC = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "泵速度1":
                    //    rsj.RG[1].BSD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "泵速度2":
                    //    rsj.RG[2].BSD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "泵速度3":
                    //    rsj.RG[3].BSD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "泵速度4":
                    //    rsj.RG[4].BSD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "泵速度5":
                    //    rsj.RG[5].BSD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "温度1":
                    //    rsj.RG[1].WD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "温度2":
                    //    rsj.RG[2].WD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "温度3":
                    //    rsj.RG[3].WD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "温度4":
                    //    rsj.RG[4].WD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "温度5":
                    //    rsj.RG[5].WD = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "压力1":
                    //    rsj.RG[1].YL = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "压力2":
                    //    rsj.RG[2].YL = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "压力3":
                    //    rsj.RG[3].YL = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "压力4":
                    //    rsj.RG[4].YL = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "压力5":
                    //    rsj.RG[5].YL = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "控制字11":
                    //    rsj.RG[1].KZZ1 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字12":
                    //    rsj.RG[2].KZZ1 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字13":
                    //    rsj.RG[3].KZZ1 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字14":
                    //    rsj.RG[4].KZZ1 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字15":
                    //    rsj.RG[5].KZZ1 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字21":
                    //    rsj.RG[1].KZZ2 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字22":
                    //    rsj.RG[2].KZZ2 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字23":
                    //    rsj.RG[3].KZZ2 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字24":
                    //    rsj.RG[4].KZZ2 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字25":
                    //    rsj.RG[5].KZZ2 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字31":
                    //    rsj.RG[1].KZZ3 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字32":
                    //    rsj.RG[2].KZZ3 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字33":
                    //    rsj.RG[3].KZZ3 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字34":
                    //    rsj.RG[4].KZZ3 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;
                    //case "控制字35":
                    //    rsj.RG[5].KZZ3 = ReadData.GetStringData(resultData, deviceTamplate.Address, deviceTamplate.Length, 2);
                    //    break;

                    //case "卷筒编号1":
                    //    rsj.RG[1].JTBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "卷筒编号2":
                    //    rsj.RG[2].JTBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "卷筒编号3":
                    //    rsj.RG[3].JTBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "卷筒编号4":
                    //    rsj.RG[4].JTBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    //case "卷筒编号5":
                    //    rsj.RG[5].JTBH = (short)ReadData.GetData(resultData, deviceTamplate.Address, deviceTamplate.Length);
                    //    break;
                    #endregion
                default:
                    break;
                }
            }
            #endregion

            #region 染缸数据封装

            DeviceTemplate dvtRGYXZT = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "设备运行状态1");
            DeviceTemplate dvtRGZDXX = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "设备诊断信息");
            //"设备诊断信息"

            DeviceTemplate dvtRGYXSJ = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "运行时间1");

            DeviceTemplate dvtRGGYDH = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "工艺段号1");
            DeviceTemplate dvtRGGYBH = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "工艺步号1");
            DeviceTemplate dvtRGGYMC = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "工艺名称1");
            DeviceTemplate dvtRGBSD  = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "泵速度1");
            DeviceTemplate dvtRGWD   = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "温度1");
            DeviceTemplate dvtRGYL   = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "压力1");
            DeviceTemplate dvtRGKZZ1 = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "控制字11");
            DeviceTemplate dvtRGKZZ2 = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "控制字21");
            DeviceTemplate dvtRGKZZ3 = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "控制字31");
            DeviceTemplate dvtRGJTBH = BL_DeviceTemplate.GetDeviceTemplate(deviceTemplateList, "卷筒编号1");



            for (int i = 0; i < listRG.Count; i++)
            {
                listRG[i].SBYXZT = (short)ReadData.GetData(resultData, dvtRGYXZT.Address, dvtRGYXZT.Length + i * 2);
                listRG[i].SBZDXX = ReadData.GetStringData(resultData, dvtRGZDXX.Address + i * 2, 4, 2);

                listRG[i].YXSJ = (short)ReadData.GetData(resultData, dvtRGYXSJ.Address, dvtRGYXSJ.Length + i * 2);
                //染色机诊断信息
                listRG[i].GYDH = (short)ReadData.GetData(resultData, dvtRGGYDH.Address, dvtRGGYDH.Length + i * 2);
                listRG[i].GYBH = (short)ReadData.GetData(resultData, dvtRGGYBH.Address, dvtRGGYBH.Length + i * 2);
                listRG[i].GYMC = (short)ReadData.GetData(resultData, dvtRGGYMC.Address, dvtRGGYMC.Length + i * 4);
                listRG[i].BSD  = (short)ReadData.GetData(resultData, dvtRGBSD.Address, dvtRGBSD.Length + i * 2);
                listRG[i].WD   = (short)ReadData.GetData(resultData, dvtRGWD.Address, dvtRGWD.Length + i * 2);
                listRG[i].YL   = (short)ReadData.GetData(resultData, dvtRGYL.Address, dvtRGYL.Length + i * 2);
                listRG[i].KZZ1 = ReadData.GetStringData(resultData, dvtRGKZZ1.Address + i * 2, 2, 2);
                listRG[i].KZZ2 = ReadData.GetStringData(resultData, dvtRGKZZ2.Address + i * 2, 2, 2);
                listRG[i].KZZ3 = ReadData.GetStringData(resultData, dvtRGKZZ3.Address + i * 2, 2, 2);
                listRG[i].JTBH = ReadData.GetData(resultData, dvtRGJTBH.Address + i * 2, 4);
            }

            rsj.RGS = listRG;
            #endregion

            return(rsj);
        }
Esempio n. 28
0
 public new async Task <Device> CreateDevice(string applicationId, string deviceName, DeviceTemplate model)
 {
     return(await CreateDevice(applicationId, deviceName, model.Id, model.Version));
 }
Esempio n. 29
0
 /// <summary>
 /// Shows the extended settings form as a modal dialog box.
 /// </summary>
 /// <returns>Returns true if the settings changed.</returns>
 public virtual bool ShowExtendedSettings(DeviceTemplate deviceTemplate)
 {
     return(false);
 }
Esempio n. 30
0
 /// <summary>
 /// Shows the extended template options as a modal dialog box.
 /// </summary>
 /// <returns>Returns true if the options changed.</returns>
 public virtual bool ShowExtendedOptions(DeviceTemplate deviceTemplate) => false;
Esempio n. 31
0
        /// <summary>
        /// Initializes the device tags.
        /// </summary>
        public override void InitDeviceTags()
        {
            DeviceTemplate deviceTemplate = GetDeviceTemplate();

            if (deviceTemplate == null)
            {
                return;
            }

            // create device model
            deviceModel      = CreateDeviceModel();
            deviceModel.Addr = (byte)NumAddress;

            // add model elements and device tags
            foreach (ElemGroupConfig elemGroupConfig in deviceTemplate.ElemGroups)
            {
                bool      groupActive   = elemGroupConfig.Active;
                bool      groupCommands = groupActive && elemGroupConfig.ReadOnlyEnabled;
                ElemGroup elemGroup     = null;
                TagGroup  tagGroup      = new TagGroup(elemGroupConfig.Name)
                {
                    Hidden = !groupActive
                };
                int elemIndex = 0;

                if (groupActive)
                {
                    elemGroup             = deviceModel.CreateElemGroup(elemGroupConfig.DataBlock);
                    elemGroup.Name        = elemGroupConfig.Name;
                    elemGroup.Address     = (ushort)elemGroupConfig.Address;
                    elemGroup.StartTagIdx = DeviceTags.Count;
                }

                foreach (ElemConfig elemConfig in elemGroupConfig.Elems)
                {
                    // add model element
                    if (groupActive)
                    {
                        Elem elem = elemGroup.CreateElem();
                        elem.Name      = elemConfig.Name;
                        elem.ElemType  = elemConfig.ElemType;
                        elem.ByteOrder = ModbusUtils.ParseByteOrder(elemConfig.ByteOrder) ??
                                         deviceTemplate.Options.GetDefaultByteOrder(ModbusUtils.GetDataLength(elemConfig.ElemType));
                        elemGroup.Elems.Add(elem);
                    }

                    // add model command
                    if (groupCommands && !elemConfig.ReadOnly && !string.IsNullOrEmpty(elemConfig.TagCode))
                    {
                        deviceModel.Cmds.Add(
                            CreateModbusCmd(deviceTemplate.Options, elemGroupConfig, elemConfig, elemIndex));
                    }

                    // add device tag
                    tagGroup.AddTag(elemConfig.TagCode, elemConfig.Name).SetFormat(GetTagFormat(elemConfig));
                    elemIndex++;
                }

                if (groupActive)
                {
                    elemGroup.InitReqPDU();
                    elemGroup.InitReqADU(deviceModel.Addr, transMode);
                    deviceModel.ElemGroups.Add(elemGroup);
                }

                DeviceTags.AddGroup(tagGroup);
            }

            // add model commands
            foreach (CmdConfig cmdConfig in deviceTemplate.Cmds)
            {
                deviceModel.Cmds.Add(CreateModbusCmd(deviceTemplate.Options, cmdConfig));
            }

            deviceModel.InitCmdMap();
            CanSendCommands = deviceModel.Cmds.Count > 0;
            InitModbusPoll();
        }
Esempio n. 32
0
        /// <summary>
        /// Выполнить действия после добавления КП на линию связи
        /// </summary>
        public override void OnAddedToCommLine()
        {
            // загрузка шаблона устройства
            deviceTemplate = null;
            elemGroups     = null;
            elemGroupCnt   = 0;
            floatSignals   = new HashSet <int>();
            string fileName = ReqParams.CmdLine.Trim();

            if (fileName == "")
            {
                WriteToLog(string.Format(Localization.UseRussian ?
                                         "{0} Ошибка: Не задан шаблон устройства для {1}" :
                                         "{0} Error: Template is undefined for the {1}", CommUtils.GetNowDT(), Caption));
            }
            else
            {
                Dictionary <string, DeviceTemplate> templates = GetTemplates();
                if (templates.ContainsKey(fileName))
                {
                    // создание шаблона устройства на основе шаблона, загруженного ранее
                    DeviceTemplate template = templates[fileName];
                    if (template != null)
                    {
                        deviceTemplate = new DeviceTemplate();
                        deviceTemplate.CopyFrom(template);
                    }
                }
                else
                {
                    WriteToLog(string.Format(Localization.UseRussian ?
                                             "{0} Загрузка шаблона устройства из файла {1}" :
                                             "{0} Load device template from file {1}", CommUtils.GetNowDT(), fileName));
                    DeviceTemplate template = new DeviceTemplate();
                    string         errMsg;

                    if (template.Load(AppDirs.ConfigDir + fileName, out errMsg))
                    {
                        deviceTemplate = template;
                        templates.Add(fileName, template);
                    }
                    else
                    {
                        WriteToLog(errMsg);
                        templates.Add(fileName, null);
                    }
                }
            }

            if (deviceTemplate != null)
            {
                elemGroups   = deviceTemplate.GetActiveElemGroups();
                elemGroupCnt = elemGroups.Count;
            }

            // инициализация тегов КП на основе модели устройства
            if (deviceTemplate.ElemGroups.Count > 0)
            {
                List <TagGroup> tagGroups = new List <TagGroup>();
                int             tagInd    = 0;

                foreach (ElemGroup elemGroup in deviceTemplate.ElemGroups)
                {
                    TagGroup tagGroup = new TagGroup(elemGroup.Name);
                    tagGroups.Add(tagGroup);
                    elemGroup.StartKPTagInd = tagInd;

                    foreach (Elem elem in elemGroup.Elems)
                    {
                        int signal = ++tagInd;
                        tagGroup.KPTags.Add(new KPTag(signal, elem.Name));
                        if (elem.ElemType == ElemTypes.Float)
                        {
                            floatSignals.Add(signal);
                        }
                    }
                }

                InitKPTags(tagGroups);
                CanSendCmd = deviceTemplate.Cmds.Count > 0;
            }
        }