Exemplo n.º 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < 9; i++)
                {
                    SendData(i);
                    Thread.Sleep(300);
                    string Magnification  = (string)dataGridView1.Rows[i].Cells[3].Value;
                    double Magnification1 = Convert.ToDouble(Magnification);



                    if (dataGridView1.Rows[i].Cells[5].Value.ToString() == "无符号")
                    {
                        var tempchange = temp1 * Magnification1;

                        dataGridView1.Rows[i].Cells[2].Value = tempchange.ToString("00.000");
                        DataHisTextbox.AppendText(tempchange.ToString("00.000") + "  ");
                    }
                    else
                    {
                        var tempchange = temp2 * Magnification1;
                        dataGridView1.Rows[i].Cells[2].Value = tempchange.ToString("00.000");
                        DataHisTextbox.AppendText(tempchange.ToString("00.000") + "  ");
                    }
                }
                DataHisTextbox.AppendText("\n");
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
        //打开串口
        private void button2_Click(object sender, EventArgs e)
        {
            OpenPortButton.Enabled = false;
            label4.ForeColor       = Color.Green;
            serialPort1.BaudRate   = Convert.ToInt32(BaudRateComboBox.Text);
            if (!CloseSerialButton.Enabled)
            {
                CloseSerialButton.Enabled = true;
            }
            try
            {
                serialPort1.PortName = SerialComboBox.Text;
                serialPort1.Open();

                for (int i = 0; i < 9; i++)
                {
                    SendData(i);                                                          //发送第i条报文
                    Thread.Sleep(300);
                    string Magnification  = (string)dataGridView1.Rows[i].Cells[3].Value; //倍率
                    double Magnification1 = Convert.ToDouble(Magnification);
                    if (dataGridView1.Rows[i].Cells[5].Value.ToString() == "无符号")         //检测有无符号
                    {
                        var tempchange = temp1 * Magnification1;                          //返回值乘倍率得到结果
                        dataGridView1.Rows[i].Cells[2].Value = tempchange.ToString("00.000");
                        DataHisTextbox.AppendText(tempchange.ToString("00.000") + "  ");
                    }
                    else
                    {
                        var tempchange = temp2 * Magnification1;
                        dataGridView1.Rows[i].Cells[2].Value = tempchange.ToString("00.000");
                        DataHisTextbox.AppendText(tempchange.ToString("00.000") + "  ");
                    }
                }
                DataHisTextbox.AppendText("\n");
                timer1.Enabled = true;
            }
            catch (Exception)
            {
            }
        }