private void setSpConfigEntity(SpConfigEntity entry) { try { OperateIniFile.WriteIniData("SerialPort", "PortName", entry.PortName, OperateIniFile.getFilePath()); OperateIniFile.WriteIniData("SerialPort", "Baudrate", entry.Baudrate.ToString(), OperateIniFile.getFilePath()); OperateIniFile.WriteIniData("SerialPort", "ParityBit", entry.ParityBit, OperateIniFile.getFilePath()); OperateIniFile.WriteIniData("SerialPort", "DataBit", entry.DataBit.ToString(), OperateIniFile.getFilePath()); OperateIniFile.WriteIniData("SerialPort", "StopBit", entry.StopBit.ToString(), OperateIniFile.getFilePath()); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private SpConfigEntity getSpConfigEntity() { SpConfigEntity entry = new SpConfigEntity(); try { entry.PortName = OperateIniFile.ReadIniData("SerialPort", "PortName", "", OperateIniFile.getFilePath()); entry.Baudrate = Convert.ToInt32(OperateIniFile.ReadIniData("SerialPort", "Baudrate", "9600", OperateIniFile.getFilePath())); entry.ParityBit = OperateIniFile.ReadIniData("SerialPort", "ParityBit", "无", OperateIniFile.getFilePath()); entry.DataBit = Convert.ToInt32(OperateIniFile.ReadIniData("SerialPort", "DataBit", "8", OperateIniFile.getFilePath())); entry.StopBit = Convert.ToInt32(OperateIniFile.ReadIniData("SerialPort", "StopBit", "1", OperateIniFile.getFilePath())); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(entry); }