private void rbType_CheckedChanged(object sender, EventArgs e) { // изменение типа элемента if (procChangedEv && selElemInfo != null) { Modbus.Elem elem = selElemInfo.Elem; if (rbUShort.Checked) { elem.ElemType = Modbus.ElemTypes.UShort; } else if (rbShort.Checked) { elem.ElemType = Modbus.ElemTypes.Short; } else if (rbUInt.Checked) { elem.ElemType = Modbus.ElemTypes.UInt; } else if (rbInt.Checked) { elem.ElemType = Modbus.ElemTypes.Int; } else if (rbULong.Checked) { elem.ElemType = Modbus.ElemTypes.ULong; } else if (rbLong.Checked) { elem.ElemType = Modbus.ElemTypes.Long; } else if (rbFloat.Checked) { elem.ElemType = Modbus.ElemTypes.Float; } else if (rbDouble.Checked) { elem.ElemType = Modbus.ElemTypes.Double; } else { elem.ElemType = Modbus.ElemTypes.Bool; } txtElemAddress.Text = selElemInfo.AddressRange; selNode.Text = selElemInfo.Caption; UpdateElemNodes(selNode.Parent); Modified = true; } }
/// <summary> /// Выполнить действия после добавления КП на линию связи /// </summary> public override void OnAddedToCommLine() { // загрузка шаблона устройства deviceModel = null; elemGroupCnt = 0; floatSignals = new HashSet <int>(); string fileName = KPReqParams.CmdLine.Trim(); if (fileName == "") { WriteToLog((Localization.UseRussian ? "Не задан шаблон устройства для " : "Template is undefined for the ") + Caption); } else { Dictionary <string, Modbus.DeviceModel> templates = GetTemplates(); if (templates.ContainsKey(fileName)) { // создание модели устройства на основе модели, загруженной ранее Modbus.DeviceModel template = templates[fileName]; if (template != null) { deviceModel = new Modbus.DeviceModel(); deviceModel.CopyFrom(template); elemGroupCnt = deviceModel.ElemGroups.Count; } } else { WriteToLog((Localization.UseRussian ? "Загрузка шаблона устройства из файла " : "Load device template from file ") + fileName); Modbus.DeviceModel template = new Modbus.DeviceModel(); string errMsg; if (template.LoadTemplate(ConfigDir + fileName, out errMsg)) { deviceModel = template; elemGroupCnt = deviceModel.ElemGroups.Count; templates.Add(fileName, template); } else { WriteToLog(errMsg); templates.Add(fileName, null); } } } // инициализация параметров КП на основе модели устройства if (elemGroupCnt > 0) { ParamGroup[] paramGroups = new ParamGroup[elemGroupCnt]; int paramInd = 0; int paramGroupInd = 0; foreach (Modbus.ElemGroup elemGroup in deviceModel.ElemGroups) { int elemCnt = elemGroup.Elems.Count; ParamGroup paramGroup = new ParamGroup(elemGroup.Name, elemCnt); paramGroups[paramGroupInd++] = paramGroup; elemGroup.StartParamInd = paramInd; for (int i = 0; i < elemCnt; i++) { int signal = ++paramInd; Modbus.Elem elem = elemGroup.Elems[i]; Param param = new Param(signal, elem.Name); paramGroup.KPParams[i] = param; if (elem.ElemType == Modbus.ElemTypes.Float) { floatSignals.Add(signal); } } } InitArrays(paramInd, elemGroupCnt); for (int i = 0; i < elemGroupCnt; i++) { ParamGroups[i] = paramGroups[i]; } CopyParamsFromGroups(); CanSendCmd = deviceModel.Cmds.Count > 0; } }