private void btnOpenClosePort_Click(object sender, EventArgs e) { if (btnOpenClosePort.Text == "打开串口") { if (comm.comOpen(comboPort.Text, int.Parse(comboBPS.Text), false)) { Global.comPort = comboPort.Text; Global.comBPS = int.Parse(comboBPS.Text); XMLUnit.XMLSetValue(Global.xmlPath, "transferdata", "normal", "comport", comboPort.Text); XMLUnit.XMLSetValue(Global.xmlPath, "transferdata", "normal", "combps", comboBPS.Text); setFormStatus(1); showInfo("串口打开成功", false, true); } else { showInfo("串口打开失败", true, false); } } else if (btnOpenClosePort.Text == "关闭串口") { if (comm.comClose()) { setFormStatus(0); showInfo("串口关闭成功", false, true); } else { showInfo("串口关闭失败", true, false); } } }
private void getParamFromXML() { if (!File.Exists(Global.xmlPath)) { showInfo("配置文件不存在", false, false); return; } try { Global.comPort = XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "comport"); Global.comBPS = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "combps")); Global.parity = (Parity)Enum.Parse(typeof(Parity), XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "comparity")); Global.comTimeout = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "comtimeout")); Global.stationAddr = byte.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "stationaddr")); Global.writeCmd = byte.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "writecmd")); Global.readCmd = byte.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "readcmd")); Global.sizeOffset = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "sizeoffset")); Global.planOffset = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "planoffset")); Global.pinOffset = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "pinoffset")); Global.defaultPath = Application.StartupPath + "\\" + XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "defaultfile"); Global.regCount = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "regcount")); Global.bLogOpen = Convert.ToBoolean(int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "logopen"))); Global.timeOut = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "normal", "timeout")); Global.dataCount = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "data", "datacount")); Global.sizeDistance = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "data", "sizedistance")); Global.unit = int.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "data", "unit")); Global.accuracy = double.Parse(XMLUnit.XmlGetValue(Global.xmlPath, "transferdata", "data", "accuracy")); for (int i = 0; i < Global.convFactor.Length; i++) { Global.convFactor[i] = Global.convFactor[i] / Global.accuracy; } showInfo("初始化配置文件成功", false, true); } catch (Exception ex) { showInfo("读取配置文件失败", false, false); return; } Global.procData = new DataFormat[Global.dataCount]; comboPort.Text = Global.comPort; }
private void comboUnit_SelectedIndexChanged(object sender, EventArgs e) { Global.unit = comboUnit.SelectedIndex; XMLUnit.XMLSetValue(Global.xmlPath, "transferdata", "data", "unit", Global.unit.ToString()); }