private void btnSqRead_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < 15; i++)
            {
                TextBox tmpTextBox = this.Controls.Find("txtSq" + i.ToString(), true)[0] as TextBox;
                tmpTextBox.Text = "";
            }
            Functions.Delay(10);

            string      sqStr = null;
            Protocol645 p645  = new Protocol645();

            if (rBtnSq1.Checked)
            {
                p645.ReadData("04010000", out sqStr);
            }
            if (rBtnSq2.Checked)
            {
                p645.ReadData("04020000", out sqStr);
            }
            if (sqStr.Length > 0)
            {
                for (int i = 0; i < sqStr.Length / 6; i++)
                {
                    TextBox tmpTextBox = this.gBSq.Controls.Find("txtSq" + (i + 1).ToString(), true)[0] as TextBox;
                    tmpTextBox.Text = sqStr.Substring(sqStr.Length - (i + 1) * 6, 6);
                }
            }
        }
 private void btnRead_Click(object sender, EventArgs e)
 {
     dataId.Clear();
     dataName.Clear();
     dgvReadData.Rows.Clear();
     foreach (TreeNode n in treeView1.Nodes)
     {
         GetChildNodeValue(n);
     }
     for (int i = 0; i < dataId.Count; i++)
     {
         dgvReadData.Rows.Add();
         dgvReadData[dataid, i].Value   = dataId[i].Substring(2);
         dgvReadData[dataname, i].Value = dataName[i];
         if (!cbIsReadIdOnly.Checked)
         {
             string      result = null;
             Protocol645 p645   = new Protocol645();
             if (p645.ReadData(dataId[i].Substring(2), out result))
             {
                 dgvReadData[datavalue, i].Value = result;
             }
         }
         dgvReadData.Update();
     }
 }
        private void button3_Click(object sender, EventArgs e)//读电量并判断总电量-尖峰平谷的误差
        {
            foreach (Control tb in this.gbEnergy.Controls)
            {
                if (tb is TextBox)
                {
                    tb.Text = "";
                }
            }

            string      result = null;
            Protocol645 p645   = new Protocol645();

            for (int i = 0; i < 5; i++)
            {
                if (p645.ReadData("00000" + i.ToString() + "00", out result))
                {
                    (this.gbEnergy.Controls.Find("tbEnergy" + i.ToString(), true))[0].Text =
                        Convert.ToString(Convert.ToDouble(result) / 100);
                }
            }

            double sum = 0;

            sum            = Convert.ToDouble(tbEnergy1.Text) + Convert.ToDouble(tbEnergy2.Text) + Convert.ToDouble(tbEnergy3.Text) + Convert.ToDouble(tbEnergy4.Text);
            tbEnergy5.Text = Convert.ToString(sum);
            tbEnergy6.Text = ((Convert.ToDouble(tbEnergy0.Text) - sum)).ToString("F4");
        }
Exemple #4
0
        /// <summary>
        /// 读数据
        /// </summary>
        /// <param name="obj"></param>
        private void Read(object obj)
        {
            Ret = string.Empty;
            Protocol645 p645 = new Protocol645();

            p645.ReadData(obj.ToString(), out _ret);
            //Ret = obj.ToString();
        }
Exemple #5
0
        private void btn报警金额2读_Click(object sender, EventArgs e)
        {
            string      ret  = null;
            Protocol645 p645 = new Protocol645();

            if (p645.ReadData("04001002", out ret))
            {
                tbWarr2.Text = ret.Insert(6, ".");
            }
        }
        private void btnSdRead_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < 15; i++)
            {
                TextBox tmpTextBox = this.Controls.Find("txtSd" + i.ToString(), true)[0] as TextBox;
                tmpTextBox.Text = "";
            }
            Functions.Delay(10);

            string      sdStr = null;
            Protocol645 p645  = new Protocol645();

            if (rBtnSd1.Checked)//第一套
            {
                for (int i = 1; i < 9; i++)
                {
                    if ((this.gBSd.Controls.Find("rBtnSd_" + i.ToString(), true)[0] as RadioButton).Checked)
                    {
                        p645.ReadData("0401000" + i.ToString(), out sdStr);
                    }
                }
            }
            if (rBtnSd2.Checked)//第二套
            {
                for (int i = 1; i < 9; i++)
                {
                    if ((this.gBSd.Controls.Find("rBtnSd_" + i.ToString(), true)[0] as RadioButton).Checked)
                    {
                        p645.ReadData("0402000" + i.ToString(), out sdStr);
                    }
                }
            }
            if (sdStr != null)
            {
                for (int i = 0; i < sdStr.Length / 6; i++)
                {
                    TextBox tmpTextBox = this.gBSd.Controls.Find("txtSd" + (i + 1).ToString(), true)[0] as TextBox;
                    tmpTextBox.Text = sdStr.Substring(sdStr.Length - (i + 1) * 6, 6);
                }
            }
        }
