zoukankan      html  css  js  c++  java
  • STC-单片机控制系统

    电源测量命令

    60V开 FD020600010101000000
    60V关 FD020600020101000000
    60V保开
    60V保关

    -8KV开
    -8KV关 FD020928020102010000
    -0-2000 FD0209180001020126dc
    -2-4000 FD020910000102011b4f
    -4-8000 FD020911000102011473

    +8KV开 FD020918010001010000
    +8KV关 FD020918020101010000
    +0-2000 FD0209180001010114cd
    +2-4000 FD020910000101013116
    +4-8000 FD020911000101012fca

    -16KV开 FD020B00010100020000
    -16KV关 FD020B00020100020000
    -0-8K
    -8-130K
    -1-160K

    模拟设置
    FD0103180001010100005C46AA //U14 - 聚焦电源一组 第一段
    FD010310000101010000D586AA //U14 - 聚焦电源一组 第二段
    FD010311000101010000C546AA //U14 - 聚焦电源一组 第三段

    FD0103280001010100006C45AA //U13 - 聚焦电源二组 第一段
    FD010320000101010000E585AA //U13 - 聚焦电源二组 第二段
    FD010321000101010000F545AA //U13 - 聚焦电源二组 第三段

    FD010418000101010000A01DAA //U14 - 预聚焦电源一组 第一段
    FD0104100001010100006094AA //U14 - 预聚焦电源一组 第二段
    FD01041100010101000084A0AA //U14 - 预聚焦电源一组 第三段

    FD0104280001010100002DA3AA //U13 - 预聚焦电源二组 第一段
    FD010420000101010000A463AA //U13 - 预聚焦电源二组 第二段
    FD010421000101010000B4A3AA //U13 - 预聚焦电源二组 第三段

    FD0104380001010100003C62AA //U13 - 预聚焦电源三组 第一段
    FD010430000101010000B5A2AA //U13 - 预聚焦电源三组 第二段
    FD010431000101010000A562AA //U13 - 预聚焦电源三组 第三段


    数字量查询
    FD010210000401010000D84AAA //U14 - 引出极 电压
    FD010210000401020000284AAA //U14 - 引出极 电流

    FD0103180004010100009046AA //U14 - 聚焦电源一组 电压
    FD0103180004010200006046AA //U14 - 聚焦电源一组 电流
    FD010328000401010000A045AA //U13 - 聚焦电源二组 电压
    FD0103280004010200005045AA //U13 - 聚焦电源二组 电流

    FD010418000401010000D1A0AA //U14 - 预聚焦电源一组 电压
    FD01041800040102000021A0AA //U14 - 预聚焦电源一组 电流
    FD010428000401010000E1A3AA //U13 - 预聚焦电源二组 电压
    FD01042800040102000011A3AA //U13 - 预聚焦电源二组 电流
    FD010438000401010000F062AA //U13 - 预聚焦电源三组 电压
    FD0104380004010200000062AA //U13 - 预聚焦电源三组 电流

    FD01051000040101000099ACAA //U14 - 脉冲输出电源 5KV 电压
    FD01051000040102000069ACAA //U14 - 脉冲输出电源 5KV 电流

    FD010610000401010000D9B9AA //U13- 60V整流电源 电压
    FD01061000040102000029B9AA //U13 - 60V整流电源 电流

    FD0108100004010100005835AA //U13 - 热丝电源 10V 电压
    FD010810000401020000A835AA //U13 - 热丝电源 10V 电流


    开关控制


    FD010110010401010000998EAA //U13 - 抑制极+1KV电源开
    FD01011002040102000069BDAA //U13 - 抑制极+1KV电源关
    FD01011001040201000099CAAA //U13 - 抑制极-1KV电源开
    FD01011002040202000069F9AA //U13 - 抑制极-1KV电源关

    FD010210010401010000D99BAA //LPC - 引出极+5KV电源开
    FD01021002040102000029A8AA //LPC - 引出极+5KV电源关

    FD0103180104010100009197AA //U14 - 聚焦电源一组 开
    FD01031802040102000061A4AA //U14 - 聚焦电源一组 关
    FD010328010401010000A194AA //U13 - 聚焦电源二组 开
    FD01032802040102000051A7AA //U13 - 聚焦电源二组 关


    FD010418010401010000D071AA //U14 - 预聚焦电源一组 开
    FD0104180204010200002042AA //U14 - 预聚焦电源一组 关
    FD010428010401010000E072AA //U13 - 预聚焦电源二组 开
    FD0104280204010200001041AA //U13 - 预聚焦电源二组 关
    FD010438010401010000F1B3AA //U13 - 预聚焦电源三组 开
    FD0104380204010200000180AA //U13 - 预聚焦电源三组 关

    FD010510010401010000987DAA //U14 - 脉冲输出电源 5KV 开
    FD010510020401020000684EAA //U14 - 脉冲输出电源 5KV 关

    FD010610010401010000D868AA //U13- 60V整流电源 开 由控制箱控制
    FD010610020401020000285BAA //U13 - 60V整流电源 关

    FD01081001040101000059E4AA //U13 - 热丝电源 10V 开
    FD010810020401020000A9D7AA //U13 - 热丝电源 10V 关


    电流电压显示
    FD010118000201010000999FAA //U14 - 抑制极+1KV电源电压显示
    FD01011800020202000069DBAA //U13 - 抑制极-1KV电源电流显示
    FD01011800020201000099DBAA //U13 - 抑制极-1KV电源过压显示

    FD010218000201010000D98AAA //U14 - 引出极 +5KV电压
    FD010218000201020000298AAA //U14 - 引出极 +5KV电流

    FD0103180002010100001846AA //U14 - 聚焦电源一组 电压
    FD010318000201020000E846AA //U14 - 聚焦电源一组 电流
    FD0103280002010100002845AA //U13 - 聚焦电源二组 电压
    FD010328000201020000D845AA //U13 - 聚焦电源二组 电流

    FD01041800020101000059A0AA //U14 - 预聚焦电源一组 电压
    FD010418000201020000A9A0AA //U14 - 预聚焦电源一组 电流
    FD01042800020101000069A3AA //U13 - 预聚焦电源二组 电压
    FD01042800020102000099A3AA //U13 - 预聚焦电源二组 电流
    FD0104380002010100007862AA //U13 - 预聚焦电源三组 电压
    FD0104380002010200008862AA //U13 - 预聚焦电源三组 电流

    FD01051000020101000011ACAA //U14 - 脉冲输出电源 5KV 电压
    FD010510000201020000E1ACAA //U14 - 脉冲输出电源 5KV 电流

    FD01061000020101000051B9AA //U13- 60V整流电源 电压
    FD010610000201020000A1B9AA //U13 - 60V整流电源 电流

    FD010810000201010000D035AA //U13 - 热丝电源 10V 电压
    FD0108100002010200002035AA //U13 - 热丝电源 10V 电流

     使用到的串口调试工具

    1.CRC_16校验程序(好!不分大小写)

    2.STC_ISP_V480.exe

    3.串口调试工具SSCOM32.exe

    4.电源协议E.doc

    5.技术文件67.doc

    注意:此处技术文件为保密文件,此处就不提供出来了,还请谅解。

    不闲扯,直接替源码,如下所示:

      1 using System;
      2 using System.Drawing;
      3 using System.IO.Ports;
      4 using System.Threading;
      5 using System.Windows.Forms;
      6 
      7 namespace CDCurrentControl.UI
      8 {
      9     public class BaseForm : Form
     10     {
     11         protected readonly string redPath = Application.StartupPath + @"Images红色.png";
     12         protected readonly string greenPath = Application.StartupPath + @"Images绿色.png";
     13         protected readonly string whitePath = Application.StartupPath + @"Images白色.png";
     14         protected readonly SerialPort sp = new SerialPort();
     15 
     16         #region 发送协议
     17         /// <summary>
     18         /// 发送协议
     19         /// </summary>
     20         /// <param name="str"></param>
     21         public void SendAgreement(string str)
     22         {
     23             if (sp.IsOpen)
     24             {
     25                 //TxtAllAgreement.Text += str;
     26                 Byte[] sendstrs = BLL.ZhuanHuan.GetByte(str);
     27                 sp.Write(sendstrs, 0, sendstrs.Length);
     28                 Thread.Sleep(500);
     29             }
     30         }
     31 
     32         #endregion
     33 
     34         /// <summary>
     35         /// 清除所有文本框的值
     36         /// </summary>
     37         protected void ClearAllTextBox()
     38         {
     39             foreach (Control c in Controls)
     40             {
     41                 if (c is TextBox)
     42                 {
     43                     c.Text = string.Empty;
     44                 }
     45             }
     46         }
     47 
     48         /// <summary>
     49         /// 输入验证
     50         /// </summary>
     51         /// <param name="tb"></param>
     52         /// <param name="min"></param>
     53         /// <param name="max"></param>
     54         /// <returns></returns>
     55         public bool ValidateString(TextBox tb, double min, double max)
     56         {
     57             try
     58             {
     59                 double zhi = Convert.ToDouble(tb.Text.Trim());
     60                 if (zhi < min || zhi > max)
     61                 {
     62                     MessageBox.Show("请输入" + min + "-" + max + "之间的电压");
     63                     return false;
     64                 }
     65                 return true;
     66             }
     67             catch
     68             {
     69                 MessageBox.Show("请输入正确的数字");
     70                 return false;
     71             }
     72         }
     73 
     74         public void SetPicGreen(PictureBox image)
     75         {
     76             image.Image = Image.FromFile(greenPath);
     77         }
     78 
     79         public void SetPicRed(PictureBox image)
     80         {
     81             image.Image = Image.FromFile(redPath);
     82         }
     83 
     84         public void SetPicWhite(PictureBox image)
     85         {
     86             image.Image = Image.FromFile(whitePath);
     87         }
     88 
     89         public void ClearText(TextBox t1, TextBox t2, TextBox t3, TextBox t4, TextBox t5)
     90         {
     91             while (true)
     92             {
     93                 Thread.Sleep(2000);
     94                 if (t1.Text == "" && t2.Text == "" && t3.Text == "" && t4.Text == "" && t5.Text == "")
     95                 {
     96                     break;
     97                 }
     98                 t1.Text = "";
     99                 t2.Text = "";
    100                 t3.Text = "";
    101                 t4.Text = "";
    102                 t5.Text = "";
    103             }
    104 
    105         }
    106         public void ClearText(TextBox t1, TextBox t2, TextBox t3, TextBox t4)
    107         {
    108 
    109             while (true)
    110             {
    111                 Thread.Sleep(2000);
    112                 if (t1.Text == "" && t2.Text == "" && t3.Text == "" && t4.Text == "")
    113                 {
    114                     break;
    115                 }
    116                 t1.Text = "";
    117                 t2.Text = "";
    118                 t3.Text = "";
    119                 t4.Text = "";
    120             }
    121 
    122         }
    123     }
    124 }
    BaseForm
      1 using System;
      2 using System.Drawing;
      3 using System.Windows.Forms;
      4 
      5 namespace CDCurrentControl.UI
      6 {
      7     public partial class frmMain : BaseForm
      8     {
      9         readonly RFD_Form rfd = new RFD_Form();
     10         readonly CFS_Form cfs = new CFS_Form();
     11         readonly CeS_Form csf = new CeS_Form();
     12         readonly Point p = new Point();
     13         int count = 0;
     14         protected override CreateParams CreateParams
     15         {
     16             get
     17             {
     18                 CreateParams cp = base.CreateParams;
     19                 cp.ExStyle |= 0x02000000;
     20                 return cp;
     21             }
     22         }
     23         public frmMain()
     24         {
     25 
     26             p.X = 0;
     27             p.Y = 0;
     28             InitializeComponent();
     29 
     30 
     31 
     32         }
     33         /// <summary>
     34         /// 热发电d
     35         /// </summary>
     36         /// <param name="sender"></param>
     37         /// <param name="e"></param>
     38         private void lblRFD_Click(object sender, EventArgs e)
     39         {
     40             cfs.Hide();
     41             csf.Hide();
     42             rfd.MdiParent = this;
     43             rfd.Show();
     44             rfd.Location = p;
     45 
     46             lblRFD.ImageIndex = 0;
     47             lblCFD.ImageIndex = 1;
     48             lblCS.ImageIndex = 1;
     49         }
     50         /// <summary>
     51         /// 场发射
     52         /// </summary>
     53         /// <param name="sender"></param>
     54         /// <param name="e"></param>
     55         private void lblCFD_Click(object sender, EventArgs e)
     56         {
     57             rfd.Hide();
     58             csf.Hide();
     59             cfs.MdiParent = this;
     60             cfs.Show();
     61             cfs.Location = p;
     62 
     63             lblRFD.ImageIndex = 1;
     64             lblCFD.ImageIndex = 0;
     65             lblCS.ImageIndex = 1;
     66         }
     67 
     68         /// <summary>
     69         /// 测试
     70         /// </summary>
     71         /// <param name="sender"></param>
     72         /// <param name="e"></param>
     73         private void lblCS_Click(object sender, EventArgs e)
     74         {
     75             if (count == 1)
     76             {
     77                 rfd.Hide();
     78                 cfs.Hide();
     79                 csf.MdiParent = this;
     80                 csf.Show();
     81                 csf.Location = p;
     82 
     83                 lblRFD.ImageIndex = 1;
     84                 lblCFD.ImageIndex = 1;
     85                 lblCS.ImageIndex = 0;
     86             }
     87             else
     88             {
     89                 frmLogin fl = new frmLogin();
     90                 if (fl.ShowDialog() == DialogResult.OK)
     91                 {
     92                     TextBox tb = fl.Controls["txtName"] as TextBox;
     93                     if (tb.Text == "正确")
     94                     {
     95                         rfd.Hide();
     96                         cfs.Hide();
     97                         csf.MdiParent = this;
     98                         csf.Show();
     99                         csf.Location = p;
    100 
    101                         count = 1;
    102                         lblRFD.ImageIndex = 1;
    103                         lblCFD.ImageIndex = 1;
    104                         lblCS.ImageIndex = 0;
    105                     }
    106                     else
    107                     {
    108                         lblCS_Click(sender, e);
    109 
    110                     }
    111                 }
    112             }
    113 
    114         }
    115 
    116         private void frmMain_Resize(object sender, EventArgs e)
    117         {
    118             int kuan = Width - 15;
    119             int gao = Height - panel1.Height - 32;
    120 
    121             cfs.Width = kuan;
    122             cfs.Height = gao;
    123             rfd.Width = kuan;
    124             rfd.Height = gao;
    125             csf.Width = kuan;
    126             csf.Height = gao;
    127         }
    128 
    129         private void label1_Click(object sender, EventArgs e)
    130         {
    131             frmSJJY fs = new frmSJJY();
    132             fs.Show();
    133         }
    134 
    135         private void frmMain_Load(object sender, EventArgs e)
    136         {
    137             new BLL.SJJY().NewJiaZai();
    138         }
    139     }
    140 }
    frmMain
       1 using System;
       2 using System.Collections.Generic;
       3 using System.ComponentModel;
       4 using System.Data;
       5 using System.Drawing;
       6 using System.Linq;
       7 using System.Text;
       8 using System.Windows.Forms;
       9 using System.IO.Ports;
      10 using ZedGraph;
      11 using System.Threading;
      12 using CDCurrentControl.Model;
      13 
      14 namespace CDCurrentControl.UI {
      15     public partial class RFD_Form : Form {
      16         frmClose fc = new frmClose();
      17         List<Thread> ltr = new List<Thread>();//线程
      18         bool ZF = true;
      19         string gy = "10";
      20         string zgy = "18";//主高压初始片选
      21         string pza = "18";//偏转正初始片选
      22         string pzb = "18";//偏转负初始片选
      23         string jja = "18";//聚集极一初始片选
      24         string jjb = "28";//聚集极二初始片选
      25         string yjja = "18";//预聚集极一初始片选
      26         string yjjb = "28";//预聚集极二初始片选
      27         string yjc = "38";//预聚集极三初始片选
      28         double jjbs = 0;//聚集二设置前的值
      29         double jjas = 0;//聚集一设置前的值
      30         double yjjas = 0;//预聚集一设置前的值
      31         double yjjbs = 0;//预聚集二设置前的值
      32         double yjjcs = 0;//预聚集三设置前的值
      33         double pzas = 0;//偏转正设置前的值
      34         double pzbs = 0;//偏转负设置前的值
      35         double zgys = 10000;//主高压设置前的值
      36         double rss = 0;
      37         int count = 0;
      38         System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();//热丝电源等待时间加引出极
      39         List<Dictionary<int, CheckBox>> cbos = new List<Dictionary<int, CheckBox>>();//check按钮
      40         List<Button> btns = new List<Button>();//button按钮
      41         SerialPort sp = new SerialPort();
      42         PointPairList listzgy = new PointPairList();
      43         LineItem myCurvezgy;
      44         PointPairList listyzj = new PointPairList();
      45         LineItem myCurveyzj;
      46         PointPairList listycj = new PointPairList();
      47         LineItem myCurveycj;
      48         PointPairList listjja = new PointPairList();
      49         LineItem myCurvejja;
      50         PointPairList listjjb = new PointPairList();
      51         LineItem myCurvejjb;
      52         PointPairList listyjja = new PointPairList();
      53         LineItem myCurveyjja;
      54         PointPairList listyjjb = new PointPairList();
      55         LineItem myCurveyjjb;
      56         PointPairList listyjjc = new PointPairList();
      57         LineItem myCurveyjjc;
      58         PointPairList listymc = new PointPairList();
      59         LineItem myCurveymc;
      60         PointPairList listzl = new PointPairList();
      61         LineItem myCurvezl;
      62         PointPairList listrs = new PointPairList();
      63         LineItem myCurvers;
      64         PointPairList listpza = new PointPairList();
      65         LineItem myCurvepza;
      66         PointPairList listpzb = new PointPairList();
      67         LineItem myCurvepzb;
      68         bool b = false;
      69         List<byte[]> js = new List<byte[]>();
      70         List<List<string>> ss = new List<List<string>>();
      71         readonly string whitePath = Application.StartupPath + @"Images白色.png";
      72         readonly string redPath = Application.StartupPath + @"Images红色.png";
      73         readonly string greenPath = Application.StartupPath + @"Images绿色.png";
      74         public RFD_Form() {
      75             InitializeComponent();
      76             zedGraph zg = new zedGraph();
      77             zg.JiaZai(this.zgcZGYDY, "主高压电源");
      78             zg.JiaZai(this.zgcYZJDY, "抑制极电源");
      79             zg.JiaZai(this.zgcYCJDY, "引出极电源");
      80             zg.JiaZai(this.zgcJJDYA, "聚焦电源一");
      81             zg.JiaZai(this.zgcJJDYB, "聚焦电源二");
      82             zg.JiaZai(this.zgcYJJDYA, "预聚焦电源一");
      83             zg.JiaZai(this.zgcYJJDYB, "预聚焦电源二");
      84             zg.JiaZai(this.zgcYJJDYC, "预聚焦电源三");
      85             zg.JiaZai(this.zgcZLDY, "60V整流电源");
      86             zg.JiaZai(this.zgcRSDY, "热丝电源");
      87             zg.JiaZai(this.zgcMCSCDYA, "脉冲电源");
      88             zg.JiaZai(this.zgcPZDYA, "偏转电源一");
      89             zg.JiaZai(this.zgcPZDYB, "偏转电源二");
      90             CheckBox[] cbo = new CheckBox[] { cboZGY, cboYZJ, cboYCJ, cboJJA, cboJJB, cboYJJA, cboYJJB, cboYJJC, cboMC, cboZL, cboRS, cboPZ };
      91             Button[] b = new Button[] { button11, button1, button2, button36, button41, button5, button23, button29, button8, button9, button10, button4 };
      92             btns.AddRange(b);
      93             for (int i = 0 ; i < 12 ; i++) {
      94                 Dictionary<int, CheckBox> c = new Dictionary<int, CheckBox>();
      95                 c.Add(i, cbo[i]);
      96                 cbos.Add(c);
      97             }
      98 
      99         }
     100         //重复读取数据
     101         void NewXianCheng() {
     102             do {
     103 
     104                 if (sp.IsOpen) {
     105 
     106                     if (count > 0) {
     107                         #region MyRegion
     108                         // 整流
     109                         if (this.button9.Text == "断电") {
     110                             string gy = "FD010610000401010000";
     111                             string gl = "FD010610000401020000";
     112                             chuansong(gy);
     113                             shuchu(xianshi());
     114                             chuansong(gl);
     115                             shuchu(xianshi());
     116                             string str = "FD010618000201010000";
     117                             chuansong(str);
     118                             shuchu(xianshi());
     119                             string strs = "FD010618000201020000";
     120                             chuansong(strs);
     121                             shuchu(xianshi());
     122 
     123                         }
     124                         //抑制极
     125                         if (this.button1.Text == "断电") {
     126                             string str = "";
     127                             string strs = "";
     128                             string gl = "";
     129                             string gy = "";
     130 
     131                             //
     132                             if (ZF) {
     133 
     134                                 str = "FD010118000201010000";
     135                                 strs = "FD010118000201020000";
     136                                 gy = "FD010110000401010000";
     137                                 chuansong(gy);
     138                                 shuchu(xianshi());
     139 
     140                             }
     141                                 //
     142                             else {
     143 
     144                                 str = "FD010118000202010000";
     145                                 strs = "FD010118000202020000";
     146                                 gl = "FD010110000402020000";
     147                                 chuansong(gl);
     148                                 shuchu(xianshi());
     149 
     150 
     151 
     152                             }
     153                             chuansong(strs);
     154                             shuchu(xianshi());
     155                             chuansong(str);
     156                             shuchu(xianshi());
     157 
     158 
     159                         }
     160                         //脉冲A
     161                         if (button8.Text == "断电") {
     162                             string gy = "FD010510000401010000";
     163                             string gl = "FD010510000401020000";
     164                             chuansong(gy);
     165                             shuchu(xianshi());
     166                             chuansong(gl);
     167                             shuchu(xianshi());
     168                             string str = "FD010510000201010000";
     169                             string strs = "FD010510000201020000";
     170                             chuansong(str);
     171                             shuchu(xianshi());
     172                             chuansong(strs);
     173                             shuchu(xianshi());
     174 
     175                         }
     176                         //聚焦一
     177                         if (button36.Text == "断电") {
     178                             string gy = "FD0103" + jja + "000401010000";
     179                             string gl = "FD0103" + jja + "000401020000";
     180                             chuansong(gy);
     181                             shuchu(xianshi());
     182                             chuansong(gl);
     183                             shuchu(xianshi());
     184                             string str = "FD0103" + jja + "000201010000";
     185                             string strs = "FD0103" + jja + "000201020000";
     186                             chuansong(str);
     187                             shuchu(xianshi());
     188                             chuansong(strs);
     189                             shuchu(xianshi());
     190 
     191                         }
     192                         //聚焦二
     193                         if (button41.Text == "断电") {
     194                             string gy = "FD0103" + jjb + "000401010000";
     195                             string gl = "FD0103" + jjb + "000401020000";
     196                             chuansong(gy);
     197                             shuchu(xianshi());
     198                             chuansong(gl);
     199                             shuchu(xianshi());
     200                             string str = "FD0103" + jjb + "000201010000";
     201                             string strs = "FD0103" + jjb + "000201020000";
     202                             chuansong(str);
     203                             shuchu(xianshi());
     204 
     205                             chuansong(strs);
     206                             shuchu(xianshi());
     207 
     208                         }
     209                         //预聚焦一
     210                         if (button5.Text == "断电") {
     211                             string gy = "FD0104" + yjja + "000401010000";
     212                             string gl = "FD0104" + yjja + "000401020000";
     213                             chuansong(gy);
     214                             shuchu(xianshi());
     215                             chuansong(gl);
     216                             shuchu(xianshi());
     217                             string str = "FD0104" + yjja + "000201010000";
     218                             string strs = "FD0104" + yjja + "000201020000";
     219                             chuansong(str);
     220                             shuchu(xianshi());
     221 
     222                             chuansong(strs);
     223                             shuchu(xianshi());
     224 
     225                         }
     226                         //预聚焦二
     227                         if (button23.Text == "断电") {
     228                             string gy = "FD0104" + yjjb + "000401010000";
     229                             string gl = "FD0104" + yjjb + "000401020000";
     230                             chuansong(gy);
     231                             shuchu(xianshi());
     232                             chuansong(gl);
     233                             shuchu(xianshi());
     234                             string str = "FD0104" + yjjb + "000201010000";
     235                             string strs = "FD0104" + yjjb + "000201020000";
     236                             chuansong(str);
     237                             shuchu(xianshi());
     238                             chuansong(strs);
     239                             shuchu(xianshi());
     240 
     241                         }
     242                         //预聚焦三
     243                         if (button29.Text == "断电") {
     244                             string gy = "FD0104" + yjc + "000401010000";
     245                             string gl = "FD0104" + yjc + "000401020000";
     246                             chuansong(gy);
     247                             shuchu(xianshi());
     248                             chuansong(gl);
     249                             shuchu(xianshi());
     250                             string str = "FD0104" + yjc + "000201010000";
     251                             string strs = "FD0104" + yjc + "000201020000";
     252                             chuansong(str);
     253                             shuchu(xianshi());
     254                             chuansong(strs);
     255                             shuchu(xianshi());
     256                         }
     257                         //主高压
     258                         if (button11.Text == "断电") {
     259                             string gl = "FD020B" + zgy + "000401020000";
     260                             chuansong(gl);
     261                             shuchu(xianshi());
     262                             string gy = "FD020B" + zgy + "000401010000";
     263                             chuansong(gy);
     264                             shuchu(xianshi());
     265                             string str = "FD020B" + zgy + "000201010000";
     266                             string strs = "FD020B" + zgy + "000201020000";
     267                             chuansong(str);
     268                             shuchu(xianshi());
     269                             chuansong(strs);
     270                             shuchu(xianshi());
     271                         }
     272                         //偏转正
     273                         if (this.button4.Text == "断电") {
     274                             string gl = "FD0209" + pza + "000401020000";
     275                             chuansong(gl);
     276                             shuchu(xianshi());
     277                             string gy = "FD0209" + pza + "000401010000";
     278                             chuansong(gy);
     279                             shuchu(xianshi());
     280                             string str2 = "FD0209" + pza + "000201010000";
     281                             chuansong(str2);
     282                             shuchu(xianshi());
     283                             string strs = "FD0209" + pza + "000201020000";
     284                             chuansong(strs);
     285                             shuchu(xianshi());
     286                             string gl2 = "FD0209" + pzb + "000402020000";
     287                             chuansong(gl2);
     288                             shuchu(xianshi());
     289                             string gy2 = "FD0209" + pzb + "000402010000";
     290                             chuansong(gy2);
     291                             shuchu(xianshi());
     292                             string str = "FD0209" + pzb + "000202010000";
     293                             string strs2 = "FD0209" + pzb + "000202020000";
     294                             chuansong(str);
     295                             shuchu(xianshi());
     296                             chuansong(strs2);
     297                             shuchu(xianshi());
     298                         }
     299                         //引出极
     300                         if (this.button2.Text == "断电") {
     301                             string gl = "FD010210000401020000";
     302                             chuansong(gl);
     303                             shuchu(xianshi());
     304                             string gy = "FD010210000401010000";
     305                             chuansong(gy);
     306                             shuchu(xianshi());
     307                             string str = "FD010218000201010000";
     308                             chuansong(str);
     309                             shuchu(xianshi());
     310                             string strs = "FD010218000201020000";
     311                             chuansong(strs);
     312                             shuchu(xianshi());
     313 
     314                         }
     315 
     316                         //热丝
     317                         if (this.button10.Text == "断电") {
     318                             string gy = "FD010810000401010000";
     319                             string gl = "FD010810000401020000";
     320                             chuansong(gy);
     321                             shuchu(xianshi());
     322                             chuansong(gl);
     323                             shuchu(xianshi());
     324                             string str = "FD010818000201010000";
     325                             chuansong(str);
     326                             shuchu(xianshi());
     327                             string strs = "FD010818000201020000";
     328                             chuansong(strs);
     329                             shuchu(xianshi());
     330                         }
     331                         #endregion
     332                     } else {
     333                         Thread.Sleep(1000);
     334                     }
     335                 } else {
     336                     Thread.Sleep(1000);
     337                 }
     338             } while (true);
     339 
     340         }
     341         //接受协议
     342         public byte[] xianshi() {
     343             try {
     344 
     345                 bool bGet = false;
     346                 byte[] received = new byte[13];
     347                 int nTimeout = 0;
     348                 if (sp.BytesToRead > 0) {
     349                     do {
     350 
     351                         int zhi = sp.ReadByte();
     352                         received[nTimeout] = Convert.ToByte(zhi);
     353 
     354 
     355                         if (received[nTimeout].ToString().IndexOf("170") >= 0)//这个地方要换成你的结束符
     356                         {
     357                             bGet = true;
     358                         }
     359 
     360                         nTimeout++;
     361 
     362                         if (nTimeout > 100) {
     363                             bGet = true;
     364                         }
     365                         Thread.Sleep(1);
     366                     }
     367                     while (!bGet);
     368                     sp.DiscardOutBuffer();
     369                     sp.DiscardInBuffer();
     370                     return received;
     371                 } else {
     372                     return null;
     373                 }
     374 
     375             } catch {
     376                 return null;
     377             }
     378         }
     379         //发送协议
     380         public void chuansong(string str) {
     381 
     382             if (sp.IsOpen == true) {
     383                 Byte[] sendstrs = BLL.ZhuanHuan.GetByte(str);
     384                 sp.Write(sendstrs, 0, sendstrs.Length);
     385                 Thread.Sleep(600);
     386             }
     387 
     388         }
     389         //过流过压图片显示
     390         public void GLGY(PictureBox pbR, PictureBox pbG, string jiu, string qi) {
     391             //过压
     392             if (qi == "01") {
     393 
     394                 if (jiu == "01") {
     395 
     396                     //  Closes();
     397                     pbR.Image = Image.FromFile(redPath);
     398                 } else if (jiu == "00") {
     399                     pbG.Image = Image.FromFile(greenPath);
     400                     pbR.Image = Image.FromFile(whitePath);
     401                 }
     402             }
     403                 //过流
     404             else if (qi == "02") {
     405                 if (jiu == "01") {
     406 
     407                     //   Closes();
     408                     pbR.Image = Image.FromFile(redPath);
     409                 } else if (jiu == "00") {
     410                     pbG.Image = Image.FromFile(greenPath);
     411                     pbR.Image = Image.FromFile(whitePath);
     412                 }
     413             }
     414         }
     415         //输出显示
     416         public void shuchu(byte[] buf) {
     417             if (buf != null) {
     418                 if (buf.Count() > 0) {
     419                     string[] bufd = BLL.ZhuanHuan.ByteToByteString(buf);
     420                     #region 算法
     421                     switch (bufd[2]) {
     422                         //抑制极电源
     423                         #region 抑制极
     424                         case "01": {
     425                                 //设置与开关
     426                                 if (bufd[4] == "00") {
     427                                     //查询电压电流
     428                                     if (bufd[5] == "03") {
     429                                         //
     430                                         if (bufd[6] == "01") {
     431                                             //电压
     432                                             if (bufd[7] == "01") {
     433                                                 this.txtYZJDYS.Text = BLL.YiZhiJi.YZJSZ(bufd[8] + bufd[9]).ToString();
     434                                                 double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     435                                                 shuaxin(jieguo, this.zgcYZJDY, listyzj, myCurveyzj);
     436                                             }
     437                                                 //电流
     438                                             else if (bufd[7] == "02") {
     439                                                 double zhi = BLL.YiZhiJi.DLJSZ(bufd[8] + bufd[9]);
     440                                                 if (zhi > BLL.Model.YZJZ.SCDLG * (1 + 0.1)) {
     441                                                     //发送过流保护信号
     442                                                     this.pbxYZJDYR.Image = Image.FromFile(redPath);
     443                                                     Closes();
     444                                                 }
     445                                                 this.txtYZJDL.Text = BLL.YiZhiJi.DLJSZ(bufd[8] + bufd[9]).ToString();
     446                                                 double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     447                                             }
     448 
     449                                         }
     450                                             //
     451                                         else if (bufd[6] == "02") {
     452                                             //电压
     453                                             if (bufd[7] == "01") {
     454 
     455                                                 this.txtYZJDYS.Text = BLL.YiZhiJi.YZJSF(bufd[8] + bufd[9]).ToString();
     456                                                 double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     457                                                 shuaxin(jieguo, this.zgcYZJDY, listyzj, myCurveyzj);
     458                                             }
     459                                                 //电流
     460                                             else if (bufd[7] == "02") {
     461 
     462                                                 this.txtYZJDL.Text = BLL.YiZhiJi.YZJSZDL(bufd[8] + bufd[9]).ToString();
     463                                                 double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     464 
     465                                             }
     466                                         }
     467                                     }
     468                                         //过流过压
     469                                     else if (bufd[5] == "04") {
     470                                         //
     471                                         if (bufd[6] == "01") {
     472                                             GLGY(this.pbxYZJDYR, pbxYZJDYG, bufd[9], bufd[7]);
     473                                         }
     474                                             //
     475                                         else if (bufd[6] == "02") {
     476                                             GLGY(this.pbxYZJDYR, pbxYZJDYG, bufd[9], bufd[7]);
     477                                         }
     478                                     }
     479                                 }
     480                                 break;
     481                             }
     482                         #endregion
     483                         //引出极电源
     484                         #region 引出极
     485                         case "02": {
     486                                 //设置
     487                                 if (bufd[4] == "00") {
     488                                     //查询电流电压
     489                                     if (bufd[5] == "03") {
     490                                         //电压
     491                                         if (bufd[7] == "01") {
     492 
     493                                             this.txtYCJDYS.Text = BLL.YinChuJi.YCJSZ(bufd[8] + bufd[9]).ToString();
     494                                             double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     495                                             shuaxin(jieguo, this.zgcYCJDY, listycj, myCurveycj);
     496                                         }
     497                                             //电流
     498                                         else if (bufd[7] == "02") {
     499 
     500                                             this.txtYCJDL.Text = BLL.YinChuJi.YCJSZDL(bufd[8] + bufd[9]).ToString();
     501                                             double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     502                                         }
     503 
     504 
     505                                     }
     506                                         //过流过压
     507                                     else if (bufd[5] == "04") {
     508                                         GLGY(this.pbxYCJDYR, this.pbxYCJDYG, bufd[9], bufd[7]);
     509 
     510                                     }
     511                                 }
     512                                 break;
     513                             }
     514                         #endregion
     515                         //聚焦电源
     516                         #region 聚焦
     517                         case "03": {
     518                                 //
     519                                 switch (bufd[3]) {
     520                                     case "18": {
     521                                             if (bufd[5] == "03") {
     522 
     523                                                 if (bufd[7] == "01") {
     524 
     525                                                     this.txtJJDYAS.Text = BLL.JuJiJi.JJJAASZ(bufd[8] + bufd[9]).ToString();
     526                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     527                                                     shuaxin(jieguo, this.zgcJJDYA, listjja, myCurvejja);
     528                                                 } else if (bufd[7] == "02") {
     529 
     530                                                     this.txtJJDLA.Text = BLL.JuJiJi.JJJAASZDL(bufd[8] + bufd[9]).ToString();
     531                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     532                                                 }
     533 
     534 
     535                                             }
     536                                                 //过流过压
     537                                             else if (bufd[5] == "04") {
     538                                                 GLGY(this.pbxJJDYAR, pbxJJDYAG, bufd[9], bufd[7]);
     539                                             }
     540 
     541 
     542                                             break;
     543                                         }
     544                                     //
     545                                     case "10": {
     546                                             if (bufd[5] == "03") {
     547                                                 if (bufd[7] == "01") {
     548 
     549                                                     this.txtJJDYAS.Text = BLL.JuJiJi.JJJABSZ(bufd[8] + bufd[9]).ToString();
     550                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     551                                                     shuaxin(jieguo, this.zgcJJDYA, listjja, myCurvejja);
     552 
     553                                                 } else if (bufd[7] == "02") {
     554 
     555                                                     this.txtJJDLA.Text = BLL.JuJiJi.JJJABSZDL(bufd[8] + bufd[9]).ToString();
     556                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     557                                                 }
     558                                             }
     559                                                 //过流过压
     560                                             else if (bufd[5] == "04") {
     561                                                 GLGY(this.pbxJJDYAR, pbxJJDYAG, bufd[9], bufd[7]);
     562                                             }
     563 
     564                                             break;
     565                                         }
     566                                     case "11": {
     567                                             //
     568                                             if (bufd[5] == "03") {
     569                                                 //因为要访问ui资源,所以需要使用invoke方式同步ui。
     570                                                 if (bufd[7] == "01") {
     571                                                     this.txtJJDYAS.Text = BLL.JuJiJi.JJJACSZ(bufd[8] + bufd[9]).ToString();
     572                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     573                                                     shuaxin(jieguo, this.zgcJJDYA, listjja, myCurvejja);
     574                                                 } else if (bufd[7] == "02") {
     575 
     576                                                     this.txtJJDLA.Text = BLL.JuJiJi.JJJACSZDL(bufd[8] + bufd[9]).ToString();
     577                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     578                                                 }
     579                                             }
     580                                                 //过流过压
     581                                             else if (bufd[5] == "04") {
     582                                                 GLGY(this.pbxJJDYAR, pbxJJDYAG, bufd[9], bufd[7]);
     583                                             }
     584 
     585                                             break;
     586                                         }
     587                                     //
     588                                     case "28": {
     589 
     590                                             if (bufd[5] == "03") {
     591                                                 if (bufd[7] == "01") {
     592                                                     this.txtJJDYBS.Text = BLL.JuJiJi.JJJBASZ(bufd[8] + bufd[9]).ToString();
     593                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     594                                                     shuaxin(jieguo, this.zgcJJDYB, listjjb, myCurvejjb);
     595                                                 } else if (bufd[7] == "02") {
     596 
     597                                                     this.txtJJDLB.Text = BLL.JuJiJi.JJJBASZDL(bufd[8] + bufd[9]).ToString();
     598                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     599                                                 }
     600                                             }
     601                                                 //过流过压
     602                                             else if (bufd[5] == "04") {
     603                                                 GLGY(this.pbxJJDYBR, pbxJJDYBG, bufd[9], bufd[7]);
     604                                             }
     605                                             break;
     606                                         }
     607                                     //
     608                                     case "20": {
     609 
     610                                             if (bufd[5] == "03") {
     611                                                 if (bufd[7] == "01") {
     612                                                     this.txtJJDYBS.Text = BLL.JuJiJi.JJJBBSZ(bufd[8] + bufd[9]).ToString();
     613                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     614                                                     shuaxin(jieguo, this.zgcJJDYB, listjjb, myCurvejjb);
     615                                                 } else if (bufd[7] == "02") {
     616                                                     this.txtJJDLB.Text = BLL.JuJiJi.JJJBBSZDL(bufd[8] + bufd[9]).ToString();
     617                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     618                                                 }
     619                                             }
     620                                                 //过流过压
     621                                             else if (bufd[5] == "04") {
     622                                                 GLGY(this.pbxJJDYBR, pbxJJDYBG, bufd[9], bufd[7]);
     623                                             }
     624                                             break;
     625                                         }
     626                                     //
     627                                     case "21": {
     628 
     629                                             if (bufd[5] == "03") {
     630                                                 //因为要访问ui资源,所以需要使用invoke方式同步ui。
     631                                                 if (bufd[7] == "01") {
     632                                                     this.txtJJDYBS.Text = BLL.JuJiJi.JJJBCSZ(bufd[8] + bufd[9]).ToString();
     633                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     634                                                     shuaxin(jieguo, this.zgcJJDYB, listjjb, myCurvejjb);
     635                                                 } else if (bufd[7] == "02") {
     636                                                     this.txtJJDLB.Text = BLL.JuJiJi.JJJBCSZDL(bufd[8] + bufd[9]).ToString();
     637                                                     double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     638                                                 }
     639                                             }
     640                                                 //过流过压
     641                                             else if (bufd[5] == "04") {
     642                                                 GLGY(this.pbxJJDYBR, pbxJJDYBG, bufd[9], bufd[7]);
     643                                             }
     644                                             break;
     645                                         }
     646                                 }
     647                                 break;
     648                             }
     649                         #endregion
     650                         //预聚焦电源
     651                         #region 预聚焦
     652                         case "04": {
     653                                 {
     654                                     //
     655                                     switch (bufd[3]) {
     656                                         case "18": {
     657                                                 if (bufd[5] == "03") {
     658                                                     if (bufd[7] == "01") {
     659                                                         this.txtYJJDYAS.Text = BLL.YuJuJiJi.YJJJAASZ(bufd[8] + bufd[9]).ToString();
     660                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     661                                                         shuaxin(jieguo, this.zgcYJJDYA, listyjja, myCurveyjja);
     662                                                     } else if (bufd[7] == "02") {
     663                                                         this.txtYJJDLA.Text = BLL.YuJuJiJi.YJJJAASZDL(bufd[8] + bufd[9]).ToString();
     664                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     665                                                     }
     666                                                 }
     667                                                     //过流过压
     668                                                 else if (bufd[5] == "04") {
     669                                                     GLGY(this.pbxYJJDYAGR, pbxYJJDYAG, bufd[9], bufd[7]);
     670                                                 }
     671                                                 break;
     672                                             }
     673                                         //
     674                                         case "10": {
     675                                                 if (bufd[5] == "03") {
     676                                                     if (bufd[7] == "01") {
     677                                                         this.txtYJJDYAS.Text = BLL.YuJuJiJi.YJJJABSZ(bufd[8] + bufd[9]).ToString();
     678                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     679                                                         shuaxin(jieguo, this.zgcYJJDYA, listyjja, myCurveyjja);
     680                                                     } else if (bufd[7] == "02") {
     681                                                         this.txtYJJDLA.Text = BLL.YuJuJiJi.YJJJABSZDL(bufd[8] + bufd[9]).ToString();
     682                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     683                                                     }
     684                                                 }
     685                                                     //过流过压
     686                                                 else if (bufd[5] == "04") {
     687                                                     GLGY(this.pbxYJJDYBR, pbxYJJDYAG, bufd[9], bufd[7]);
     688                                                 }
     689                                                 break;
     690                                             }
     691                                         case "11": {
     692                                                 //
     693                                                 if (bufd[5] == "03") {
     694                                                     if (bufd[7] == "01") {
     695                                                         this.txtYJJDYAS.Text = BLL.YuJuJiJi.YJJJACSZ(bufd[8] + bufd[9]).ToString();
     696                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     697                                                         shuaxin(jieguo, this.zgcYJJDYA, listyjja, myCurveyjja);
     698                                                     } else if (bufd[7] == "02") {
     699                                                         this.txtYJJDLA.Text = BLL.YuJuJiJi.YJJJACSZDL(bufd[8] + bufd[9]).ToString();
     700                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     701                                                     }
     702                                                 }
     703                                                     //过流过压
     704                                                 else if (bufd[5] == "04") {
     705                                                     GLGY(this.pbxYJJDYCR, pbxYJJDYAG, bufd[9], bufd[7]);
     706                                                 }
     707                                                 break;
     708                                             }
     709                                         //
     710                                         case "28": {
     711                                                 if (bufd[5] == "03") {
     712                                                     if (bufd[7] == "01") {
     713                                                         this.txtYJJDYBS.Text = BLL.YuJuJiJi.YJJJBASZ(bufd[8] + bufd[9]).ToString();
     714                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     715                                                         shuaxin(jieguo, this.zgcYJJDYB, listyjjb, myCurveyjjb);
     716                                                     } else if (bufd[7] == "02") {
     717                                                         this.txtYJJDLB.Text = BLL.YuJuJiJi.YJJJBASZDL(bufd[8] + bufd[9]).ToString();
     718                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     719                                                     }
     720 
     721                                                 }
     722                                                     //过流过压
     723                                                 else if (bufd[5] == "04") {
     724                                                     GLGY(this.pbxYJJDYBR, pbxYJJDYBG, bufd[9], bufd[7]);
     725                                                 }
     726                                                 break;
     727                                             }
     728                                         //
     729                                         case "20": {
     730                                                 if (bufd[5] == "03") {
     731                                                     if (bufd[7] == "01") {
     732                                                         this.txtYJJDYBS.Text = BLL.YuJuJiJi.YJJJBBSZ(bufd[8] + bufd[9]).ToString();
     733                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     734                                                         shuaxin(jieguo, this.zgcYJJDYB, listyjjb, myCurveyjjb);
     735                                                     } else if (bufd[7] == "02") {
     736                                                         this.txtYJJDLB.Text = BLL.YuJuJiJi.YJJJBBSZDL(bufd[8] + bufd[9]).ToString();
     737                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     738                                                     }
     739                                                 }
     740                                                     //过流过压
     741                                                 else if (bufd[5] == "04") {
     742                                                     GLGY(this.pbxYJJDYBR, pbxYJJDYBG, bufd[9], bufd[7]);
     743                                                 }
     744                                                 break;
     745                                             }
     746                                         //
     747                                         case "21": {
     748                                                 if (bufd[5] == "03") {
     749                                                     if (bufd[7] == "01") {
     750                                                         this.txtYJJDYBS.Text = BLL.YuJuJiJi.YJJJBCSZ(bufd[8] + bufd[9]).ToString();
     751                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     752                                                         shuaxin(jieguo, this.zgcYJJDYB, listyjjb, myCurveyjjb);
     753                                                     } else if (bufd[7] == "02") {
     754                                                         this.txtYJJDLB.Text = BLL.YuJuJiJi.YJJJBCSZDL(bufd[8] + bufd[9]).ToString();
     755                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     756                                                     }
     757                                                 }
     758                                                     //过流过压
     759                                                 else if (bufd[5] == "04") {
     760                                                     GLGY(this.pbxYJJDYBR, pbxYJJDYBG, bufd[9], bufd[7]);
     761                                                 }
     762                                                 break;
     763                                             }
     764                                         //
     765                                         case "38": {
     766                                                 if (bufd[5] == "03") {
     767                                                     if (bufd[7] == "01") {
     768                                                         this.txtYJJDYCS.Text = BLL.YuJuJiJi.YJJJCASZ(bufd[8] + bufd[9]).ToString();
     769                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     770                                                         shuaxin(jieguo, this.zgcYJJDYC, listyjjc, myCurveyjjc);
     771                                                     } else if (bufd[7] == "02") {
     772                                                         this.txtYJJDLC.Text = BLL.YuJuJiJi.YJJJCASZDL(bufd[8] + bufd[9]).ToString();
     773                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     774                                                     }
     775                                                 }
     776                                                     //过流过压
     777                                                 else if (bufd[5] == "04") {
     778                                                     GLGY(this.pbxYJJDYCR, pbxYJJDYCG, bufd[9], bufd[7]);
     779                                                 }
     780                                                 break;
     781                                             }
     782                                         //
     783                                         case "30": {
     784                                                 if (bufd[5] == "03") {
     785                                                     if (bufd[7] == "01") {
     786                                                         this.txtYJJDYCS.Text = BLL.YuJuJiJi.YJJJCBSZ(bufd[8] + bufd[9]).ToString();
     787                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     788                                                         shuaxin(jieguo, this.zgcYJJDYC, listyjjc, myCurveyjjc);
     789                                                     } else if (bufd[7] == "02") {
     790                                                         this.txtYJJDLC.Text = BLL.YuJuJiJi.YJJJCBSZDL(bufd[8] + bufd[9]).ToString();
     791                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     792                                                     }
     793                                                 }
     794                                                     //过流过压
     795                                                 else if (bufd[5] == "04") {
     796                                                     GLGY(this.pbxYJJDYCR, pbxYJJDYCG, bufd[9], bufd[7]);
     797                                                 }
     798                                                 break;
     799                                             }
     800                                         //
     801                                         case "31": {
     802                                                 if (bufd[5] == "03") {
     803                                                     if (bufd[7] == "01") {
     804                                                         this.txtYJJDYCS.Text = BLL.YuJuJiJi.YJJJCCSZ(bufd[8] + bufd[9]).ToString();
     805                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     806                                                         shuaxin(jieguo, this.zgcYJJDYC, listyjjc, myCurveyjjc);
     807                                                     } else if (bufd[7] == "02") {
     808                                                         this.txtYJJDLC.Text = BLL.YuJuJiJi.YJJJCCSZDL(bufd[8] + bufd[9]).ToString();
     809                                                         double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     810                                                     }
     811                                                 }
     812                                                     //过流过压
     813                                                 else if (bufd[5] == "04") {
     814                                                     GLGY(this.pbxYJJDYCR, pbxYJJDYCG, bufd[9], bufd[7]);
     815                                                 }
     816                                                 break;
     817                                             }
     818                                     }
     819                                     break;
     820                                 }
     821                             }
     822                         #endregion
     823                         //脉冲输出电源
     824                         #region 脉冲输出
     825                         case "05": {
     826                                 if (bufd[4] == "00") {
     827                                     if (bufd[5] == "03") {
     828                                         if (bufd[7] == "01") {
     829                                             this.txtMCSCDYS.Text = BLL.TiaoZhiJi.TZJSZ(bufd[8] + bufd[9]).ToString();
     830                                             double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     831                                             shuaxin(jieguo, this.zgcMCSCDYA, listymc, myCurveymc);
     832                                         } else if (bufd[7] == "02") {
     833                                             this.txtMCSCDL.Text = BLL.TiaoZhiJi.TZJSZDL(bufd[8] + bufd[9]).ToString();
     834                                             double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     835                                         }
     836                                     }
     837                                         //过流过压
     838                                     else if (bufd[5] == "04") {
     839                                         GLGY(this.pbxMCSCDYR, pbxMCSCDYG, bufd[9], bufd[7]);
     840                                     }
     841                                 }
     842                                 break;
     843                             }
     844                         #endregion
     845                         //60V整流电源
     846                         #region 60V整流
     847                         case "06": {
     848                                 if (bufd[4] == "00") {
     849                                     if (bufd[5] == "03") {
     850                                         if (bufd[6] == "01") {
     851                                             if (bufd[7] == "01") {
     852                                                 this.txtZLDYS.Text = BLL._60V.VSZ(bufd[8] + bufd[9]).ToString();
     853                                                 double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     854                                                 shuaxin(jieguo, this.zgcZLDY, listzl, myCurvezl);
     855                                             } else if (bufd[7] == "02") {
     856                                                 this.txtZLDL.Text = BLL._60V.VSZDL(bufd[8] + bufd[9]).ToString();
     857                                                 double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     858                                             }
     859                                         }
     860 
     861                                     }
     862                                         //过流过压
     863                                     else if (bufd[5] == "04") {
     864                                         if (bufd[9] == "01") {
     865                                             string str = "FD020610000101110000";
     866 
     867                                             chuansong(str);
     868 
     869                                         }
     870                                         GLGY(this.pbxZLDYR, pbxZLDYG, bufd[9], bufd[7]);
     871 
     872                                     }
     873                                 }
     874                                 break;
     875                             }
     876                         #endregion
     877                         // 热丝电源预热(0-10)分钟
     878                         #region 热丝预热
     879                         case "07": {
     880                                 break;
     881 
     882                             }
     883                         #endregion
     884                         //热丝电源
     885                         #region 热丝
     886                         case "08": {
     887                                 if (bufd[4] == "00") {
     888                                     if (bufd[5] == "03") {
     889                                         if (bufd[7] == "01") {
     890                                             this.txtRSDYS.Text = BLL.DengSi.DSSZ(bufd[8] + bufd[9]).ToString();
     891                                             double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     892                                             shuaxin(jieguo, this.zgcRSDY, listrs, myCurvers);
     893                                         } else if (bufd[7] == "02") {
     894                                             this.txtRSDL.Text = BLL.DengSi.DSSZDL(bufd[8] + bufd[9]).ToString();
     895                                             double jieguo = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     896                                         }
     897                                     }
     898                                         //过流过压
     899                                     else if (bufd[5] == "04") {
     900                                         GLGY(this.pbxRSDYR, pbxRSDYG, bufd[9], bufd[7]);
     901                                     }
     902                                 }
     903                                 break;
     904                             }
     905                         #endregion
     906                         //偏转电源
     907                         #region 偏转
     908                         case "09": {
     909                                 if (bufd[5] == "03") {
     910                                     if (bufd[6] == "01") {
     911                                         if (bufd[7] == "01") {
     912 
     913                                             double zhi = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     914                                             shuaxin(zhi, this.zgcPZDYA, listpza, myCurvepza);
     915                                             if (zhi <= BLL.Model.PZDYZ1.DYXSG) {
     916                                                 this.txtPZDYAS.Text = BLL.PianZhuan.PZASZ(bufd[8] + bufd[9]).ToString();
     917                                             } else if (zhi <= BLL.Model.PZDYZ2.DYXSG) {
     918                                                 this.txtPZDYAS.Text = BLL.PianZhuan.PZBSZ(bufd[8] + bufd[9]).ToString();
     919                                             } else if (zhi <= BLL.Model.PZDYZ3.DYXSG) {
     920                                                 this.txtPZDYAS.Text = BLL.PianZhuan.PZCSZ(bufd[8] + bufd[9]).ToString();
     921                                             }
     922 
     923 
     924                                         } else if (bufd[7] == "02") {
     925                                             double zhi = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     926                                             if (zhi <= BLL.Model.PZDYZ1.DLXSG) {
     927                                                 this.txtPZDLA.Text = BLL.PianZhuan.PZASZDL(bufd[8] + bufd[9]).ToString();
     928                                             } else if (zhi <= BLL.Model.PZDYZ2.DLXSG) {
     929                                                 this.txtPZDLA.Text = BLL.PianZhuan.PZBSZDL(bufd[8] + bufd[9]).ToString();
     930                                             } else if (zhi <= BLL.Model.PZDYZ3.DLXSG) {
     931                                                 this.txtPZDLA.Text = BLL.PianZhuan.PZCSZDL(bufd[8] + bufd[9]).ToString();
     932                                             }
     933 
     934 
     935                                         }
     936 
     937                                     } else if (bufd[6] == "02") {
     938                                         if (bufd[7] == "01") {
     939 
     940                                             double zhi = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     941                                             shuaxin(zhi, this.zgcPZDYB, listpzb, myCurvepzb);
     942 
     943                                             if (zhi <= BLL.Model.PZDYF1.DYXSG) {
     944                                                 this.txtPZDYBS.Text = BLL.PianZhuan.PZASF(bufd[8] + bufd[9]).ToString();
     945                                             } else if (zhi <= BLL.Model.PZDYF2.DYXSG) {
     946                                                 this.txtPZDYBS.Text = BLL.PianZhuan.PZBSF(bufd[8] + bufd[9]).ToString();
     947                                             } else if (zhi <= BLL.Model.PZDYF3.DYXSG) {
     948                                                 this.txtPZDYBS.Text = BLL.PianZhuan.PZCSF(bufd[8] + bufd[9]).ToString();
     949                                             }
     950                                         } else if (bufd[7] == "02") {
     951                                             double zhi = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     952                                             if (zhi <= BLL.Model.PZDYF1.DLXSG) {
     953                                                 this.txtPZDLB.Text = BLL.PianZhuan.PZASFDL(bufd[8] + bufd[9]).ToString();
     954                                             } else if (zhi <= BLL.Model.PZDYF2.DLXSG) {
     955                                                 this.txtPZDLB.Text = BLL.PianZhuan.PZBSFDL(bufd[8] + bufd[9]).ToString();
     956                                             } else if (zhi <= BLL.Model.PZDYF3.DLXSG) {
     957                                                 this.txtPZDLB.Text = BLL.PianZhuan.PZCSFDL(bufd[8] + bufd[9]).ToString();
     958                                             }
     959 
     960                                         }
     961 
     962                                     }
     963 
     964                                 }
     965                                     //过流过压
     966                                 else if (bufd[5] == "05") {
     967                                     //
     968                                     if (bufd[6] == "01") {
     969                                         GLGY(this.pbxPZDYAR, pbxPZDYAG, bufd[9], bufd[7]);
     970                                     }
     971                                         //
     972                                     else if (bufd[6] == "02") {
     973                                         GLGY(this.pbxPZDYBR, pbxPZDYBG, bufd[9], bufd[7]);
     974                                     }
     975                                 }
     976                                 break;
     977                             }
     978                         #endregion
     979                         //主高电源
     980                         #region 主高压
     981                         case "0B": {
     982                                 if (bufd[5] == "03") {
     983                                     if (bufd[7] == "01") {
     984                                         double zhi = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     985                                         if (zhi <= BLL.Model.ZGY1.DYXSG) {
     986                                             this.txtZGYDYS.Text = BLL.ZhuGaoYa.GYSZA(bufd[8] + bufd[9]).ToString();
     987                                         } else if (zhi <= BLL.Model.ZGY2.DYXSG) {
     988                                             this.txtZGYDYS.Text = BLL.ZhuGaoYa.GYSZB(bufd[8] + bufd[9]).ToString();
     989                                         } else if (zhi <= BLL.Model.ZGY3.DYXSG) {
     990                                             this.txtZGYDYS.Text = BLL.ZhuGaoYa.GYSZC(bufd[8] + bufd[9]).ToString();
     991                                         }
     992                                         shuaxin(zhi, this.zgcZGYDY, listzgy, myCurvezgy);
     993 
     994                                     }
     995                                     if (bufd[7] == "02") {
     996                                         double zhi = Math.Round(BLL.ZhuanHuan.Shi(bufd[8] + bufd[9]) / 16383.0 * 5.0, 4);
     997                                         if (zhi <= BLL.Model.ZGY1.DLXSG) {
     998                                             this.txtZGYDL.Text = BLL.ZhuGaoYa.GYSZDLA(bufd[8] + bufd[9]).ToString();
     999                                         } else if (zhi <= BLL.Model.ZGY2.DLXSG) {
    1000                                             this.txtZGYDL.Text = BLL.ZhuGaoYa.GYSZDLB(bufd[8] + bufd[9]).ToString();
    1001                                         } else if (zhi <= BLL.Model.ZGY3.DLXSG) {
    1002                                             this.txtZGYDL.Text = BLL.ZhuGaoYa.GYSZDLC(bufd[8] + bufd[9]).ToString();
    1003                                         }
    1004                                     }
    1005                                 }
    1006                                     //过流过压
    1007                                 else if (bufd[5] == "05") {
    1008 
    1009                                     GLGY(this.pbxZGYDLR, pbxZGYDLG, bufd[9], bufd[7]);
    1010                                 }
    1011                                 break;
    1012 
    1013                             }
    1014                         #endregion
    1015                     }
    1016 
    1017                     #endregion
    1018                     sp.DiscardInBuffer();
    1019                 }
    1020 
    1021             }
    1022 
    1023         }
    1024         //关闭所有电源
    1025         public void Closes() {
    1026             ltr[0].Suspend();
    1027             if (count > 0) {
    1028 
    1029                 this.button8.Text = "加电";
    1030                 this.button29.Text = "加电";
    1031                 this.button23.Text = "加电";
    1032                 this.button5.Text = "加电";
    1033                 this.button41.Text = "加电";
    1034                 this.button36.Text = "加电";
    1035                 this.button2.Text = "加电";
    1036                 this.button1.Text = "加电";
    1037                 this.button11.Text = "加电";
    1038                 this.button9.Text = "加电";
    1039                 this.button10.Text = "加电";
    1040                 this.button4.Text = "加电";
    1041                 if (sp.IsOpen) {
    1042                     string str = "FD010110020401010000";
    1043                     chuansong(str);
    1044                     Thread.Sleep(1000);
    1045                     string strs1 = "FD010110020402010000";
    1046                     chuansong(strs1);
    1047                     Thread.Sleep(1000);
    1048                     string str2 = "FD010210020401010000";
    1049                     chuansong(str2);
    1050                     Thread.Sleep(1000);
    1051                     string strs3 = "FD010318020402010000";
    1052                     chuansong(strs3);
    1053                     Thread.Sleep(1000);
    1054                     string strs4 = "FD010328020401010000";
    1055                     chuansong(strs4);
    1056                     Thread.Sleep(1000);
    1057                     string strs5 = "FD010418020401010000";
    1058                     chuansong(strs5);
    1059                     Thread.Sleep(1000);
    1060                     string strs6 = "FD010428020401010000";
    1061                     chuansong(strs6);
    1062                     Thread.Sleep(1000);
    1063                     string strs7 = "FD010438020401010000";
    1064                     chuansong(strs7);
    1065                     Thread.Sleep(1000);
    1066                     string str8 = "FD010510020401010000";
    1067                     chuansong(str8);
    1068                     Thread.Sleep(1000);
    1069                     string str10 = "FD010810020401010000";
    1070                     chuansong(str10);
    1071                     Thread.Sleep(1000);
    1072                     string strs11 = "FD020910020401010000";
    1073                     chuansong(strs11);
    1074                     Thread.Sleep(1000);
    1075                     string strs12 = "FD020910020402010000";
    1076                     chuansong(strs12);
    1077                     Thread.Sleep(1000);
    1078                     string strs13 = "FD020B10020401010000";
    1079                     chuansong(strs13);
    1080                     Thread.Sleep(1000);
    1081                     string str9 = "FD010610020401010000";
    1082                     chuansong(str9);
    1083                 }
    1084                 for (int i = 0 ; i < cbos.Count ; i++) {
    1085                     cbos[i][i].Enabled = true;
    1086                     btns[i].Enabled = true;
    1087                 }
    1088             }
    1089             ltr[0].Resume();
    1090             sp.Close();
    1091             PictureBox pb = new PictureBox();
    1092             pb.Name = "qb";
    1093             guandeng(pb);
    1094             fc.Hide();
    1095             btnCom.Text = "打开";
    1096             this.pictureBox1.Image = Image.FromFile(whitePath);
    1097         }
    1098         /// <summary>
    1099         /// 输入验证
    1100         /// </summary>
    1101         /// <param name="tb">TextBox文本框</param>
    1102         /// <param name="min">最小值</param>
    1103         /// <param name="max">最大值</param>
    1104         /// <returns></returns>
    1105         public bool tanchukuang(TextBox tb, double min, double max) {
    1106             try {
    1107                 double zhi = Convert.ToDouble(tb.Text.Trim());
    1108                 if (zhi < min || zhi > max) {
    1109                     MessageBox.Show("请输入" + min + "-" + max + "之间的电压");
    1110                     return false;
    1111                 } else {
    1112                     return true;
    1113                 }
    1114             } catch {
    1115                 MessageBox.Show("请输入正确的数字");
    1116                 return false;
    1117 
    1118             }
    1119         }
    1120         //主高压开关
    1121         private void button11_Click(object sender, EventArgs e) {
    1122             ltr[0].Suspend();
    1123             if (tanchukuang(this.txtZGYDY, 9000, 168000)) {
    1124                 if (this.button11.Text == "加电") {
    1125                     count++;
    1126                     this.button11.Text = "断电";
    1127                     string str1 = "FD020B1800010101" + BLL.ZhuGaoYa.GYXZA(10000);
    1128                     chuansong(str1);
    1129                     string strk = "FD020B00010100020000";
    1130                     chuansong(strk);
    1131                     int counts = 30;
    1132                     string[] jieguo = ZGY.SheZhi(this.txtZGYDY.Text.Trim(), gy, zgys);
    1133                     zgy = jieguo[2];
    1134                     if (zgys >= Convert.ToDouble(this.txtZGYDY.Text.Trim())) {
    1135                         chuansong(jieguo[1]);
    1136                         Thread.Sleep(5000);
    1137                         chuansong(jieguo[0]);
    1138                     } else {
    1139                         chuansong(jieguo[0]);
    1140                         double d = Convert.ToDouble(this.txtZGYDY.Text.Trim()) - zgys;
    1141                         //判断之前设置和现在设置的电压差距·根据差距设置循环加电次数
    1142                         if (d >= 140000) {
    1143                             counts = 75;
    1144                         } else if (d >= 100000) {
    1145                             counts = 55;
    1146                         } else if (d >= 60000) {
    1147                             counts = 50;
    1148                         } else if (d >= 30000) {
    1149                             counts = 35;
    1150                         } else {
    1151                             counts = 20;
    1152                         }
    1153                         if (jieguo[3] != "") {
    1154                             chuansong(jieguo[3]);
    1155                             if (jieguo[2] == "11") {
    1156                                 string str = "FD020B1000010101" + BLL.ZhuanHuan.ShiLiu(4.9 * 16383 / 5);
    1157                                 chuansong(str);
    1158                             }
    1159                             double dizeng = Math.Round((4.9 - Convert.ToDouble(jieguo[4])) / counts, 4);
    1160                             double dq = 4.9;
    1161                             for (int i = 0 ; i < counts ; i++) {
    1162                                 if (jieguo[2] == "18") {
    1163                                     dq -= dizeng;
    1164                                     string strs = "FD020B1800010101" + BLL.ZhuanHuan.ShiLiu(dq * 16383 / 5);
    1165                                     chuansong(strs);
    1166                                 } else if (jieguo[2] == "10") {
    1167                                     dq -= dizeng;
    1168                                     string strs = "FD020B1000010101" + BLL.ZhuanHuan.ShiLiu(dq * 16383 / 5);
    1169                                     chuansong(strs);
    1170                                 } else if (jieguo[2] == "11") {
    1171                                     dq -= dizeng;
    1172                                     string strs = "FD020B1100010101" + BLL.ZhuanHuan.ShiLiu(dq * 16383 / 5);
    1173                                     chuansong(strs);
    1174                                 }
    1175                             }
    1176                         } else {
    1177                             double tizeng = (Convert.ToDouble(this.txtZGYDY.Text.Trim()) - zgys) / counts;
    1178                             double dq = zgys;
    1179                             for (int i = 0 ; i < counts ; i++) {
    1180                                 if (jieguo[2] == "18") {
    1181                                     dq += tizeng;
    1182                                     string strs = "FD020B1800010101" + BLL.ZhuGaoYa.GYXZA(dq);
    1183                                     chuansong(strs);
    1184                                 } else if (jieguo[2] == "10") {
    1185                                     dq += tizeng;
    1186                                     string strs = "FD020B1000010101" + BLL.ZhuGaoYa.GYXZB(dq);
    1187                                     chuansong(strs);
    1188                                 } else if (jieguo[2] == "11") {
    1189                                     dq += tizeng;
    1190                                     string strs = "FD020B1100010101" + BLL.ZhuGaoYa.GYXZC(dq);
    1191                                     chuansong(strs);
    1192                                 }
    1193                             }
    1194                         }
    1195                     }
    1196                     zgys = Convert.ToDouble(this.txtZGYDY.Text.Trim());
    1197 
    1198                 } else {
    1199                     count--;
    1200                     zgys = 10000;
    1201 
    1202                     this.button11.Text = "加电";
    1203                     string str = "FD020B00020100020000";
    1204                     guandeng(pbxZGYDLG);
    1205                     chuansong(str);
    1206                     string strs = "FD020B1800010101" + BLL.ZhuGaoYa.GYXZA(10000);
    1207                     chuansong(strs);
    1208                     txtZGYDYS.Text = "";
    1209                     txtZGYDL.Text = "";
    1210                 }
    1211             }
    1212             ltr[0].Resume();
    1213         }
    1214         //偏转A开关
    1215         private void button4_Click(object sender, EventArgs e) {
    1216             ltr[0].Suspend();
    1217             if (tanchukuang(this.txtPZDYA, 0, 9000)) {
    1218                 if (this.button4.Text == "加电") {
    1219                     count++;
    1220 
    1221                     this.button4.Text = "断电";
    1222                     string[] jieguo = new PZA().shezhi(this.txtPZDYA.Text.Trim(), gy, pzas);
    1223                     pza = jieguo[2];
    1224                     if (pzas >= Convert.ToDouble(this.txtPZDYA.Text.Trim())) {
    1225                         chuansong(jieguo[1]);
    1226                         Thread.Sleep(2000);
    1227                         chuansong(jieguo[0]);
    1228                     } else {
    1229                         chuansong(jieguo[0]);
    1230                         chuansong(jieguo[1]);
    1231                     }
    1232                     string[] jieguo2 = new PZB().shezhi(this.txtPZDYA.Text.Trim(), gy, pzbs);
    1233                     pzb = jieguo2[2];
    1234                     if (pzbs >= Convert.ToDouble(this.txtPZDYA.Text.Trim())) {
    1235                         chuansong(jieguo2[1]);
    1236                         Thread.Sleep(2000);
    1237                         chuansong(jieguo2[0]);
    1238                     } else {
    1239                         chuansong(jieguo2[0]);
    1240                         chuansong(jieguo2[1]);
    1241                     }
    1242                     pzas = Convert.ToDouble(this.txtPZDYA.Text.Trim());
    1243                     string str = "FD020900010001010000";
    1244                     chuansong(str);
    1245                     pzbs = Convert.ToDouble(this.txtPZDYA.Text.Trim());
    1246                     string str2 = "FD020900010002010000";
    1247                     chuansong(str2);
    1248                 } else {
    1249                     count--;
    1250                     guandeng(pbxPZDYAG);
    1251                     this.button4.Text = "加电";
    1252                     string str = "FD020900020101010000";
    1253                     chuansong(str);
    1254                     string str2 = "FD020928020102010000";
    1255                     chuansong(str2);
    1256                     txtPZDYAS.Text = "";
    1257                     txtPZDLA.Text = "";
    1258                     txtPZDYBS.Text = "";
    1259                     txtPZDLB.Text = "";
    1260                 }
    1261             }
    1262             ltr[0].Resume();
    1263         }
    1264         //电流图
    1265         public void shuaxin(double shuju, ZedGraphControl zedGraphControl1, PointPairList list, LineItem myCurve) {
    1266             int lenth = 1;
    1267             try {
    1268                 zedGraphControl1.GraphPane.XAxis.Type = ZedGraph.AxisType.DateAsOrdinal;
    1269             } catch {
    1270             }
    1271             for (int i = 0 ; i < lenth ; i++) {
    1272                 double x = (double)new XDate(DateTime.Now.AddSeconds(-(100 - i)));
    1273                 list.Add(x, shuju);
    1274                 if (lenth > 20) {
    1275                     list.RemoveAt(0);
    1276                 }
    1277             }
    1278             DateTime dt = DateTime.Now;
    1279             myCurve = zedGraphControl1.GraphPane.AddCurve("", list, Color.DarkGreen, SymbolType.None);
    1280             zedGraphControl1.AxisChange();
    1281             zedGraphControl1.Refresh();
    1282             lenth++;
    1283         }
    1284         //引出极开关
    1285         private void button2_Click(object sender, EventArgs e) {
    1286             ltr[0].Suspend();
    1287             if (tanchukuang(this.txtYCJDY, 0, 6000)) {
    1288                 if (this.button2.Text == "加电") {
    1289                     count++;
    1290 
    1291                     this.button2.Text = "断电";
    1292                     string[] jieguo = new YCJ().shezhi(this.txtYCJDY.Text.Trim(), gy);
    1293                     chuansong(jieguo[0]);
    1294                     chuansong(jieguo[1]);
    1295                     string str = "FD010210010401010000";
    1296                     chuansong(str);
    1297                     t.Stop();
    1298                     this.button2.Enabled = true;
    1299                 } else {
    1300                     count--;
    1301                     guandeng(pbxYCJDYG);
    1302                     this.button2.Text = "加电";
    1303                     string str = "FD010210020401020000";
    1304                     chuansong(str);
    1305                     txtYCJDYS.Text = "";
    1306                     txtYCJDL.Text = "";
    1307                 }
    1308             }
    1309             ltr[0].Resume();
    1310         }
    1311         //聚焦A开关
    1312         private void button36_Click(object sender, EventArgs e) {
    1313             ltr[0].Suspend();
    1314             if (tanchukuang(this.txtJJDYA, 0, 15000)) {
    1315                 if (this.button36.Text == "加电") {
    1316                     count++;
    1317                     this.button36.Text = "断电";
    1318                     string[] jieguo = new JJA().shezhi(this.txtJJDYA.Text.Trim(), gy, jjas);
    1319                     jja = jieguo[2];
    1320                     if (jjas >= Convert.ToDouble(this.txtJJDYA.Text.Trim())) {
    1321                         chuansong(jieguo[1]);
    1322                         Thread.Sleep(2000);
    1323                         chuansong(jieguo[0]);
    1324                     } else {
    1325                         chuansong(jieguo[0]);
    1326 
    1327                         chuansong(jieguo[1]);
    1328                     }
    1329                     jjas = Convert.ToDouble(this.txtJJDYA.Text.Trim());
    1330                     string str = "FD010318010101010000";
    1331                     chuansong(str);
    1332                 } else {
    1333                     count--;
    1334                     guandeng(pbxJJDYAG);
    1335                     this.button36.Text = "加电";
    1336                     string str = "FD010318020101010000";
    1337                     chuansong(str);
    1338                     txtJJDYAS.Text = "";
    1339                     txtJJDLA.Text = "";
    1340                 }
    1341             }
    1342             ltr[0].Resume();
    1343         }
    1344         //聚集B开关
    1345         private void button41_Click(object sender, EventArgs e) {
    1346             ltr[0].Suspend();
    1347             if (tanchukuang(this.txtJJDYB, 0, 15000)) {
    1348                 if (this.button41.Text == "加电") {
    1349                     count++;
    1350                     this.button41.Text = "断电";
    1351                     string[] jieguo = JJB.shezhi(this.txtJJDYB.Text.Trim(), gy, jjbs);
    1352                     jjb = jieguo[2];
    1353                     if (jjbs >= Convert.ToDouble(this.txtJJDYB.Text.Trim())) {
    1354                         chuansong(jieguo[1]);
    1355                         Thread.Sleep(2000);
    1356                         chuansong(jieguo[0]);
    1357                     } else {
    1358                         chuansong(jieguo[0]);
    1359                         chuansong(jieguo[1]);
    1360                     }
    1361                     jjbs = Convert.ToDouble(this.txtJJDYB.Text.Trim());
    1362                     string str = "FD010328010101010000";
    1363                     chuansong(str);
    1364 
    1365                 } else {
    1366                     count--;
    1367                     guandeng(pbxJJDYBG);
    1368                     this.button41.Text = "加电";
    1369                     string str = "FD010328020101010000";
    1370                     chuansong(str);
    1371                     txtJJDYBS.Text = "";
    1372                     txtJJDLB.Text = "";
    1373                 }
    1374             }
    1375             ltr[0].Resume();
    1376         }
    1377         //预聚集A开关
    1378         private void button5_Click(object sender, EventArgs e) {
    1379             ltr[0].Suspend();
    1380             if (tanchukuang(this.txtYJJDYA, 0, 25000)) {
    1381                 if (this.button5.Text == "加电") {
    1382                     count++;
    1383                     this.button5.Text = "断电";
    1384                     string[] jieguo = new YJJA().shezhi(this.txtYJJDYA.Text.Trim(), gy, yjjas);
    1385                     yjja = jieguo[2];
    1386                     if (yjjas >= Convert.ToDouble(this.txtYJJDYA.Text.Trim())) {
    1387                         chuansong(jieguo[1]);
    1388                         Thread.Sleep(2000);
    1389                         chuansong(jieguo[0]);
    1390                     } else {
    1391                         chuansong(jieguo[0]);
    1392                         chuansong(jieguo[1]);
    1393                     }
    1394                     yjjas = Convert.ToDouble(this.txtYJJDYA.Text.Trim());
    1395                     string str = "FD010418010101010000";
    1396                     chuansong(str);
    1397                 } else {
    1398                     count--;
    1399                     guandeng(pbxYJJDYAG);
    1400                     this.button5.Text = "加电";
    1401                     string str = "FD010418020101010000";
    1402                     chuansong(str);
    1403                     txtYJJDYAS.Text = "";
    1404                     txtYJJDLA.Text = "";
    1405                 }
    1406             }
    1407             ltr[0].Resume();
    1408         }
    1409         //预聚集B开关
    1410         private void button23_Click(object sender, EventArgs e) {
    1411             ltr[0].Suspend();
    1412             if (tanchukuang(this.txtYJJDYB, 0, 25000)) {
    1413                 if (this.button23.Text == "加电") {
    1414                     count++;
    1415                     this.button23.Text = "断电";
    1416                     string[] jieguo = new YJJB().shezhi(this.txtYJJDYB.Text.Trim(), gy, yjjbs);
    1417                     yjjb = jieguo[2];
    1418                     if (yjjbs >= Convert.ToDouble(this.txtYJJDYB.Text.Trim())) {
    1419                         chuansong(jieguo[1]);
    1420                         Thread.Sleep(2000);
    1421                         chuansong(jieguo[0]);
    1422                     } else {
    1423 
    1424                         chuansong(jieguo[0]);
    1425                         chuansong(jieguo[1]);
    1426 
    1427                     }
    1428                     yjjbs = Convert.ToDouble(this.txtYJJDYB.Text.Trim());
    1429                     string str = "FD010428010101010000";
    1430                     chuansong(str);
    1431                 } else {
    1432                     count--;
    1433                     guandeng(pbxYJJDYBG);
    1434                     this.button23.Text = "加电";
    1435                     string str = "FD010428020101010000";
    1436                     chuansong(str);
    1437                     txtYJJDYBS.Text = "";
    1438                     txtYJJDLB.Text = "";
    1439                 }
    1440             }
    1441             ltr[0].Resume();
    1442         }
    1443         //预聚集C开关
    1444         private void button29_Click(object sender, EventArgs e) {
    1445             ltr[0].Suspend();
    1446             if (tanchukuang(this.txtYJJDYC, 0, 25000)) {
    1447                 if (this.button29.Text == "加电") {
    1448                     count++;
    1449                     this.button29.Text = "断电";
    1450                     string[] jieguo = new YJJC().shezhi(this.txtYJJDYC.Text.Trim(), gy, yjjcs);
    1451                     yjc = jieguo[2];
    1452                     if (yjjcs >= Convert.ToDouble(this.txtYJJDYC.Text.Trim())) {
    1453                         chuansong(jieguo[1]);
    1454                         Thread.Sleep(2000);
    1455                         chuansong(jieguo[0]);
    1456                     } else {
    1457                         chuansong(jieguo[0]);
    1458                         chuansong(jieguo[1]);
    1459                     }
    1460                     yjjcs = Convert.ToDouble(this.txtYJJDYC.Text.Trim());
    1461                     string str = "FD010438010101010000";
    1462                     chuansong(str);
    1463                 } else {
    1464                     count--;
    1465                     guandeng(pbxYJJDYCG);
    1466                     this.button29.Text = "加电";
    1467                     string str = "FD010438020101010000";
    1468                     chuansong(str);
    1469                     txtYJJDYCS.Text = "";
    1470                     txtYJJDLC.Text = "";
    1471                 }
    1472             }
    1473             ltr[0].Resume();
    1474         }
    1475         //主高压
    1476         private void button22_Click(object sender, EventArgs e) {
    1477             ltr[0].Suspend();
    1478             if (tanchukuang(this.txtZGYDY, 9000, 168000)) {
    1479                 double newzgy = Convert.ToDouble(this.txtZGYDY.Text.Trim());
    1480                 string[] jieguo = ZGY.SheZhi(this.txtZGYDY.Text.Trim(), gy, zgys);
    1481                 if (zgys >= Convert.ToDouble(this.txtZGYDY.Text.Trim())) {
    1482                     chuansong(jieguo[1]);
    1483                     Thread.Sleep(5000);
    1484                     chuansong(jieguo[0]);
    1485                 } else {
    1486                     int counts = 30;
    1487                     chuansong(jieguo[0]);
    1488                     double d = Convert.ToDouble(this.txtZGYDY.Text.Trim()) - zgys;
    1489                     //判断之前设置和现在设置的电压差距·根据差距设置循环加电次数
    1490                     if (d >= 140000) {
    1491 
    1492                         counts = 75;
    1493                     } else if (d >= 100000) {
    1494                         counts = 55;
    1495                     } else if (d >= 600000) {
    1496                         counts = 50;
    1497                     } else if (d >= 300000) {
    1498                         counts = 35;
    1499                     } else {
    1500                         counts = 20;
    1501                     }
    1502                     if (jieguo[3] != "") {
    1503                         chuansong(jieguo[3]);
    1504                         if (jieguo[2] == "11") {
    1505                             string str = "FD020B1000010101" + BLL.ZhuanHuan.ShiLiu(4.9 * 16383 / 5);
    1506                             chuansong(str);
    1507                         }
    1508                         double dizeng = Math.Round((4.9 - Convert.ToDouble(jieguo[4])) / counts, 4);
    1509                         double dq = 4.9;
    1510                         for (int i = 0 ; i < counts ; i++) {
    1511                             if (jieguo[2] == "18") {
    1512                                 dq -= dizeng;
    1513                                 string strs = "FD020B1800010101" + BLL.ZhuanHuan.ShiLiu(dq * 16383 / 5);
    1514                                 chuansong(strs);
    1515                             } else if (jieguo[2] == "10") {
    1516                                 dq -= dizeng;
    1517                                 string strs = "FD020B1000010101" + BLL.ZhuanHuan.ShiLiu(dq * 16383 / 5);
    1518                                 chuansong(strs);
    1519                             } else if (jieguo[2] == "11") {
    1520                                 dq -= dizeng;
    1521                                 string strs = "FD020B1100010101" + BLL.ZhuanHuan.ShiLiu(dq * 16383 / 5);
    1522                                 chuansong(strs);
    1523                             }
    1524                         }
    1525                     } else {
    1526                         double tizeng = (Convert.ToDouble(this.txtZGYDY.Text.Trim()) - zgys) / counts;
    1527                         double dq = zgys;
    1528                         for (int i = 0 ; i < counts ; i++) {
    1529                             if (jieguo[2] == "18") {
    1530                                 dq += tizeng;
    1531                                 string strs = "FD020B1800010101" + BLL.ZhuGaoYa.GYXZA(dq);
    1532                                 chuansong(strs);
    1533                             } else if (jieguo[2] == "10") {
    1534                                 dq += tizeng;
    1535                                 string strs = "FD020B1000010101" + BLL.ZhuGaoYa.GYXZB(dq);
    1536                                 chuansong(strs);
    1537                             } else if (jieguo[2] == "11") {
    1538                                 dq += tizeng;
    1539                                 string strs = "FD020B1100010101" + BLL.ZhuGaoYa.GYXZC(dq);
    1540                                 chuansong(strs);
    1541                             }
    1542                         }
    1543                     }
    1544 
    1545                 }
    1546                 zgy = jieguo[2];
    1547                 zgys = Convert.ToDouble(this.txtZGYDY.Text.Trim());
    1548 
    1549             }
    1550             ltr[0].Resume();
    1551         }
    1552         //引出极
    1553         private void button13_Click(object sender, EventArgs e) {
    1554             ltr[0].Suspend();
    1555             if (tanchukuang(this.txtYCJDY, 0, 6000)) {
    1556                 string[] jieguo = new YCJ().shezhi(this.txtYCJDY.Text.Trim(), gy.Trim());
    1557                 chuansong(jieguo[0]);
    1558                 chuansong(jieguo[1]);
    1559             }
    1560             ltr[0].Resume();
    1561         }
    1562         //聚焦A
    1563         private void button14_Click(object sender, EventArgs e) {
    1564             ltr[0].Suspend();
    1565             if (tanchukuang(this.txtJJDYA, 0, 15000)) {
    1566                 string[] jieguo = new JJA().shezhi(this.txtJJDYA.Text.Trim(), gy, jjas);
    1567                 if (jjas >= Convert.ToDouble(this.txtJJDYA.Text.Trim())) {
    1568                     chuansong(jieguo[1]);
    1569                     Thread.Sleep(2000);
    1570                     chuansong(jieguo[0]);
    1571                 } else {
    1572                     chuansong(jieguo[0]);
    1573                     if (jieguo[3] != "") {
    1574                         chuansong(jieguo[3]);
    1575                     }
    1576                     chuansong(jieguo[1]);
    1577                 }
    1578                 jjas = Convert.ToDouble(this.txtJJDYA.Text.Trim());
    1579             }
    1580             ltr[0].Resume();
    1581         }
    1582         //聚集B
    1583         private void button38_Click(object sender, EventArgs e) {
    1584             ltr[0].Suspend();
    1585             if (tanchukuang(this.txtJJDYB, 0, 15000)) {
    1586                 string[] jieguo = JJB.shezhi(this.txtJJDYB.Text.Trim(), gy, jjbs);
    1587                 if (jjbs >= Convert.ToDouble(this.txtJJDYB.Text.Trim())) {
    1588                     chuansong(jieguo[1]);
    1589                     Thread.Sleep(2000);
    1590                     chuansong(jieguo[0]);
    1591                 } else {
    1592                     chuansong(jieguo[0]);
    1593                     if (jieguo[3] != "") {
    1594                         chuansong(jieguo[3]);
    1595                     }
    1596                     chuansong(jieguo[1]);
    1597                 }
    1598                 jjbs = Convert.ToDouble(this.txtJJDYB.Text.Trim());
    1599             }
    1600             ltr[0].Resume();
    1601         }
    1602         //预聚集A
    1603         private void button16_Click(object sender, EventArgs e) {
    1604             ltr[0].Suspend();
    1605             if (tanchukuang(this.txtYJJDYA, 0, 25000)) {
    1606                 string[] jieguo = new YJJA().shezhi(this.txtYJJDYA.Text.Trim(), gy, yjjas);
    1607 
    1608                 if (yjjas >= Convert.ToDouble(this.txtYJJDYA.Text.Trim())) {
    1609                     chuansong(jieguo[1]);
    1610                     Thread.Sleep(2000);
    1611                     chuansong(jieguo[0]);
    1612                 } else {
    1613                     chuansong(jieguo[0]);
    1614                     if (jieguo[3] != "") {
    1615                         chuansong(jieguo[3]);
    1616                     }
    1617                     chuansong(jieguo[1]);
    1618                 }
    1619                 yjjas = Convert.ToDouble(this.txtYJJDYA.Text.Trim());
    1620             }
    1621             ltr[0].Resume();
    1622         }
    1623         //预聚集B
    1624         private void button24_Click(object sender, EventArgs e) {
    1625             ltr[0].Suspend();
    1626             if (tanchukuang(this.txtYJJDYB, 0, 25000)) {
    1627                 string[] jieguo = new YJJB().shezhi(this.txtYJJDYB.Text.Trim(), gy, yjjbs);
    1628                 if (yjjbs >= Convert.ToDouble(this.txtYJJDYB.Text.Trim())) {
    1629                     chuansong(jieguo[1]);
    1630                     Thread.Sleep(2000);
    1631                     chuansong(jieguo[0]);
    1632                 } else {
    1633                     chuansong(jieguo[0]);
    1634                     if (jieguo[3] != "") {
    1635                         chuansong(jieguo[3]);
    1636                     }
    1637                     chuansong(jieguo[1]);
    1638                 }
    1639                 yjjbs = Convert.ToDouble(this.txtYJJDYB.Text.Trim());
    1640             }
    1641             ltr[0].Resume();
    1642         }
    1643         //预聚集C
    1644         private void button30_Click(object sender, EventArgs e) {
    1645             ltr[0].Suspend();
    1646             if (tanchukuang(this.txtYJJDYC, 0, 25000)) {
    1647                 string[] jieguo = new YJJC().shezhi(this.txtYJJDYC.Text.Trim(), gy, yjjcs);
    1648                 if (yjjcs >= Convert.ToDouble(this.txtYJJDYC.Text.Trim())) {
    1649                     chuansong(jieguo[1]);
    1650                     Thread.Sleep(2000);
    1651                     chuansong(jieguo[0]);
    1652                 } else {
    1653                     chuansong(jieguo[0]);
    1654                     if (jieguo[3] != "") {
    1655                         chuansong(jieguo[3]);
    1656                     }
    1657                     chuansong(jieguo[1]);
    1658                 }
    1659                 yjjcs = Convert.ToDouble(this.txtYJJDYC.Text.Trim());
    1660             }
    1661             ltr[0].Resume();
    1662         }
    1663         //偏转A
    1664         private void button3_Click(object sender, EventArgs e) {
    1665             ltr[0].Suspend();
    1666             if (tanchukuang(this.txtPZDYA, 0, 9000)) {
    1667                 string[] jieguo = new PZA().shezhi(this.txtPZDYA.Text.Trim(), gy, pzas);
    1668                 if (pzas >= Convert.ToDouble(this.txtPZDYA.Text.Trim())) {
    1669                     chuansong(jieguo[1]);
    1670                     Thread.Sleep(2000);
    1671                     chuansong(jieguo[0]);
    1672                 } else {
    1673                     chuansong(jieguo[0]);
    1674                     if (jieguo[3] != "") {
    1675                         chuansong(jieguo[3]);
    1676                     }
    1677                     chuansong(jieguo[1]);
    1678                 }
    1679                 pzas = Convert.ToDouble(this.txtPZDYA.Text.Trim());
    1680                 string[] jieguo2 = new PZB().shezhi(this.txtPZDYA.Text.Trim(), gy, pzbs);
    1681                 if (pzbs >= Convert.ToDouble(this.txtPZDYA.Text.Trim())) {
    1682                     chuansong(jieguo2[1]);
    1683                     Thread.Sleep(2000);
    1684                     chuansong(jieguo2[0]);
    1685                 } else {
    1686                     chuansong(jieguo2[0]);
    1687                     if (jieguo2[3] != "") {
    1688                         chuansong(jieguo2[3]);
    1689                     }
    1690                     chuansong(jieguo2[1]);
    1691                 }
    1692                 pzbs = Convert.ToDouble(this.txtPZDYA.Text.Trim());
    1693             }
    1694             ltr[0].Resume();
    1695         }
    1696         //关闭状态图片
    1697         public void guandeng(PictureBox pb) {
    1698             if (pb.Name == "qb") {
    1699                 this.pbxZGYDLG.Image = Image.FromFile(whitePath);
    1700                 this.pbxYCJDYG.Image = Image.FromFile(whitePath);
    1701                 this.pbxJJDYAG.Image = Image.FromFile(whitePath);
    1702                 this.pbxJJDYBG.Image = Image.FromFile(whitePath);
    1703                 this.pbxYJJDYAG.Image = Image.FromFile(whitePath);
    1704                 this.pbxYJJDYBG.Image = Image.FromFile(whitePath);
    1705                 this.pbxYJJDYCG.Image = Image.FromFile(whitePath);
    1706                 this.pbxPZDYAG.Image = Image.FromFile(whitePath);
    1707                 this.pbxPZDYBG.Image = Image.FromFile(whitePath);
    1708             } else {
    1709                 pb.Image = Image.FromFile(whitePath);
    1710             }
    1711         }
    1712         //切换模式
    1713         private void RFD_Form_Deactivate(object sender, EventArgs e) {
    1714             Closes();
    1715             ltr[0].Abort();
    1716             ltr.RemoveAt(0);
    1717         }
    1718         //模式加载
    1719         private void RFD_Form_Activated(object sender, EventArgs e) {
    1720             Control.CheckForIllegalCrossThreadCalls = false;
    1721             this.cboCom.SelectedIndex = 0;
    1722             this.cboMCA.SelectedIndex = 0;
    1723             fc.Hide();
    1724             count = 0;
    1725             jjas = 0;
    1726             jjbs = 0;
    1727             yjjas = 0;
    1728             yjjbs = 0;
    1729             yjjcs = 0;
    1730             rss = 0;
    1731             zgys = 10000;
    1732             pzas = 0;
    1733             pzbs = 0;
    1734             Thread td = new Thread(new ThreadStart(NewXianCheng));
    1735             ltr.Add(td);
    1736             td.Start();
    1737             if (!sp.IsOpen) {
    1738                 for (int i = 0 ; i < this.cboCom.Items.Count ; i++) {
    1739                     try {
    1740                         sp.PortName = cboCom.Items[i].ToString();
    1741                         sp.BaudRate = 9600;
    1742                         sp.Parity = Parity.None;
    1743                         sp.DataBits = 8;
    1744                         sp.StopBits = StopBits.One;
    1745                         sp.Open();
    1746                         this.btnCom.Text = "关闭";
    1747                         this.pictureBox1.Image = Image.FromFile(greenPath);
    1748                         continue;
    1749                     } catch {
    1750 
    1751                     }
    1752                 }
    1753             }
    1754         }
    1755         //串口设置
    1756         private void btnCom_Click(object sender, EventArgs e) {
    1757             if (sp.IsOpen == false) {
    1758                 if (cboCom.Text != "") {
    1759                     try {
    1760                         sp.PortName = cboCom.SelectedItem.ToString();
    1761                         sp.BaudRate = 9600;
    1762                         sp.Parity = Parity.None;
    1763                         sp.DataBits = 8;
    1764                         sp.StopBits = StopBits.One;
    1765                         sp.Open();
    1766                         this.btnCom.Text = "关闭";
    1767                         this.pictureBox1.Image = Image.FromFile(greenPath);
    1768 
    1769                     } catch {
    1770 
    1771                         MessageBox.Show(cboCom.SelectedItem.ToString() + "不存在");
    1772                     }
    1773 
    1774                 }
    1775             } else {
    1776                 if (MessageBox.Show("是否关闭端口?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes) {
    1777 
    1778                     fc.Show();
    1779                     Thread t = new Thread(new ThreadStart(Closes));
    1780                     t.Start();
    1781                 }
    1782 
    1783             }
    1784         }
    1785         //刷新显示
    1786         private void button15_Click(object sender, EventArgs e) {
    1787             if (ltr[0].IsAlive) {
    1788                 try {
    1789                     ltr[0].Abort();
    1790                     ltr.RemoveAt(0);
    1791                     Thread td = new Thread(new ThreadStart(NewXianCheng));
    1792                     ltr.Add(td);
    1793                     td.Start();
    1794                 } catch {
    1795 
    1796 
    1797                 }
    1798             } else {
    1799                 ltr.RemoveAt(0);
    1800                 Thread td = new Thread(new ThreadStart(NewXianCheng));
    1801                 ltr.Add(td);
    1802                 td.Start();
    1803             }
    1804         }
    1805         //关闭窗口
    1806         private void RFD_Form_FormClosing(object sender, FormClosingEventArgs e) {
    1807             if (ltr[0].IsAlive) {
    1808                 ltr[0].Abort();
    1809             }
    1810         }
    1811         //抑制极开关
    1812         private void button1_Click(object sender, EventArgs e) {
    1813             ltr[0].Suspend();
    1814             if (tanchukuang(this.txtYZJDY, -1500, 1500)) {
    1815                 if (this.button1.Text == "加电") {
    1816                     count++;
    1817                     double dy = Convert.ToDouble(this.txtYZJDY.Text);
    1818                     if (dy >= 0) {
    1819                         ZF = true;
    1820                         string[] jieguo = YZJ.shezhi(this.txtYZJDY.Text.Trim(), "");
    1821                         chuansong(jieguo[0]);
    1822                         string strs = "FD010110030001000000";
    1823                         chuansong(strs);
    1824                         string[] fu = YZJ.shezhi("0", "");
    1825                         chuansong(fu[0]);
    1826                         string str3 = "FD010110020402010000";
    1827                         chuansong(str3);
    1828                         string str = "FD010110010001010000";
    1829                         chuansong(str);
    1830 
    1831 
    1832                     } else {
    1833                         ZF = false;
    1834                         string[] jieguo = YZJ.shezhi(this.txtYZJDY.Text.Trim(), "");
    1835                         chuansong(jieguo[0]);
    1836                         string strs = "FD010110030002000000";
    1837                         chuansong(strs);
    1838                         string[] zheng = YZJ.shezhi("0", "");
    1839                         chuansong(zheng[0]);
    1840                         string str3 = "FD010110020401010000";
    1841                         chuansong(str3);
    1842                         string str2 = "FD010110010002010000";
    1843                         chuansong(str2);
    1844 
    1845                     }
    1846 
    1847                     this.button1.Text = "断电";
    1848                 } else {
    1849                     count--;
    1850                     this.button1.Text = "加电";
    1851                     string str = "";
    1852                     if (ZF) {
    1853                         str = "FD010110020401010000";
    1854                         chuansong(str);
    1855                     } else {
    1856                         str = "FD010110020402010000";
    1857                         chuansong(str);
    1858                     }
    1859                     guandeng(pbxYZJDYG);
    1860                     txtYZJDYS.Text = "";
    1861                     txtYZJDL.Text = "";
    1862                 }
    1863             }
    1864             ltr[0].Resume();
    1865         }
    1866         //抑制极
    1867         private void button12_Click(object sender, EventArgs e) {
    1868             if (tanchukuang(this.txtYZJDY, -1500, 1500)) {
    1869                 ltr[0].Suspend();
    1870                 double dy = Convert.ToDouble(this.txtYZJDY.Text);
    1871                 if (dy >= 0) {
    1872                     ZF = true;
    1873                     string[] jieguo = YZJ.shezhi(this.txtYZJDY.Text.Trim(), "");
    1874                     chuansong(jieguo[0]);
    1875                     string strs = "FD010110030001000000";
    1876                     chuansong(strs);
    1877                     string[] fu = YZJ.shezhi("0", "");
    1878                     chuansong(fu[0]);
    1879                     string str3 = "FD010110020402010000";
    1880                     chuansong(str3);
    1881                     string str = "FD010110010001010000";
    1882                     chuansong(str);
    1883 
    1884 
    1885                 } else {
    1886                     ZF = false;
    1887                     string[] jieguo = YZJ.shezhi(this.txtYZJDY.Text.Trim(), "");
    1888                     chuansong(jieguo[0]);
    1889                     string strs = "FD010110030002000000";
    1890                     chuansong(strs);
    1891                     string[] zheng = YZJ.shezhi("0", "");
    1892                     chuansong(zheng[0]);
    1893                     string str3 = "FD010110020401010000";
    1894                     chuansong(str3);
    1895                     string str2 = "FD010110010002010000";
    1896                     chuansong(str2);
    1897 
    1898                 }
    1899 
    1900                 ltr[0].Resume();
    1901             }
    1902         }
    1903         //脉冲开关A
    1904         private void button8_Click(object sender, EventArgs e) {
    1905             ltr[0].Suspend();
    1906             if (tanchukuang(this.txtMCSCDY, 0, 6000)) {
    1907                 if (this.button8.Text == "加电") {
    1908                     count++;
    1909                     string jieguo2 = new MCSZ().shezhi("20/100");
    1910                     chuansong(jieguo2);
    1911                     this.button8.Text = "断电";
    1912                     string[] jieguo = new MC().shezhi(this.txtMCSCDY.Text.Trim(), gy);
    1913                     chuansong(jieguo[0]);
    1914                     double z = Convert.ToDouble(this.txtMCSCDY.Text.Trim());
    1915                     double j = z / 20;
    1916                     double s = j;
    1917                     for (int i = 0 ; i < 20 ; i++) {
    1918                         string[] jieguo3 = new MC().shezhi(j.ToString(), gy);
    1919                         chuansong(jieguo3[1]);
    1920                         j = j + s;
    1921                         if (i == 0) {
    1922                             string str = "FD010510010101010000";
    1923                             chuansong(str);
    1924                         }
    1925                     }
    1926 
    1927 
    1928                     chuansong(jieguo[1]);
    1929 
    1930                 } else {
    1931                     count--;
    1932                     guandeng(pbxMCSCDYG);
    1933                     this.button8.Text = "加电";
    1934                     string str = "FD010510020101010000";
    1935                     chuansong(str);
    1936                     txtMCSCDYS.Text = "";
    1937                     txtMCSCDL.Text = "";
    1938                 }
    1939             }
    1940             ltr[0].Resume();
    1941         }
    1942         //脉冲A设置
    1943         private void button17_Click(object sender, EventArgs e) {
    1944             ltr[0].Suspend();
    1945             string[] jieguo = new MC().shezhi(this.txtMCSCDY.Text.Trim(), gy);
    1946             chuansong(jieguo[0]);
    1947             string[] jieguo3 = new MC().shezhi("300", gy);
    1948             chuansong(jieguo3[1]);
    1949             Thread.Sleep(2000);
    1950             if (this.cboMCA.Text != "") {
    1951                 string jieguo2 = new MCSZ().shezhi(this.cboMCA.SelectedItem.ToString());
    1952                 chuansong(jieguo2);
    1953             }
    1954             double z = Convert.ToDouble(this.txtMCSCDY.Text.Trim());
    1955             double j = z / 50;
    1956             double s = j;
    1957             for (int i = 0 ; i < 50 ; i++) {
    1958                 string[] jieguo2 = new MC().shezhi(j.ToString(), gy);
    1959                 chuansong(jieguo2[1]);
    1960                 j = j + s;
    1961             }
    1962 
    1963             ltr[0].Resume();
    1964 
    1965         }
    1966         //热丝开关
    1967         private void button10_Click(object sender, EventArgs e) {
    1968             ltr[0].Suspend();
    1969             if (tanchukuang(this.txtRSDY, 0, 15)) {
    1970                 if (this.button10.Text == "加电") {
    1971                     count++;
    1972 
    1973                     this.button10.Text = "断电";
    1974                     string[] jieguo = new RS().shezhi(this.txtRSDY.Text.Trim(), gy);
    1975                     if (rss >= Convert.ToDouble(this.txtRSDY.Text.Trim())) {
    1976                         chuansong(jieguo[1]);
    1977                         chuansong(jieguo[0]);
    1978                     } else {
    1979                         chuansong(jieguo[0]);
    1980                         chuansong(jieguo[1]);
    1981                     }
    1982                     rss = Convert.ToDouble(this.txtRSDY.Text.Trim());
    1983                     string str = "FD010810010101010000";
    1984                     chuansong(str);
    1985                 } else {
    1986                     count--;
    1987                     guandeng(pbxRSDYG);
    1988                     this.button10.Text = "加电";
    1989                     string str = "FD010810020101020000";
    1990                     chuansong(str);
    1991                     txtRSDYS.Text = "";
    1992                     txtRSDL.Text = "";
    1993                 }
    1994             }
    1995             ltr[0].Resume();
    1996         }
    1997 
    1998         void t_Tick(object sender, EventArgs e) {
    1999             if (button2.Text == "加电") {
    2000                 button2_Click(sender, e);
    2001             }
    2002             button2.Enabled = false;
    2003         }
    2004         //60v整流开关
    2005         private void button9_Click(object sender, EventArgs e) {
    2006             ltr[0].Suspend();
    2007             if (this.button9.Text == "加电") {
    2008                 string str1 = "FD010510020101010000";
    2009                 chuansong(str1);
    2010                 count++;
    2011                 this.button9.Text = "断电";
    2012                 string str = "FD020600010101000000";
    2013                 chuansong(str);
    2014 
    2015 
    2016             } else {
    2017                 count--;
    2018                 guandeng(pbxZLDYG);
    2019                 this.button9.Text = "加电";
    2020                 string str = "FD020600020101000000";
    2021                 chuansong(str);
    2022                 txtZLDYS.Text = "";
    2023                 txtZLDL.Text = "";
    2024             }
    2025             ltr[0].Resume();
    2026         }
    2027         //热丝
    2028         private void button21_Click(object sender, EventArgs e) {
    2029             ltr[0].Suspend();
    2030             if (tanchukuang(this.txtRSDY, 0, 15)) {
    2031                 string[] jieguo = new RS().shezhi(this.txtRSDY.Text.Trim(), gy);
    2032                 if (rss >= Convert.ToDouble(this.txtRSDY.Text.Trim())) {
    2033                     chuansong(jieguo[1]);
    2034                     chuansong(jieguo[0]);
    2035                 } else {
    2036                     chuansong(jieguo[0]);
    2037                     chuansong(jieguo[1]);
    2038                 }
    2039                 rss = Convert.ToDouble(this.txtRSDY.Text.Trim());
    2040             }
    2041             ltr[0].Resume();
    2042         }
    2043         //脉冲A
    2044         private void button20_Click(object sender, EventArgs e) {
    2045             if (tanchukuang(this.txtMCSCDY, 0, 6000)) {
    2046                 string[] jieguo = new MC().shezhi(this.txtMCSCDY.Text.Trim(), gy);
    2047                 chuansong(jieguo[0]);
    2048                 double z = Convert.ToDouble(this.txtMCSCDY.Text.Trim());
    2049                 double j = z / 20;
    2050                 double s = j;
    2051                 for (int i = 0 ; i < 20 ; i++) {
    2052                     string[] jieguo2 = new MC().shezhi(j.ToString(), gy);
    2053                     chuansong(jieguo2[1]);
    2054                     j = j + s;
    2055                 }
    2056 
    2057 
    2058                 chuansong(jieguo[1]);
    2059             }
    2060         }
    2061         //自动加断电
    2062         private void button6_Click(object sender, EventArgs e) {
    2063             if (this.button6.Text == "热发射模式加电") {
    2064                 #region 加电
    2065                 int[] sx = new int[] { 0, 9, 1, 10, 2, 5, 6, 7, 3, 4, 8, 11 };
    2066                 int[] sx2 = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
    2067                 for (int i = 0 ; i < cbos.Count ; i++) {
    2068                     if (cbos[i][i].Checked) {
    2069                         for (int j = 0 ; j < sx.Count() ; j++) {
    2070                             if (sx[j] == i) {
    2071                                 sx2[j] = i;
    2072                             }
    2073                         }
    2074 
    2075                     }
    2076                 }
    2077                 for (int i = 0 ; i < sx2.Count() ; i++) {
    2078                     switch (sx2[i]) {
    2079                         //热丝
    2080                         case 10: {
    2081                                 if (this.button10.Text == "加电") {
    2082 
    2083                                     button10_Click(sender, e);
    2084                                     button10.Enabled = false;
    2085                                     //等待2分钟后加引出极
    2086                                     if (cboYCJ.Checked) {
    2087 
    2088                                         t.Interval = 120000;
    2089                                         t.Tick += new EventHandler(t_Tick);
    2090                                         t.Start();
    2091                                         this.button2.Enabled = false;
    2092                                     }
    2093 
    2094                                 }
    2095                                 break;
    2096                             }
    2097 
    2098                         ////引出极
    2099                         //case 2:
    2100                         //    {
    2101                         //        button2_Click(sender, e);
    2102                         //        break;
    2103                         //    }
    2104                         //抑制极
    2105                         case 1: {
    2106                                 if (this.button1.Text == "加电") {
    2107                                     button1_Click(sender, e);
    2108                                     button1.Enabled = false;
    2109                                 }
    2110                                 break;
    2111                             }
    2112                         //聚集A
    2113                         case 3: {
    2114                                 if (this.button36.Text == "加电") {
    2115                                     button36_Click(sender, e);
    2116                                     button36.Enabled = false;
    2117                                 }
    2118                                 break;
    2119                             }
    2120                         //聚集B
    2121                         case 4: {
    2122                                 if (this.button41.Text == "加电") {
    2123                                     button41_Click(sender, e);
    2124                                     button41.Enabled = false;
    2125                                 }
    2126                                 break;
    2127                             }
    2128                         //预聚集A
    2129                         case 5: {
    2130                                 if (this.button5.Text == "加电") {
    2131                                     button5_Click(sender, e);
    2132                                     button5.Enabled = false;
    2133                                 }
    2134                                 break;
    2135                             }
    2136                         //预聚集B
    2137                         case 6: {
    2138                                 if (this.button23.Text == "加电") {
    2139                                     button23_Click(sender, e);
    2140                                     button23.Enabled = false;
    2141                                 }
    2142                                 break;
    2143                             }
    2144                         //预聚集C
    2145                         case 7: {
    2146                                 if (this.button29.Text == "加电") {
    2147                                     button29_Click(sender, e);
    2148                                     button29.Enabled = false;
    2149                                 }
    2150                                 break;
    2151                             }
    2152                         //偏转
    2153                         case 11: {
    2154                                 if (this.button4.Text == "加电") {
    2155                                     button4_Click(sender, e);
    2156                                     button4.Enabled = false;
    2157                                 }
    2158                                 break;
    2159                             }
    2160                         //脉冲
    2161                         case 8: {
    2162                                 if (this.button8.Text == "加电") {
    2163                                     button8_Click(sender, e);
    2164                                     button8.Enabled = false;
    2165                                 }
    2166                                 break;
    2167                             }
    2168                         //整流
    2169                         case 9: {
    2170                                 if (this.button9.Text == "加电") {
    2171                                     button9_Click(sender, e);
    2172                                     button9.Enabled = false;
    2173                                     Thread.Sleep(5000);
    2174                                 }
    2175                                 break;
    2176                             }
    2177                         //主高压
    2178                         case 0: {
    2179                                 if (this.button11.Text == "加电") {
    2180                                     button11_Click(sender, e);
    2181                                     button11.Enabled = false;
    2182                                 }
    2183                                 break;
    2184                             }
    2185                         default:
    2186                             break;
    2187                     }
    2188                 }
    2189                 #endregion
    2190                 this.button6.Text = "热发射模式断电";
    2191                 for (int i = 0 ; i < cbos.Count ; i++) {
    2192                     cbos[i][i].Enabled = false;
    2193                 }
    2194 
    2195             } else {
    2196                 #region 断电
    2197                 int[] sx = new int[] { 10, 2, 1, 3, 4, 5, 6, 7, 11, 8, 9, 0 };
    2198                 int[] sx2 = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
    2199                 for (int i = 0 ; i < cbos.Count ; i++) {
    2200                     if (cbos[i][i].Checked) {
    2201                         for (int j = 0 ; j < sx.Count() ; j++) {
    2202                             if (sx[j] == i) {
    2203                                 sx2[j] = i;
    2204                             }
    2205                         }
    2206 
    2207                     }
    2208                 }
    2209                 //抑制极调到负的最极大,但不断电
    2210                 if (button1.Text == "断电") {
    2211                     ZF = false;
    2212                     string[] jieguo = YZJ.shezhi("-1000", "");
    2213                     chuansong(jieguo[0]);
    2214                     string strs = "FD010110030002000000";
    2215                     chuansong(strs);
    2216                 }
    2217                 for (int i = 0 ; i < sx2.Count() ; i++) {
    2218                     switch (sx2[i]) {
    2219 
    2220                         //热丝
    2221                         case 10: {
    2222                                 if (button10.Text == "断电") {
    2223                                     button10_Click(sender, e);
    2224                                     button10.Enabled = true;
    2225                                     if (t.Enabled) {
    2226                                         t.Stop();
    2227                                     }
    2228 
    2229                                 }
    2230                                 break;
    2231                             }
    2232 
    2233                         //引出极
    2234                         case 2: {
    2235                                 if (button2.Text == "断电") {
    2236                                     button2_Click(sender, e);
    2237                                 }
    2238                                 button2.Enabled = true;
    2239                                 break;
    2240                             }
    2241                         //抑制极
    2242                         case 1: {
    2243                                 if (button1.Text == "断电") {
    2244                                     button1_Click(sender, e);
    2245                                     button1.Enabled = true;
    2246                                 }
    2247                                 break;
    2248                             }
    2249                         //聚集A
    2250                         case 3: {
    2251                                 if (button36.Text == "断电") {
    2252                                     button36_Click(sender, e);
    2253                                     button36.Enabled = true;
    2254                                 }
    2255                                 break;
    2256                             }
    2257                         //聚集B
    2258                         case 4: {
    2259                                 if (button41.Text == "断电") {
    2260                                     button41_Click(sender, e);
    2261                                     button41.Enabled = true;
    2262                                 }
    2263                                 break;
    2264                             }
    2265                         //预聚集A
    2266                         case 5: {
    2267                                 if (button5.Text == "断电") {
    2268                                     button5_Click(sender, e);
    2269                                     button5.Enabled = true;
    2270                                 }
    2271                                 break;
    2272                             }
    2273                         //预聚集B
    2274                         case 6: {
    2275                                 if (button23.Text == "断电") {
    2276                                     button23_Click(sender, e);
    2277                                     button23.Enabled = true;
    2278                                 }
    2279                                 break;
    2280                             }
    2281                         //预聚集C
    2282                         case 7: {
    2283                                 if (button29.Text == "断电") {
    2284                                     button29_Click(sender, e);
    2285                                     button29.Enabled = true;
    2286                                 }
    2287                                 break;
    2288                             }
    2289                         //偏转
    2290                         case 11: {
    2291                                 if (button4.Text == "断电") {
    2292                                     button4_Click(sender, e);
    2293                                     button4.Enabled = true;
    2294                                 }
    2295                                 break;
    2296                             }
    2297                         //脉冲
    2298                         case 8: {
    2299                                 if (button8.Text == "断电") {
    2300                                     button8_Click(sender, e);
    2301                                     button8.Enabled = true;
    2302                                 }
    2303                                 break;
    2304                             }
    2305                         //整流
    2306                         case 9: {
    2307                                 if (button9.Text == "断电") {
    2308                                     button9_Click(sender, e);
    2309                                     button9.Enabled = true;
    2310                                 }
    2311                                 break;
    2312                             }
    2313                         //主高压
    2314                         case 0: {
    2315                                 if (button11.Text == "断电") {
    2316                                     button11_Click(sender, e);
    2317                                     button11.Enabled = true;
    2318                                 }
    2319                                 break;
    2320                             }
    2321                         default:
    2322                             break;
    2323                     }
    2324                 }
    2325                 #endregion
    2326                 this.button6.Text = "热发射模式加电";
    2327                 for (int i = 0 ; i < cbos.Count ; i++) {
    2328                     cbos[i][i].Enabled = true;
    2329                 }
    2330 
    2331             }
    2332 
    2333         }
    2334         //全选/取消
    2335         private void checkBox1_CheckedChanged(object sender, EventArgs e) {
    2336             if (checkBox1.Checked) {
    2337                 for (int i = 0 ; i < cbos.Count ; i++) {
    2338                     cbos[i][i].Checked = true;
    2339                 }
    2340             } else {
    2341                 for (int i = 0 ; i < cbos.Count ; i++) {
    2342                     cbos[i][i].Checked = false;
    2343                 }
    2344             }
    2345         }
    2346     }
    2347 }
    RFD_Form
  • 相关阅读:
    类库探源——开头
    码的生产——(二维码、条形码)
    java 接口
    Eclipse下修改工程名
    Oracle 查询库中所有表名、字段名、字段名说明,查询表的数据条数、表名、中文表名、
    oracle中SQL根据生日日期查询年龄的方法
    TRUNCATE 删除表,无法回退。默认选择为整个表的内容,所以不能加条件。
    【kettle】window安装与配置
    SQL SELECT语句
    Oracle 查询类似 select top 的用法
  • 原文地址:https://www.cnblogs.com/cykj/p/SCM-control-system.html
Copyright © 2011-2022 走看看