//public void readxml() //{ // XmlDocument xmlDoc = new XmlDocument(); // xmlDoc.Load("han.xml"); // XmlNodeList nodeList = xmlDoc.SelectSingleNode("han").ChildNodes;//获取bookstore节点的所有子节点 // foreach (XmlNode xn in nodeList)//遍历根节点的所有子节点 // { // XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型 // //if (xe.GetAttribute("lun") == "video1") // //{ // // strvideo1 = xe.InnerText.Trim(); //给视频赋值IP // //} // //if (xe.GetAttribute("lun") == "video2") // //{ // // strvideo2 = xe.InnerText.Trim(); // //} // //if (xe.GetAttribute("lun") == "video3") // //{ // // strvideo3 = xe.InnerText.Trim(); // //} // //if (xe.GetAttribute("lun") == "video4") // //{ // // strvideo4 = xe.InnerText.Trim(); // //} // if (xe.GetAttribute("lun") == "qu") // { // ConnectionManger.G_MineArea = xe.InnerText.Trim(); // } // //if (xe.GetAttribute("lun") == "Com") // //{ // // Com = xe.InnerText.Trim(); // //} // //if (xe.GetAttribute("lun") == "Com") // //{ // // Com = xe.InnerText.Trim(); // //} // } //} private void FrmNew_Load(object sender, EventArgs e) { //readxml(); ConnectionManger.readxml(); string str = "select * from user_table where user_area = '" + ConnectionManger.G_MineArea + "'"; DataTable dt = SQLHelper.GetDataSet(str, CommandType.Text).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { CmbName.Items.Add(dt.Rows[i]["user_name"].ToString()); } dt.Dispose(); if (CmbName.Items.Count > 0) { CmbName.SelectedIndex = 0; } TxtMima.Focus(); TxtMima.Select(); }
private StringBuilder builder = new StringBuilder();//避免在事件处理方法中反复的创建,定义到外面。 private void ParameterSet_Load(object sender, EventArgs e) { ConnectionManger.readxml(); string[] ports = SerialPort.GetPortNames(); Array.Sort(ports); comboBox1.Items.AddRange(ports); model_com.Items.AddRange(ports); yb_Com.Items.AddRange(ports); comboBox1.Text = ConnectionManger.Card_Com; comboBox2.Text = ConnectionManger.Card_Baudrate; txt_video1.Text = ConnectionManger.strvideo1; txt_video2.Text = ConnectionManger.strvideo2; txt_video3.Text = ConnectionManger.strvideo3; txt_video4.Text = ConnectionManger.strvideo4; model_com.Text = ConnectionManger.Model_Com; model_txt.Text = ConnectionManger.Model_Com_Send_Txt; model_baute.SelectedIndex = 0; comboBox3.Text = "1"; yb_Com.Text = ConnectionManger.Yibiao_Com; yb_baute.Text = ConnectionManger.Yibiao_Baute; txt_ledip.Text = ConnectionManger.led_IP; txt_ledwight.Text = ConnectionManger.led_wight.ToString(); txt_ledheight.Text = ConnectionManger.led_height.ToString(); try { comm.BaudRate = int.Parse(ConnectionManger.Card_Baudrate); comm.PortName = ConnectionManger.Card_Com; if (!comm.IsOpen) { comm.Open(); } //添加事件注册 comm.DataReceived += comm_DataReceived; } catch (Exception ex) { } //根据当前串口对象,来判断操作 if (comm_model.IsOpen) { //打开时点击,则关闭串口 comm_model.Close(); } else { try { //关闭时点击,则设置好端口,波特率后打开 comm_model.PortName = ConnectionManger.Model_Com; comm_model.BaudRate = 9600; comm_model.Open(); } catch (Exception ex) { //捕获到异常信息,创建一个新的comm对象,之前的不能用了。 comm_model = new SerialPort(); } //添加事件注册 //comm_model.DataReceived += comm_DataReceived_Model; } }