public UserControlCom(UserControlBase ub, string com, SERIALData serialValueData, bool configured = false) { InitializeComponent(); UserControl1 us = ub.parent_ as UserControl1; setTreeNodeStatusDelegate = new setTreeNodeStatusEventHandler(us.setTreeComEthNodeStats); serialValueData_ = serialValueData; //串口名 com_ = com; //configured为true,串口数据加载config_project //configured为false,串口数据加载控制器模板数据 configured_ = configured; if (serialValueData_.terminalResis == HAS_BOTH) { radioButton1.Enabled = true; radioButton2.Enabled = true; } else if (serialValueData_.terminalResis == HAS_RS485) { radioButton2.Enabled = false; } if (serialValueData.databitEnable == DATABIE_DISENABLE) { comboBox_Databit.Enabled = false; } else if (serialValueData_.databitEnable == DATABIE_ENABLE) { comboBox_Databit.Enabled = true; } initDone = false; if (configured_) { Init(); setDataToUI(); } else { Init(); } initDone = true; //数据管理里的串口数组 //UserControlBase.dataManage.serialDic.Add(com_, serialValueData); setButtonEnable(false); }
//动态创建串口界面 void createSerialUserControl() { //清空之前加载的串口控件数组 comDic.Clear(); List <DeviceModuleElem> list = dataManage.deviceInfoElem.connector.moduleList; foreach (DeviceModuleElem elem in list) { if (elem.moduleID == "SERIAL_LINE") { SERIALData data = new SERIALData(); data.name = elem.baseName; data.terminalResis = elem.terminalResis; data.databitEnable = elem.databitEnable; UserControlCom com = new UserControlCom(this, elem.baseName, data, false); comDic.Add(elem.baseName, com); dataManage.serialDic.Add(elem.baseName, data); } } }
public void loadXmlSerial(XmlNode xn) { XmlNodeList nodeList = xn.ChildNodes; //创建xn的所有子节点的集合 foreach (XmlNode childNode in nodeList) //遍历集合中所有的节点 { XmlElement e = (XmlElement)childNode; SERIALData serialData = new SERIALData(); string name = e.Name; serialData.name = e.GetAttribute("name"); string baud = e.GetAttribute("baud"); int.TryParse(baud, out serialData.baud); string parity = e.GetAttribute("parity"); int.TryParse(parity, out serialData.Parity); string databit = e.GetAttribute("databit"); int.TryParse(databit, out serialData.dataBit); string stopbit = e.GetAttribute("stopbit"); int.TryParse(stopbit, out serialData.stopBit); //串口模式 string rsMode = e.GetAttribute("rsmode"); int.TryParse(rsMode, out serialData.rsMode); //极化电阻 string polR = e.GetAttribute("polr"); int.TryParse(polR, out serialData.polR); //终端电阻 serialData.terminalResis = e.GetAttribute("terminalresis"); //数据位是否enable serialData.databitEnable = e.GetAttribute("databitenable"); dataManage.serialDic.Add(serialData.name, serialData); } }