Exemple #7
0
        private void btn身份认证_Click(object sender, EventArgs e)
        {
            Protocol645 p645 = new Protocol645();

            Esam645Service.EsamOptionClient ESAMproxy = new Esam645Service.EsamOptionClient();//要操作时才new
            string meterNum = "000000000000";

            if (p645.ReadData("04000402", out meterNum))
            {
                tbDiv.Text = "0000" + meterNum;
            }
            else
            {
                MessageBox.Show("读表号出错!");
            }
            Functions.Delay(100);
            int flag = 0;//公钥为0

            if (rbFlagPri.Checked)
            {
                flag = 1;                   //私钥为1
            }
            try
            {
                tbRand.Text   = ESAMproxy.Meter_Formal_IdentityAuthentication(flag, tbDiv.Text).OutRand;   //取随机数
                tbEndata.Text = ESAMproxy.Meter_Formal_IdentityAuthentication(flag, tbDiv.Text).OutEndata; //取密文
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            Functions.Delay(100);
            string result = null;

            if (p645.SecurityAuthentication("070000FF", tbDiv.Text + tbRand.Text + tbEndata.Text, out result))
            {
                tbEsamNo.Text = result.Substring(0, 16);
                tbRand2.Text  = result.Substring(16);
            }
            else//身份认证经常不成功,试多一次又好了,什么鬼。。。那我就试多一次吧。。。
            if (p645.SecurityAuthentication("070000FF", tbDiv.Text + tbRand.Text + tbEndata.Text, out result))
            {
                tbEsamNo.Text = result.Substring(0, 16);
                tbRand2.Text  = result.Substring(16);
            }
            else
            {
                MessageBox.Show("身份认证失败!");
            }
            ESAMproxy.Close();//每次操作完都要关掉!!!真讨厌,老贺你能不能做成自动关掉的啊。。
        }
        private void btn读显示内容_Click(object sender, EventArgs e)
        {
            int         displayNum = 0;
            string      startId    = null;
            string      display    = null;
            Protocol645 p645       = new Protocol645();

            if (rbDisplayAuto.Checked)
            {
                if (!p645.ReadParameter(tbXunxianNum, "04000301"))
                {
                    return;
                }
                startId    = "040401";
                displayNum = Convert.ToInt16(tbXunxianNum.Text);
            }
            if (rbDisplayButton.Checked)
            {
                if (!p645.ReadParameter(tbJianxianNum, "04000305"))
                {
                    return;
                }
                startId    = "040402";
                displayNum = Convert.ToInt16(tbJianxianNum.Text);
            }

            dgvDisplay.Rows.Clear();
            dgvDisplay.Rows.Add(displayNum);
            //progressBar.Maximum = displayNum;
            //progressBar.Value = 0;
            for (int i = 0; i < displayNum; i++)
            {
                dgvDisplay.Rows[i].HeaderCell.Value = "第" + (i + 1).ToString() + "屏";
                if (p645.ReadData(startId + (i + 1).ToString("X2"), out display))
                {
                    dgvDisplay[0, i].Value = display.Substring(2);
                    dgvDisplay[1, i].Value = display.Substring(0, 2);
                    try
                    {
                        dgvDisplay[2, i].Value = Functions.DISPLAY[display];
                    }
                    catch { }
                    //progressBar.Value++;
                }
                else
                {
                    MessageBox.Show("读表出错!");
                    return;
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// 读上n次事件记录
        /// 输入:事件记录ID前6位【D3D2D1】、第n次记录
        /// 返回:记录数据
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        private string ReadLastNtimesRec(string recID, int n)
        {
            string result    = null;
            string recv      = null;
            int    recID_int = 0x00000000 + Convert.ToInt32(recID.PadRight(8, '0'), 16);

            recID_int += n;
            Protocol645 p645 = new Protocol645();

            if (p645.ReadData(Convert.ToString(recID_int, 16).PadLeft(8, '0'), out recv))
            {
                result += recv;
            }
            recv = null;

            return(result);
        }
        }//读当前运行的时区

        private void btnSdNowRead_Click(object sender, EventArgs e)
        {
            txtSdNow.Text = "";
            Functions.Delay(10);
            string      result = null;
            Protocol645 p645   = new Protocol645();

            if (p645.ReadData("04000503", out result))
            {
                int a = Convert.ToInt16(result, 16) & 0x01;
                if (a == 0x00)
                {
                    txtSdNow.Text = "第1套";
                }
                if (a == 0x01)
                {
                    txtSdNow.Text = "第2套";
                }
            }
        }//读当前运行的时段
Exemple #11
0
        private void btn读认证状态_Click(object sender, EventArgs e)
        {
            string      result = null;
            Protocol645 p645   = new Protocol645();

            if (p645.ReadData("04000503", out result))
            {
                int x = Convert.ToInt32(result, 16);
                if ((x & 0x2000) == 0x2000)
                {
                    tbRenzhengState.Text = "身份认证有效";
                }
                else
                {
                    tbRenzhengState.Text = "身份认证无效";
                }
            }
            else
            {
                MessageBox.Show("读认证状态失败!");
            }
        }
Exemple #12
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            txtContent.Text = string.Empty;

            string id = txtId.Text;

            if (id.Length != 8)
            {
                MessageBox.Show("ID长度错误!");
                return;
            }

            if (!Functions.IsNum(txtTimes.Text))
            {
                MessageBox.Show("次数必须为阿拉伯数字");
                return;
            }
            UInt32 times = UInt32.Parse(txtTimes.Text.Replace(" ", ""));

            string      result = string.Empty;
            Protocol645 p645   = new Protocol645();

            for (UInt32 i = 0; i < times; i++)
            {
                bool re = p645.ReadData(id, out result);
                if (re)
                {
                    txtContent.AppendText(string.Format("第{0}次读取数据:{1}\r\n", (i + 1).ToString().PadLeft(4, '0'), result));
                }
                else
                {
                    txtContent.AppendText(string.Format("第{0}次读取数据:非法报文帧,丢弃。\r\n", (i + 1).ToString().PadLeft(4, '0')));
                }
                Functions.Delay(100);
            }
        }
Exemple #13
0
        /// <summary>
        /// 读参数
        /// </summary>
        /// <param name="tbObj">文本框控件name</param>
        /// <param name="dataId">数据ID</param>
        private bool ReadParameter(object tbObj, string dataId)
        {
            if (!(tbObj is TextBox))
            {
                return(false);
            }

            TextBox tb = (TextBox)tbObj;

            tb.ForeColor = Color.Black;
            tb.Text      = "";
            Method.Delay(10);
            string result = null;

            if (Protocol645.ReadData(dataId, out result))
            {
                tb.Text = result;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #14
0
        private void btn费率读_Click(object sender, EventArgs e)
        {
            string ret    = null;
            string dataID = "040501FF";//当前套费率

            if (rbBeiyongtao.Checked)
            {
                dataID = "040502FF";                      //备用套费率
            }
            Protocol645 p645 = new Protocol645();

            if (p645.ReadData(dataID, out ret))
            {
                int n = ret.Length / 8;
                for (int i = 0; i < 32; i++)
                {
                    this.dgRates[0, i].Value = "";
                }
                for (int i = 0; i < n; i++)
                {
                    this.dgRates[0, i].Value = ret.Substring(ret.Length - 8 * (i + 1), 8).Insert(4, ".");
                }
            }
        }
        private void RidongjieTest()
        {
            this.tBRidongjieRec.Clear();

            bool riFreezeIsOk    = false;
            int  timesOfRiFreeze = Convert.ToInt16(this.tBRidongjieRecTimes.Text);

            string[]    _NtimesRiFreezeOld = new string[timesOfRiFreeze]; //测之前先记录日冻结数据
            string[]    _NtimesRiFreezeNew = new string[timesOfRiFreeze]; //测之后记录日冻结数据,判断新的上2~N次记录是否等于旧的上1~(N-1)次记录
            string      ridongjieDate      = null;
            Protocol645 p645 = new Protocol645();

            p645.ReadData("04001203", out ridongjieDate);
            //****************************读日冻结数据*********************************************
            for (int m = 0; m < timesOfRiFreeze; m++)
            {
                _NtimesRiFreezeOld[m] = ReadLastNtimesRiFreeze(m + 1);
                if (_NtimesRiFreezeOld[m].Length == 138)
                {
                    tBRidongjieRec.AppendText("      上" + (m + 1).ToString("D3") + "次日冻结:" + _NtimesRiFreezeOld[m] + "  读取成功!\r\n");
                }
                else
                {
                    tBRidongjieRec.AppendText("      上" + (m + 1).ToString("D3") + "次日冻结:" + _NtimesRiFreezeOld[m] + "  读取失败!\r\n");
                }
            }
            for (int i = 0; i < int.Parse(tBRidongjieTestTimes.Text); i++)
            {
                //****************************设时间在日冻结时间前5秒*********************************
                string setTime = "000000";
                //日冻结时间有4种可能:00:00、00:XX、XX:00、XX:XX
                if (ridongjieDate == "0000")
                {
                    setTime = "235955";
                }
                else if (ridongjieDate.Substring(0, 2) == "00" && ridongjieDate.Substring(2, 2) != "00")
                {
                    setTime = "00" + (Convert.ToInt16(ridongjieDate.Substring(2, 2)) - 1).ToString("D2") + "55";
                }
                else if (ridongjieDate.Substring(0, 2) != "00" && ridongjieDate.Substring(2, 2) == "00")
                {
                    setTime = (Convert.ToInt16(ridongjieDate.Substring(0, 2)) - 1).ToString("D2") + "5955";
                }
                else if (ridongjieDate.Substring(0, 2) != "00" && ridongjieDate.Substring(2, 2) != "00")
                {
                    setTime = ridongjieDate.Substring(0, 2) + (Convert.ToInt16(ridongjieDate.Substring(2, 2)) - 1).ToString("D2") + "55";
                }

                if (p645.WriteData("04000102", setTime))
                {
                    this.tBRidongjieRec.AppendText((i + 1).ToString("D5") + ":设电表时间:"
                                                   + setTime.Substring(0, 2) + ":" + setTime.Substring(2, 2) + ":" + setTime.Substring(4, 2) + "  设置成功!\r\n");
                }
                else
                {
                    this.tBRidongjieRec.AppendText((i + 1).ToString("D5") + ":设电表时间:设电表时间失败!\r\n");
                }
                //****************************等待时间过日冻结时间************************************
                tBRidongjieRec.AppendText("      等待10秒...\r\n");
                Functions.Delay(10000);//等待10秒
                //****************************读日冻结数据*********************************************
                for (int m = 0; m < timesOfRiFreeze; m++)
                {
                    _NtimesRiFreezeNew[m] = ReadLastNtimesRiFreeze(m + 1);
                    if (_NtimesRiFreezeNew[m].Length == 138)
                    {
                        tBRidongjieRec.AppendText("      上" + (m + 1).ToString("D3") + "次日冻结:" + _NtimesRiFreezeNew[m] + "  读取成功!\r\n");
                    }
                    else
                    {
                        tBRidongjieRec.AppendText("      上" + (m + 1).ToString("D3") + "次日冻结:" + _NtimesRiFreezeNew[m] + "  读取失败!\r\n");
                    }
                }
                //****************************判断新的上1次日冻结时间是否正确***************************
                if (_NtimesRiFreezeNew[0].Substring(6, 4) == ridongjieDate)
                {
                    //****************************判断新的上2~N次记录是否等于旧的上1~(N-1)次记录**************
                    for (int m = 1; m < timesOfRiFreeze; m++)
                    {
                        if (_NtimesRiFreezeNew[m] == _NtimesRiFreezeOld[m - 1])//新的上2~N次等于旧的上1~(N-1)次
                        {
                            riFreezeIsOk = true;
                        }
                        else
                        {
                            riFreezeIsOk = false;
                            break;
                        }
                    }
                    System.Array.Copy(_NtimesRiFreezeNew, _NtimesRiFreezeOld, _NtimesRiFreezeNew.Length);//新的终究要变成旧的,好吧。。。
                }
                else
                {
                    riFreezeIsOk = false;
                }
                if (riFreezeIsOk)
                {
                    this.tBRidongjieRec.AppendText("日冻结记录正确!\r\n");
                }
                else
                {
                    this.tBRidongjieRec.AppendText("日冻结记录失败!\r\n");
                }
            }
            this.tBRidongjieRec.AppendText("日冻结测试结束!");

            //判断测试结果是否合格
            string testRec = this.tBRidongjieRec.Text;

            if (testRec.Contains("失败"))
            {
                this.lblRidongjieResult.Text = "测试结果:不合格";
            }
            else
            {
                this.lblRidongjieResult.Text = "测试结果:合格";
            }

            this.btnRidongjieTest.Text        = "开始测试";
            this.btnRidongjieDataSave.Enabled = true;
        }
        /// <summary>
        /// 结束测试按钮:读电量、时间、电压、电流、功率因数,计算理论值、实际值
        /// </summary>
        private void btnEnergyTestStop_Click(object sender, EventArgs e)
        {
            this.btnEnergyTestStart.Enabled = true;
            this.btnEnergyTestStop.Enabled  = false;
            this.checkBoxZuhe.Enabled       = true;
            this.checkBoxZhengxiang.Enabled = true;
            this.checkBoxFanxiang.Enabled   = true;
            this.radioButtonZ.Enabled       = true;
            this.radioButtonZ_F.Enabled     = true;
            this.radioButtonF.Enabled       = true;
            string      startTestTime = Convert.ToString(this.dataGridViewTestEnergy[6, 0].Value);
            string      stopTestTime  = null;
            Protocol645 p645          = new Protocol645();

            int k = this.dataGridViewTestEnergy.RowCount - 1;

            dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());//加空行
            dataGridViewTestEnergy[6, k].Value = DateTime.Now.ToString("HH:mm:ss");
            stopTestTime = Convert.ToString(dataGridViewTestEnergy[6, k].Value);

            if (checkBoxZuhe.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "结束组合有功电量";
                double[] energy = new double[5];
                for (int i = 0; i < 5; i++)
                {
                    string sEnergy = null;
                    p645.ReadData("00000" + i.ToString() + "00", out sEnergy);
                    dataGridViewTestEnergy[i, k].Value = Functions.RecvDataDeal(sEnergy, 6, 2);
                    energy[i] = Convert.ToDouble(dataGridViewTestEnergy[i, k].Value);
                }
                double wucha = energy[0] - (energy[1] + energy[2] + energy[3] + energy[4]);
                dataGridViewTestEnergy[5, k].Value = wucha.ToString("F2");

                k++;
                Update();
            }
            if (checkBoxZhengxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "结束正向有功电量";
                double[] energy = new double[5];
                for (int i = 0; i < 5; i++)
                {
                    string zEnergy = null;
                    p645.ReadData("00010" + i.ToString() + "00", out zEnergy);
                    dataGridViewTestEnergy[i, k].Value = Functions.RecvDataDeal(zEnergy, 6, 2);
                    energy[i] = Convert.ToDouble(dataGridViewTestEnergy[i, k].Value);
                }
                double wucha = energy[0] - (energy[1] + energy[2] + energy[3] + energy[4]);
                dataGridViewTestEnergy[5, k].Value = wucha.ToString("F2");

                k++;
                Update();
            }
            if (checkBoxFanxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "结束反向有功电量";
                double[] energy = new double[5];
                for (int i = 0; i < 5; i++)
                {
                    string fEnergy = null;
                    p645.ReadData("00020" + i.ToString() + "00", out fEnergy);
                    dataGridViewTestEnergy[i, k].Value = Functions.RecvDataDeal(fEnergy, 6, 2);
                    energy[i] = Convert.ToDouble(dataGridViewTestEnergy[i, k].Value);
                }
                double wucha = energy[0] - (energy[1] + energy[2] + energy[3] + energy[4]);
                dataGridViewTestEnergy[5, k].Value = wucha.ToString("F2");

                k++;
                Update();
            }

            if (radioButtonZ_F.Checked && checkBoxZuhe.Checked && checkBoxZhengxiang.Checked && checkBoxFanxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "组合=正+反(误差)";

                for (int i = 0; i < 5; i++)
                {
                    double energy  = Convert.ToDouble(dataGridViewTestEnergy[i, 0].Value);
                    double energy1 = Convert.ToDouble(dataGridViewTestEnergy[i, 1].Value);
                    double energy2 = Convert.ToDouble(dataGridViewTestEnergy[i, 2].Value);
                    double wucha   = energy - energy1 - energy2;
                    dataGridViewTestEnergy[i, k].Value = wucha.ToString("F2");
                }

                k++;
                Update();
            }
            if (radioButtonZ.Checked && checkBoxZuhe.Checked && checkBoxZhengxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "组合=正(误差)";

                for (int i = 0; i < 5; i++)
                {
                    double energy  = Convert.ToDouble(dataGridViewTestEnergy[i, 0].Value);
                    double energy1 = Convert.ToDouble(dataGridViewTestEnergy[i, 1].Value);
                    double wucha   = energy - energy1;
                    dataGridViewTestEnergy[i, k].Value = wucha.ToString("F2");
                }

                k++;
                Update();
            }
            if (radioButtonF.Checked && checkBoxZuhe.Checked && checkBoxFanxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "组合=反(误差)";

                if (checkBoxZhengxiang.Checked)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        double energy  = Convert.ToDouble(dataGridViewTestEnergy[i, 0].Value);
                        double energy1 = Convert.ToDouble(dataGridViewTestEnergy[i, 2].Value);
                        double wucha   = energy - energy1;
                        dataGridViewTestEnergy[i, k].Value = wucha.ToString("F2");
                    }
                }
                else
                {
                    for (int i = 0; i < 5; i++)
                    {
                        double energy  = Convert.ToDouble(dataGridViewTestEnergy[i, 0].Value);
                        double energy1 = Convert.ToDouble(dataGridViewTestEnergy[i, 1].Value);
                        double wucha   = energy - energy1;
                        dataGridViewTestEnergy[i, k].Value = wucha.ToString("F2");
                    }
                }

                k++;
                Update();
            }

            dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());//加空行
            k++;

            //计算实际走电量、理论走电量
            //理论走电
            dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
            dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "理论走电";
            string A_voltageStr   = null;
            string A_currentStr   = null;
            string powerFactorStr = null;

            p645.ReadData("02010100", out A_voltageStr);
            p645.ReadData("02020100", out A_currentStr);
            p645.ReadData("02060000", out powerFactorStr);
            double A_voltage   = Functions.RecvDataDeal(A_voltageStr, 3, 1);
            double A_current   = Functions.RecvDataDeal(A_currentStr, 3, 3);
            double powerFactor = Functions.RecvDataDeal(powerFactorStr, 1, 3);
            double secondTime  = Functions.CountTimeSpan(startTestTime, stopTestTime);
            double factEnergy  = A_voltage * A_current * powerFactor * secondTime / 1000;

            this.dataGridViewTestEnergy[0, k].Value = factEnergy.ToString("F3");

            k++;
            //实际走电
            int zuheEnergyStartIndex   = 0;
            int zuheEnergyEndIndex     = 0;
            int zhengxEnergyStartIndex = 0;
            int zhengxEnergyEndIndex   = 0;
            int fanxEnergyStartIndex   = 0;
            int fanxEnergyEndIndex     = 0;

            for (int i = 0; i < k; i++)
            {
                if (Convert.ToString(this.dataGridViewTestEnergy.Rows[i].HeaderCell.Value) == "开始组合有功电量")
                {
                    zuheEnergyStartIndex = i;
                }
                if (Convert.ToString(this.dataGridViewTestEnergy.Rows[i].HeaderCell.Value) == "开始正向有功电量")
                {
                    zhengxEnergyStartIndex = i;
                }
                if (Convert.ToString(this.dataGridViewTestEnergy.Rows[i].HeaderCell.Value) == "开始反向有功电量")
                {
                    fanxEnergyStartIndex = i;
                }
                if (Convert.ToString(this.dataGridViewTestEnergy.Rows[i].HeaderCell.Value) == "结束组合有功电量")
                {
                    zuheEnergyEndIndex = i;
                }
                if (Convert.ToString(this.dataGridViewTestEnergy.Rows[i].HeaderCell.Value) == "结束正向有功电量")
                {
                    zhengxEnergyEndIndex = i;
                }
                if (Convert.ToString(this.dataGridViewTestEnergy.Rows[i].HeaderCell.Value) == "结束反向有功电量")
                {
                    fanxEnergyEndIndex = i;
                }
            }
            if (checkBoxZuhe.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "实际组合走电";
                for (int i = 0; i < 5; i++)
                {
                    dataGridViewTestEnergy[i, k].Value = Convert.ToDouble(dataGridViewTestEnergy[i, zuheEnergyEndIndex].Value)
                                                         - Convert.ToDouble(dataGridViewTestEnergy[i, zuheEnergyStartIndex].Value);
                }
                k++;
            }
            if (checkBoxZhengxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "实际正向走电";
                for (int i = 0; i < 5; i++)
                {
                    dataGridViewTestEnergy[i, k].Value = Convert.ToDouble(dataGridViewTestEnergy[i, zhengxEnergyEndIndex].Value)
                                                         - Convert.ToDouble(dataGridViewTestEnergy[i, zhengxEnergyStartIndex].Value);
                }
                k++;
            }
            if (checkBoxFanxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "实际反向走电";
                for (int i = 0; i < 5; i++)
                {
                    dataGridViewTestEnergy[i, k].Value = Convert.ToDouble(dataGridViewTestEnergy[i, fanxEnergyEndIndex].Value)
                                                         - Convert.ToDouble(dataGridViewTestEnergy[i, fanxEnergyStartIndex].Value);
                }
                k++;
            }
        }
        /// <summary>
        /// 开始测试按钮:读电量、时间
        /// </summary>
        private void btnEnergyTestStart_Click(object sender, EventArgs e)
        {
            this.btnEnergyTestStart.Enabled = false;
            this.btnEnergyTestStop.Enabled  = true;
            this.checkBoxZuhe.Enabled       = false;
            this.checkBoxZhengxiang.Enabled = false;
            this.checkBoxFanxiang.Enabled   = false;
            this.radioButtonZ.Enabled       = false;
            this.radioButtonZ_F.Enabled     = false;
            this.radioButtonF.Enabled       = false;
            dataGridViewTestEnergy.Rows.Clear();
            Protocol645 p645 = new Protocol645();

            int k = 0;

            dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());//加空行
            dataGridViewTestEnergy[6, k].Value = DateTime.Now.ToString("HH:mm:ss");
            if (checkBoxZuhe.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "开始组合有功电量";

                string   sEnergy = null;
                double[] energy  = new double[5];
                for (int i = 0; i < 5; i++)
                {
                    p645.ReadData("00000" + i.ToString() + "00", out sEnergy);//00000000、00000100、00000200、00000300、00000400
                    dataGridViewTestEnergy[i, k].Value = Functions.RecvDataDeal(sEnergy, 6, 2);
                    energy[i] = Convert.ToDouble(dataGridViewTestEnergy[i, k].Value);
                }

                double wucha = energy[0] - (energy[1] + energy[2] + energy[3] + energy[4]);
                dataGridViewTestEnergy[5, k].Value = wucha.ToString("F2");
                k++;
                Update();
            }
            if (checkBoxZhengxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "开始正向有功电量";

                string   zEnergy = null;
                double[] energy  = new double[5];
                for (int i = 0; i < 5; i++)
                {
                    p645.ReadData("00010" + i.ToString() + "00", out zEnergy);//00010000、00010100、00010200、00010300、00010400
                    dataGridViewTestEnergy[i, k].Value = Functions.RecvDataDeal(zEnergy, 6, 2);
                    energy[i] = Convert.ToDouble(dataGridViewTestEnergy[i, k].Value);
                }

                double wucha = energy[0] - (energy[1] + energy[2] + energy[3] + energy[4]);
                dataGridViewTestEnergy[5, k].Value = wucha.ToString("F2");
                k++;
                Update();
            }
            if (checkBoxFanxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "开始反向有功电量";

                string   fEnergy = null;
                double[] energy  = new double[5];
                for (int i = 0; i < 5; i++)
                {
                    p645.ReadData("00020" + i.ToString() + "00", out fEnergy);//00020000、00020100、00020200、00020300、00020400
                    dataGridViewTestEnergy[i, k].Value = Functions.RecvDataDeal(fEnergy, 6, 2);
                    energy[i] = Convert.ToDouble(dataGridViewTestEnergy[i, k].Value);
                }

                double wucha = energy[0] - (energy[1] + energy[2] + energy[3] + energy[4]);
                dataGridViewTestEnergy[5, k].Value = wucha.ToString("F2");
                k++;
                Update();
            }

            if (radioButtonZ_F.Checked && checkBoxZuhe.Checked && checkBoxZhengxiang.Checked && checkBoxFanxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "组合=正+反(误差)";

                for (int i = 0; i < 5; i++)
                {
                    double energy  = Convert.ToDouble(dataGridViewTestEnergy[i, 0].Value);
                    double energy1 = Convert.ToDouble(dataGridViewTestEnergy[i, 1].Value);
                    double energy2 = Convert.ToDouble(dataGridViewTestEnergy[i, 2].Value);
                    double wucha   = energy - energy1 - energy2;
                    dataGridViewTestEnergy[i, k].Value = wucha.ToString("F2");
                }
                k++;
                Update();
            }
            if (radioButtonZ.Checked && checkBoxZuhe.Checked && checkBoxZhengxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "组合=正(误差)";

                for (int i = 0; i < 5; i++)
                {
                    double energy  = Convert.ToDouble(dataGridViewTestEnergy[i, 0].Value);
                    double energy1 = Convert.ToDouble(dataGridViewTestEnergy[i, 1].Value);
                    double wucha   = energy - energy1;
                    dataGridViewTestEnergy[i, k].Value = wucha.ToString("F2");
                }
                k++;
                Update();
            }
            if (radioButtonF.Checked && checkBoxZuhe.Checked && checkBoxFanxiang.Checked)
            {
                dataGridViewTestEnergy.Rows.Add(new DataGridViewRow());
                dataGridViewTestEnergy.Rows[k].HeaderCell.Value = "组合=反(误差)";

                if (checkBoxZhengxiang.Checked)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        double energy  = Convert.ToDouble(dataGridViewTestEnergy[i, 0].Value);
                        double energy1 = Convert.ToDouble(dataGridViewTestEnergy[i, 2].Value);
                        double wucha   = energy - energy1;
                        dataGridViewTestEnergy[i, k].Value = wucha.ToString("F2");
                    }
                }
                else
                {
                    for (int i = 0; i < 5; i++)
                    {
                        double energy  = Convert.ToDouble(dataGridViewTestEnergy[i, 0].Value);
                        double energy1 = Convert.ToDouble(dataGridViewTestEnergy[i, 1].Value);
                        double wucha   = energy - energy1;
                        dataGridViewTestEnergy[i, k].Value = wucha.ToString("F2");
                    }
                }
                k++;
                Update();
            }
        }
Exemple #18
0
        public void SetTimeEventTest()
        {
            txtBoxTimeSetEvent.Clear();
            Protocol645 p645 = new Protocol645();

            //校时记录清零
            txtBoxTimeSetEvent.AppendText("校时记录清零。。。");
            if (p645.EventClear("033004"))
            {
                txtBoxTimeSetEvent.AppendText("  成功!\r\n");
            }
            else
            {
                txtBoxTimeSetEvent.AppendText("  失败!\r\n");
            }

            //校时记录测试
            Functions.Delay(100);//等待清零动作完成
            bool setTimeEventIsOk = false;

            string[] _10timesSetTimeEvent = new string[10];//将10次校时记录写进一个数组,以便比较
            for (int m = 0; m < 10; m++)
            {
                _10timesSetTimeEvent[m] = ReadLastNtimesRec("033004", m + 1);
                if (_10timesSetTimeEvent[m] == "00000000000000000000000000000000")//判断是否已经清零
                {
                    setTimeEventIsOk = true;
                }
                else
                {
                    setTimeEventIsOk = false;
                    break;
                }
            }
            if (setTimeEventIsOk)
            {
                for (int i = 0; i < int.Parse(textBoxTestTimes.Text); i++)
                {
                    //********************随机设时间*********************************
                    string setTime = Functions.GenerateRandomTime();
                    if (p645.WriteData("04000102", setTime))
                    {
                        txtBoxTimeSetEvent.AppendText((i + 1).ToString("D5") + ":随机设电表时间:"
                                                      + setTime.Substring(0, 2) + ":" + setTime.Substring(2, 2) + ":" + setTime.Substring(4, 2) + "..........................成功!\r\n");
                    }
                    else
                    {
                        txtBoxTimeSetEvent.AppendText((i + 1).ToString("D5") + ":设电表时间:设电表时间失败!\r\n");
                    }
                    //********************读校时记录总次数,检查是否记录正确*********************************
                    Functions.Delay(50);
                    string timesOfSetTime = null;
                    if (p645.ReadData("03300400", out timesOfSetTime))
                    {
                        txtBoxTimeSetEvent.AppendText("      读校时次数:" + timesOfSetTime.Substring(0, 6));
                        if (timesOfSetTime == (i + 1).ToString("D6"))
                        {
                            txtBoxTimeSetEvent.AppendText("      校时次数符合实际设的次数,成功!\r\n");
                        }
                        else
                        {
                            txtBoxTimeSetEvent.AppendText("      校时次数不符合实际设的次数,失败!\r\n");
                        }
                    }
                    else//如果失败就读多一次
                    if (p645.ReadData("03300400", out timesOfSetTime))
                    {
                        txtBoxTimeSetEvent.AppendText("      读校时次数:" + timesOfSetTime.Substring(0, 6));
                        if (timesOfSetTime == (i + 1).ToString("D6"))
                        {
                            txtBoxTimeSetEvent.AppendText("      校时次数符合实际设的次数,成功!\r\n");
                        }
                        else
                        {
                            txtBoxTimeSetEvent.AppendText("      校时次数不符合实际设的次数,失败!\r\n");
                        }
                    }
                    else
                    {
                        txtBoxTimeSetEvent.AppendText("      读校时次数失败!\r\n");
                    }
                    //********************读上10次校时记录,检查是否记录正确*********************************
                    //读10次记录
                    for (int j = 0; j < 10; j++)
                    {
                        if (ReadLastNtimesRec("033004", j + 1) != null)
                        {
                            txtBoxTimeSetEvent.AppendText("      上" + (j + 1).ToString("D2") + "次校时记录:"
                                                          + ReadLastNtimesRec("033004", j + 1) + "  成功!\r\n");
                        }
                        else
                        {
                            txtBoxTimeSetEvent.AppendText("      上" + (j + 1).ToString("D2") + "次校时记录:读上"
                                                          + (j + 1).ToString() + "次校时记录失败!\r\n");
                        }
                    }
                    //判断10次记录
                    //this.txtBoxTimeSetEvent.AppendText("      判断10次校时事件是否正确记录(判断上1次事件记录的校时后时间是否为所设时间、判断10次记录是否轮换正确)。。。\r\n");
                    string[] _10timesSetTimeEventTemp = new string[10];
                    for (int m = 0; m < 10; m++)
                    {
                        _10timesSetTimeEventTemp[m] = ReadLastNtimesRec("033004", m + 1);
                    }
                    if (ReadLastNtimesRec("033004", 1) != null && ReadLastNtimesRec("033004", 1).Substring(6, 6) == setTime)//判断第一次是否等于所设时间
                    {
                        for (int m = 1; m < 10; m++)
                        {
                            if (_10timesSetTimeEventTemp[m] == _10timesSetTimeEvent[m - 1])//新的上2~10次等于旧的上1~9次
                            {
                                setTimeEventIsOk = true;
                            }
                            else
                            {
                                setTimeEventIsOk = false;
                                break;
                            }
                        }
                        //_10timesSetTimeEvent = _10timesSetTimeEventTemp;
                        System.Array.Copy(_10timesSetTimeEventTemp, _10timesSetTimeEvent, _10timesSetTimeEvent.Length);//新的写入旧的,以便下次比较
                    }
                    else
                    {
                        setTimeEventIsOk = false;
                    }
                    if (setTimeEventIsOk)
                    {
                        txtBoxTimeSetEvent.AppendText("      10次校时事件记录正确!\r\n");
                    }
                    else
                    {
                        txtBoxTimeSetEvent.AppendText("      10次校时事件记录失败!\r\n");
                    }
                }
            }
            else
            {
                txtBoxTimeSetEvent.AppendText("10校时记录不为空,请检查是否清空!失败!\r\n");
            }
            txtBoxTimeSetEvent.AppendText("\r\n校时记录自动测试结束!\r\n");

            //判断测试结果是否合格
            string testRec = txtBoxTimeSetEvent.Text;

            if (testRec.Contains("失败"))
            {
                labelSetTimeEventTestResult.Text = "测试结果:不合格";
            }
            else
            {
                labelSetTimeEventTestResult.Text = "测试结果:合格";
            }

            btnTimeSetEventTest.Text = "开始测试";
            btnDataSave.Enabled      = true;
        }