/// <summary> /// Удаляет устройство из контейнера. /// </summary> /// <param name="clxDevice">Устройство которое необходимо удалить.</param> /// <returns></returns> public bool Remove(TreeNode_EthernetDevice treeNode_EthernetDevice) { if (treeNode_EthernetDevice == null) { return(false); } if (!this.CLXDevicesByName.ContainsKey(treeNode_EthernetDevice.Device.Name)) { return(false); } if (treeNode_EthernetDevice.Task.ProcessState != TaskProcessState.Stop || treeNode_EthernetDevice.Task.ServerState != ServerState.Off) { return(false); } treeNode_EthernetDevice.DevicePropertyWasChanged -= treeNode_EthernetDevice_DevicePropertyWasChanged; treeNode_EthernetDevice.TagsValueWasChanged -= treeNode_EthernetDevice_TagsValueWasChanged; treeNode_EthernetDevice.TagsValueWasReaded -= treeNode_EthernetDevice_TagsValueWasReaded; treeNode_EthernetDevice.TagsValueWasWrited -= treeNode_EthernetDevice_TagsValueWasWrited; treeNode_EthernetDevice.TaskStateWasChanged -= treeNode_EthernetDevice_TaskStateWasChanged; treeNode_EthernetDevice.Message -= treeNode_EthernetDevice_Message; this.treeView.Nodes.Remove(treeNode_EthernetDevice); // Вызываем событие. Event_TaskCollectionWasChanged(); return(true); }
/// <summary> /// Добавляет новое устройство в контейнер. /// </summary> /// <param name="treeNode_EthernetDevice">Новый визуальный объект характеризующий устройство.</param> /// <returns></returns> public bool Add(TreeNode_EthernetDevice treeNode_EthernetDevice) { if (treeNode_EthernetDevice == null) { return(false); } string name = treeNode_EthernetDevice.Device.Name; string address = treeNode_EthernetDevice.Device.Address + "/" + treeNode_EthernetDevice.Device.ProcessorSlot; if (this.CLXDevicesByName.ContainsKey(name) || this.CLXDevicesByAddress.ContainsKey(address)) { return(false); } this.treeView.Nodes.Add(treeNode_EthernetDevice); treeNode_EthernetDevice.DevicePropertyWasChanged += treeNode_EthernetDevice_DevicePropertyWasChanged; treeNode_EthernetDevice.TagsValueWasChanged += treeNode_EthernetDevice_TagsValueWasChanged; treeNode_EthernetDevice.TagsValueWasReaded += treeNode_EthernetDevice_TagsValueWasReaded; treeNode_EthernetDevice.TagsValueWasWrited += treeNode_EthernetDevice_TagsValueWasWrited; treeNode_EthernetDevice.TaskStateWasChanged += treeNode_EthernetDevice_TaskStateWasChanged; treeNode_EthernetDevice.Message += treeNode_EthernetDevice_Message; // Вызываем событие. Event_TaskCollectionWasChanged(); return(true); }
/// <summary> /// Подписка на событие : ToolStripButton : Нажата кнопка. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripButton_Add_Click(object sender, EventArgs e) { string plcName = "NewPLC_"; for (int ix = 0; ix < 1000; ix++) { if (!this.CLXDevicesByName.ContainsKey(plcName + ix.ToString())) { plcName = plcName + ix.ToString(); break; } } LogixDevice newCLXDevice = new LogixDevice(plcName, new System.Net.IPAddress(new byte[] { 0, 0, 0, 0 }), 0); TreeNode_EthernetDevice treeNodeEthernetDevice = new TreeNode_EthernetDevice(newCLXDevice); this.Add(treeNodeEthernetDevice); this.treeView.SelectedNode = treeNodeEthernetDevice; }
/* ======================================================================================== */ #endregion #region [ PUBLIC METHODS ] /* ======================================================================================== */ /// <summary> /// Добавляет новое устройство по умолчанию в контейнер. /// </summary> /// <param name="namePrefix">Префикс имени по умолчанию для добваления. После текущего имени следуют символы цифр.</param> /// <param name="defaultIpAddress">IP Адрес устройства по умолчанию.</param> /// <returns></returns> public bool Add(string namePrefix, byte [] defaultIpAddress) { bool result; string plcName = namePrefix; for (int ix = 0; ix < 1000; ix++) { if (!this.CLXDevicesByName.ContainsKey(plcName + ix.ToString())) { plcName = plcName + ix.ToString(); break; } } LogixDevice newCLXDevice = new LogixDevice(plcName, new System.Net.IPAddress(defaultIpAddress), 0); TreeNode_EthernetDevice treeNodeEthernetDevice = new TreeNode_EthernetDevice(newCLXDevice); result = this.Add(treeNodeEthernetDevice); this.treeView.SelectedNode = treeNodeEthernetDevice; return(result); }