예제 #1
0
        private void buttonSaveSettings_Click(object sender, EventArgs e)
        {
            try
            {
                Configure cfg = new Configure();
                cfg.InputSerialPortName = comboBoxSerialPort.Text;
                if (checkBoxExcel.Checked)
                {
                    cfg.bOutputExcel = true;
                }
                else
                {
                    cfg.bOutputExcel = false;
                }

                if (checkBoxLims.Checked)
                {
                    cfg.bOutputLims = true;
                }
                else
                {
                    cfg.bOutputLims = false;
                }

                cfg.InputSerialPortBaud    = comboBoxBaud.Text.ToString();
                cfg.InputSerialPortDataBit = "8 Data Bits";
                cfg.InputSerialPortParity  = "None Parity";
                cfg.InputSerialPortStopBit = "1 Stop Bit";;

                cfg.username     = textBoxUserName.Text.Trim();
                cfg.userpassword = textBoxPassword.Text.Trim();
                cfg.analysis     = textBoxAnalysis.Text.Trim();
                cfg.dev_id       = textBoxDevID.Text.Trim();
                cfg.dev_name     = textBoxDevName.Text.Trim();
                cfg.lab_name     = textBoxLabName.Text.Trim();
                cfg.oil_id       = textBoxOilID.Text.Trim();
                cfg.oil_name     = textBoxOilName.Text.Trim();

                cfg.startAddr   = ushort.Parse(maskedTextBoxStartAddr.Text.Trim());
                cfg.floatFormat = comboBoxFormat.Text.Trim();

                if (radioButtonSerial.Checked)
                {
                    cfg.bSerial_sel = true;
                }
                else
                {
                    cfg.bSerial_sel = false;
                }

                if (radioButtonNetwork.Checked)
                {
                    cfg.bNetwork_sel = true;
                }
                else
                {
                    cfg.bNetwork_sel = false;
                }

                cfg.protocol = comboBoxProtocol.Text.Trim();
                cfg.ipaddr   = textBoxIPAddr.Text.Trim();
                cfg.port     = textBoxPort.Text.Trim();
                string cfgfile = System.IO.Path.Combine(Application.StartupPath, "cfg.json");
                File.WriteAllText(cfgfile, JsonConvert.SerializeObject(cfg));

                //if (false == inputCommPortSingleton.GetInstance().initComm() || false == inputCommPortSingleton.GetInstance().openComm())
                //{
                //    labelWarning.Text = "串口初始化失败";
                //}
                //else
                //{
                stopUpdateRegs();
                if (last_startaddr != cfg.startAddr || last_floatformat != cfg.floatFormat)
                {
                    last_startaddr   = cfg.startAddr;
                    last_floatformat = cfg.floatFormat;

                    RegTextBox.FloatFMT fmt = RegTextBox.FloatFMT.FMT_DCBA;

                    if (last_floatformat == "AB CD")
                    {
                        fmt = RegTextBox.FloatFMT.FMT_ABCD;
                    }
                    else if (last_floatformat == "BA DC")
                    {
                        fmt = RegTextBox.FloatFMT.FMT_BADC;
                    }
                    else if (last_floatformat == "CD AB")
                    {
                        fmt = RegTextBox.FloatFMT.FMT_CDAB;
                    }
                    else
                    {
                        fmt = fmt = RegTextBox.FloatFMT.FMT_DCBA;
                    }

                    lRegTextBox.Clear();

                    modbusRegs.startAddress = last_startaddr;
                    addRegTextBoxControl(ref lRegTextBox, ref modbusRegs, this.Controls, fmt);
                    updateRegAddrLabel(last_startaddr);
                }

                if (input_method == INPUT_METHOD_SERIAL)
                {
                    if (false == inputCommPortSingleton.GetInstance().initComm() || false == inputCommPortSingleton.GetInstance().openComm())
                    {
                        labelWarning.Text = "串口初始化失败";
                    }
                    else
                    {
                        startUpdateRegs();
                    }
                }
                else
                {
                    if (false == modbusNetworkSingleton.GetInstance().initModbusPoll(cfg.ipaddr, int.Parse(cfg.port), cfg.protocol))
                    {
                        labelWarning.Text = "以太网初始化失败";
                    }
                    else
                    {
                        startUpdateRegs();
                    }
                }
                //}
            }
            catch (Exception ex)
            {
                LogClass.GetInstance().WriteExceptionLog(ex);
                //MessageBox.Show(ex.ToString(), "Error - No Ports available", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        public bool createXmlFile(string filename)
        {
            try
            {
                Configure cfg     = null;
                string    cfgfile = System.IO.Path.Combine(Application.StartupPath, "cfg.json");
                if (File.Exists(cfgfile))
                {
                    cfg = JsonConvert.DeserializeObject <Configure>(File.ReadAllText(cfgfile));
                    if (cfg != null)
                    {
                        LimsDoc l;
                        l = new LimsDoc(cfg.username, cfg.userpassword, "system");

                        LimsDocEntity entity       = l.createEntity("SAMPLE", "RESULT_ENTRY");
                        LimsDocEntity entity2      = l.createEntity("TEST", null);
                        LimsDocEntity entity1_time = l.createEntity("RESULT", null);
                        LimsDocEntity entity1_res  = l.createEntity("RESULT", null);
                        LimsDocEntity entity2_time = l.createEntity("RESULT", null);
                        LimsDocEntity entity2_res  = l.createEntity("RESULT", null);
                        LimsDocEntity entity3_time = l.createEntity("RESULT", null);
                        LimsDocEntity entity3_res  = l.createEntity("RESULT", null);
                        LimsDocEntity entity4_time = l.createEntity("RESULT", null);
                        LimsDocEntity entity4_res  = l.createEntity("RESULT", null);

                        entity2.addFields("ANALYSIS", "in", textBoxAnalysis.Text);

                        entity.addFields("ID_NUMERIC", "in", textBoxOilID.Text);

                        if (lcfg == null)
                        {
                            entity1_time.addFields("NAME", "in", "一号弹测试时间");
                            entity1_time.addFields("TEXT", "in", regTextBox1.Text);
                            entity2.addChild(entity1_time.getElement());

                            entity1_res.addFields("NAME", "in", "一号弹最大压力");
                            entity1_res.addFields("TEXT", "in", regTextBox2.Text);
                            entity2.addChild(entity1_res.getElement());

                            entity2_time.addFields("NAME", "in", "二号弹测试时间");
                            entity2_time.addFields("TEXT", "in", regTextBox3.Text);
                            entity2.addChild(entity2_time.getElement());

                            entity2_res.addFields("NAME", "in", "二号弹最大压力");
                            entity2_res.addFields("TEXT", "in", regTextBox4.Text);
                            entity2.addChild(entity2_res.getElement());

                            entity3_time.addFields("NAME", "in", "三号弹测试时间");
                            entity3_time.addFields("TEXT", "in", regTextBox5.Text);
                            entity2.addChild(entity3_time.getElement());

                            entity3_res.addFields("NAME", "in", "三号弹最大压力");
                            entity3_res.addFields("TEXT", "in", regTextBox6.Text);
                            entity2.addChild(entity3_res.getElement());

                            entity4_time.addFields("NAME", "in", "四号弹测试时间");
                            entity4_time.addFields("TEXT", "in", regTextBox7.Text);
                            entity2.addChild(entity4_time.getElement());

                            entity4_res.addFields("NAME", "in", "四号弹最大压力");
                            entity4_res.addFields("TEXT", "in", regTextBox8.Text);
                            entity2.addChild(entity4_res.getElement());
                        }
                        else
                        {
                            entity1_time.addFields("NAME", "in", lcfg.label_1_out);
                            entity1_time.addFields("TEXT", "in", regTextBox1.Text);
                            entity2.addChild(entity1_time.getElement());

                            entity1_res.addFields("NAME", "in", lcfg.label_2_out);
                            entity1_res.addFields("TEXT", "in", regTextBox2.Text);
                            entity2.addChild(entity1_res.getElement());

                            entity2_time.addFields("NAME", "in", lcfg.label_3_out);
                            entity2_time.addFields("TEXT", "in", regTextBox3.Text);
                            entity2.addChild(entity2_time.getElement());

                            entity2_res.addFields("NAME", "in", lcfg.label_4_out);
                            entity2_res.addFields("TEXT", "in", regTextBox4.Text);
                            entity2.addChild(entity2_res.getElement());

                            entity3_time.addFields("NAME", "in", lcfg.label_5_out);
                            entity3_time.addFields("TEXT", "in", regTextBox5.Text);
                            entity2.addChild(entity3_time.getElement());

                            entity3_res.addFields("NAME", "in", lcfg.label_6_out);
                            entity3_res.addFields("TEXT", "in", regTextBox6.Text);
                            entity2.addChild(entity3_res.getElement());

                            entity4_time.addFields("NAME", "in", lcfg.label_7_out);
                            entity4_time.addFields("TEXT", "in", regTextBox7.Text);
                            entity2.addChild(entity4_time.getElement());

                            entity4_res.addFields("NAME", "in", lcfg.label_8_out);
                            entity4_res.addFields("TEXT", "in", regTextBox8.Text);
                            entity2.addChild(entity4_res.getElement());
                        }

                        entity.addChild(entity2.getElement());

                        l.getBody().addEntity(entity.getElement());

                        return(l.createdoc(filename));
                    }
                }
            }
            catch (Exception ex)
            {
                LogClass.GetInstance().WriteExceptionLog(ex);
                //MessageBox.Show(ex.ToString(), "Error - No Ports available", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(false);
        }
예제 #3
0
        private void InitializeSystemSetting()
        {
            try
            {
                load_labcfg();
                Configure cfg     = null;
                string    cfgfile = System.IO.Path.Combine(Application.StartupPath, "cfg.json");
                if (File.Exists(cfgfile))
                {
                    cfg = JsonConvert.DeserializeObject <Configure>(File.ReadAllText(cfgfile));
                }

                string[] portList = System.IO.Ports.SerialPort.GetPortNames();

                for (int i = 0; i < portList.Length; ++i)
                {
                    string name = portList[i];
                    comboBoxSerialPort.Items.Add(name);
                    if (cfg != null && name.ToLower() == cfg.InputSerialPortName.ToLower())
                    {
                        comboBoxSerialPort.SelectedIndex = i;
                    }
                }

                if (cfg == null)
                {
                    return;
                }

                if (cfg.bSerial_sel)
                {
                    radioButtonSerial.Checked = true;
                    input_method = INPUT_METHOD_SERIAL;
                }
                else if (cfg.bNetwork_sel)
                {
                    radioButtonNetwork.Checked = true;
                    input_method = INPUT_METHOD_IP;
                }
                else
                {
                    radioButtonSerial.Checked = true;
                    input_method = INPUT_METHOD_SERIAL;
                }

                if (radioButtonSerial.Checked)
                {
                    comboBoxSerialPort.Enabled = true;
                    comboBoxBaud.Enabled       = true;
                    textBoxIPAddr.Enabled      = false;
                    textBoxPort.Enabled        = false;
                }
                else if (radioButtonNetwork.Checked)
                {
                    comboBoxSerialPort.Enabled = false;
                    comboBoxBaud.Enabled       = false;
                    textBoxIPAddr.Enabled      = true;
                    textBoxPort.Enabled        = true;
                }


                if (inputCommPortSingleton.GetInstance().checkSerialPort(cfg.InputSerialPortName))
                {
                    comboBoxSerialPort.Text = cfg.InputSerialPortName;
                }
                else
                {
                    comboBoxSerialPort.Text = "";
                }

                if (cfg.bOutputExcel)
                {
                    checkBoxExcel.Checked = true;
                }
                else
                {
                    checkBoxExcel.Checked = false;
                }

                if (cfg.bOutputLims)
                {
                    checkBoxLims.Checked = true;
                }
                else
                {
                    checkBoxLims.Checked = false;
                }

                if (comboBoxBaud.Items.Contains(cfg.InputSerialPortBaud))
                {
                    comboBoxBaud.Text = cfg.InputSerialPortBaud;
                }

                textBoxUserName.Text = cfg.username;
                textBoxPassword.Text = cfg.userpassword;
                textBoxAnalysis.Text = cfg.analysis;

                textBoxDevID.Text           = cfg.dev_id;
                textBoxDevName.Text         = cfg.dev_name;
                textBoxLabName.Text         = cfg.lab_name;
                textBoxOilID.Text           = cfg.oil_id;
                textBoxOilName.Text         = cfg.oil_name;
                maskedTextBoxStartAddr.Text = cfg.startAddr.ToString();
                comboBoxFormat.Text         = cfg.floatFormat;
                last_startaddr   = cfg.startAddr;
                last_floatformat = cfg.floatFormat;

                textBoxIPAddr.Text = cfg.ipaddr;
                textBoxPort.Text   = cfg.port;

                if (input_method == INPUT_METHOD_SERIAL)
                {
                    if (false == inputCommPortSingleton.GetInstance().initComm() || false == inputCommPortSingleton.GetInstance().openComm())
                    {
                        labelWarning.Text = "串口初始化失败";
                    }
                    else
                    {
                        startUpdateRegs();
                    }
                }
                else
                {
                    if (false == modbusNetworkSingleton.GetInstance().initModbusPoll(cfg.ipaddr, int.Parse(cfg.port), cfg.protocol))
                    {
                        labelWarning.Text = "以太网初始化失败";
                    }
                    else
                    {
                        startUpdateRegs();
                    }
                }
            }
            catch (Exception ex)
            {
                LogClass.GetInstance().WriteExceptionLog(ex);
                //MessageBox.Show(ex.ToString(), "Error - No Ports available", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }