自动化设备上位机设计 十三(完结)

目录

一 设计原型

二 后台代码


一 设计原型

二 后台代码

namespace 自动化上位机设计
{
    partial class Form1
    {
        /// <summary>
        ///  Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        ///  Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        ///  Required method for Designer support - do not modify
        ///  the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
            DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
            DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
            DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
            DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
            DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
            Data = new Sunny.UI.UIDataGridView();
            Column1 = new DataGridViewTextBoxColumn();
            Column2 = new DataGridViewTextBoxColumn();
            Column3 = new DataGridViewTextBoxColumn();
            Column4 = new DataGridViewTextBoxColumn();
            Column5 = new DataGridViewTextBoxColumn();
            Column6 = new DataGridViewTextBoxColumn();
            Column7 = new DataGridViewTextBoxColumn();
            Column8 = new DataGridViewTextBoxColumn();
            Column9 = new DataGridViewTextBoxColumn();
            Column10 = new DataGridViewTextBoxColumn();
            Column11 = new DataGridViewTextBoxColumn();
            Column12 = new DataGridViewTextBoxColumn();
            Column13 = new DataGridViewTextBoxColumn();
            Column14 = new DataGridViewTextBoxColumn();
            Column15 = new DataGridViewTextBoxColumn();
            uiGroupBox1 = new Sunny.UI.UIGroupBox();
            button1 = new Button();
            LJJ = new Sunny.UI.UITextBox();
            SD = new Sunny.UI.UITextBox();
            CC = new Sunny.UI.UITextBox();
            PRESS = new Sunny.UI.UITextBox();
            uiLabel9 = new Sunny.UI.UILabel();
            uiLabel10 = new Sunny.UI.UILabel();
            uiLabel11 = new Sunny.UI.UILabel();
            uiLabel12 = new Sunny.UI.UILabel();
            NZ = new Sunny.UI.UITextBox();
            DY = new Sunny.UI.UITextBox();
            ZY = new Sunny.UI.UITextBox();
            ZL = new Sunny.UI.UITextBox();
            uiLabel5 = new Sunny.UI.UILabel();
            uiLabel6 = new Sunny.UI.UILabel();
            uiLabel7 = new Sunny.UI.UILabel();
            uiLabel8 = new Sunny.UI.UILabel();
            JD = new Sunny.UI.UITextBox();
            GD = new Sunny.UI.UITextBox();
            KD = new Sunny.UI.UITextBox();
            CD = new Sunny.UI.UITextBox();
            uiLabel4 = new Sunny.UI.UILabel();
            uiLabel3 = new Sunny.UI.UILabel();
            uiLabel2 = new Sunny.UI.UILabel();
            uiLabel1 = new Sunny.UI.UILabel();
            Log = new Sunny.UI.UIRichTextBox();
            uiLight1 = new Sunny.UI.UILight();
            uiSwitch1 = new Sunny.UI.UISwitch();
            uiLedDisplay1 = new Sunny.UI.UILedDisplay();
            uiLedDisplay2 = new Sunny.UI.UILedDisplay();
            splitContainer1 = new SplitContainer();
            RunLog = new Sunny.UI.UIRichTextBox();
            ErorrLog = new Sunny.UI.UIRichTextBox();
            timer1 = new System.Windows.Forms.Timer(components);
            ((System.ComponentModel.ISupportInitialize)Data).BeginInit();
            uiGroupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
            splitContainer1.Panel1.SuspendLayout();
            splitContainer1.Panel2.SuspendLayout();
            splitContainer1.SuspendLayout();
            SuspendLayout();
            // 
            // Data
            // 
            dataGridViewCellStyle1.BackColor = Color.Lime;
            Data.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
            Data.BackgroundColor = Color.DarkSeaGreen;
            Data.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
            dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridViewCellStyle2.BackColor = Color.FromArgb(80, 160, 255);
            dataGridViewCellStyle2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            dataGridViewCellStyle2.ForeColor = Color.White;
            dataGridViewCellStyle2.SelectionBackColor = SystemColors.Highlight;
            dataGridViewCellStyle2.SelectionForeColor = SystemColors.HighlightText;
            dataGridViewCellStyle2.WrapMode = DataGridViewTriState.True;
            Data.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
            Data.ColumnHeadersHeight = 32;
            Data.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            Data.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3, Column4, Column5, Column6, Column7, Column8, Column9, Column10, Column11, Column12, Column13, Column14, Column15 });
            dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle3.BackColor = SystemColors.Window;
            dataGridViewCellStyle3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            dataGridViewCellStyle3.ForeColor = SystemColors.ControlText;
            dataGridViewCellStyle3.SelectionBackColor = SystemColors.Highlight;
            dataGridViewCellStyle3.SelectionForeColor = SystemColors.HighlightText;
            dataGridViewCellStyle3.WrapMode = DataGridViewTriState.False;
            Data.DefaultCellStyle = dataGridViewCellStyle3;
            Data.EnableHeadersVisualStyles = false;
            Data.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            Data.GridColor = Color.FromArgb(80, 160, 255);
            Data.Location = new Point(11, 302);
            Data.Margin = new Padding(2, 3, 2, 3);
            Data.Name = "Data";
            Data.RectColor = Color.Red;
            dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle4.BackColor = Color.FromArgb(235, 243, 255);
            dataGridViewCellStyle4.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            dataGridViewCellStyle4.ForeColor = Color.FromArgb(48, 48, 48);
            dataGridViewCellStyle4.SelectionBackColor = Color.FromArgb(80, 160, 255);
            dataGridViewCellStyle4.SelectionForeColor = Color.White;
            dataGridViewCellStyle4.WrapMode = DataGridViewTriState.True;
            Data.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
            Data.RowHeadersWidth = 51;
            dataGridViewCellStyle5.BackColor = Color.FromArgb(0, 192, 0);
            dataGridViewCellStyle5.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            Data.RowsDefaultCellStyle = dataGridViewCellStyle5;
            Data.ScrollBarBackColor = Color.Lime;
            Data.ScrollBarHandleHeight = 22;
            Data.ScrollBarHandleWidth = 22;
            Data.ScrollBarHeight = 22;
            Data.ScrollBarStyleInherited = false;
            Data.ScrollBarWidth = 22;
            Data.SelectedIndex = -1;
            Data.Size = new Size(999, 334);
            Data.StripeEvenColor = Color.FromArgb(0, 192, 0);
            Data.StripeOddColor = Color.Lime;
            Data.TabIndex = 0;
            // 
            // Column1
            // 
            Column1.HeaderText = "长度";
            Column1.MinimumWidth = 6;
            Column1.Name = "Column1";
            Column1.Width = 125;
            // 
            // Column2
            // 
            Column2.HeaderText = "宽度";
            Column2.MinimumWidth = 6;
            Column2.Name = "Column2";
            Column2.Width = 125;
            // 
            // Column3
            // 
            Column3.HeaderText = "高度";
            Column3.MinimumWidth = 6;
            Column3.Name = "Column3";
            Column3.Width = 125;
            // 
            // Column4
            // 
            Column4.HeaderText = "角度";
            Column4.MinimumWidth = 6;
            Column4.Name = "Column4";
            Column4.Width = 125;
            // 
            // Column5
            // 
            Column5.HeaderText = "重量";
            Column5.MinimumWidth = 6;
            Column5.Name = "Column5";
            Column5.Width = 125;
            // 
            // Column6
            // 
            Column6.HeaderText = "噪音";
            Column6.MinimumWidth = 6;
            Column6.Name = "Column6";
            Column6.Width = 125;
            // 
            // Column7
            // 
            Column7.HeaderText = "电压";
            Column7.MinimumWidth = 6;
            Column7.Name = "Column7";
            Column7.Width = 125;
            // 
            // Column8
            // 
            Column8.HeaderText = "内阻";
            Column8.MinimumWidth = 6;
            Column8.Name = "Column8";
            Column8.Width = 125;
            // 
            // Column9
            // 
            Column9.HeaderText = "压力";
            Column9.MinimumWidth = 6;
            Column9.Name = "Column9";
            Column9.Width = 125;
            // 
            // Column10
            // 
            Column10.HeaderText = "温度";
            Column10.MinimumWidth = 6;
            Column10.Name = "Column10";
            Column10.Width = 125;
            // 
            // Column11
            // 
            Column11.HeaderText = "湿度";
            Column11.MinimumWidth = 6;
            Column11.Name = "Column11";
            Column11.Width = 125;
            // 
            // Column12
            // 
            Column12.HeaderText = "力矩";
            Column12.MinimumWidth = 6;
            Column12.Name = "Column12";
            Column12.Width = 125;
            // 
            // Column13
            // 
            Column13.HeaderText = "时间";
            Column13.MinimumWidth = 6;
            Column13.Name = "Column13";
            Column13.Width = 125;
            // 
            // Column14
            // 
            Column14.HeaderText = "总结果";
            Column14.MinimumWidth = 6;
            Column14.Name = "Column14";
            Column14.Width = 125;
            // 
            // Column15
            // 
            Column15.HeaderText = "备注";
            Column15.MinimumWidth = 6;
            Column15.Name = "Column15";
            Column15.Width = 125;
            // 
            // uiGroupBox1
            // 
            uiGroupBox1.BackColor = Color.Beige;
            uiGroupBox1.Controls.Add(button1);
            uiGroupBox1.Controls.Add(LJJ);
            uiGroupBox1.Controls.Add(SD);
            uiGroupBox1.Controls.Add(CC);
            uiGroupBox1.Controls.Add(PRESS);
            uiGroupBox1.Controls.Add(uiLabel9);
            uiGroupBox1.Controls.Add(uiLabel10);
            uiGroupBox1.Controls.Add(uiLabel11);
            uiGroupBox1.Controls.Add(uiLabel12);
            uiGroupBox1.Controls.Add(NZ);
            uiGroupBox1.Controls.Add(DY);
            uiGroupBox1.Controls.Add(ZY);
            uiGroupBox1.Controls.Add(ZL);
            uiGroupBox1.Controls.Add(uiLabel5);
            uiGroupBox1.Controls.Add(uiLabel6);
            uiGroupBox1.Controls.Add(uiLabel7);
            uiGroupBox1.Controls.Add(uiLabel8);
            uiGroupBox1.Controls.Add(JD);
            uiGroupBox1.Controls.Add(GD);
            uiGroupBox1.Controls.Add(KD);
            uiGroupBox1.Controls.Add(CD);
            uiGroupBox1.Controls.Add(uiLabel4);
            uiGroupBox1.Controls.Add(uiLabel3);
            uiGroupBox1.Controls.Add(uiLabel2);
            uiGroupBox1.Controls.Add(uiLabel1);
            uiGroupBox1.FillColor = Color.Gray;
            uiGroupBox1.Font = new Font("宋体", 16.2F, FontStyle.Bold, GraphicsUnit.Point, 134);
            uiGroupBox1.ForeColor = Color.Black;
            uiGroupBox1.Location = new Point(10, 6);
            uiGroupBox1.Margin = new Padding(3, 4, 3, 4);
            uiGroupBox1.MinimumSize = new Size(1, 1);
            uiGroupBox1.Name = "uiGroupBox1";
            uiGroupBox1.Padding = new Padding(0, 32, 0, 0);
            uiGroupBox1.Size = new Size(566, 289);
            uiGroupBox1.TabIndex = 1;
            uiGroupBox1.Text = "参数设置";
            uiGroupBox1.TextAlignment = ContentAlignment.MiddleLeft;
            // 
            // button1
            // 
            button1.Location = new Point(14, 227);
            button1.Name = "button1";
            button1.Size = new Size(124, 46);
            button1.TabIndex = 19;
            button1.Text = "保存参数";
            button1.UseVisualStyleBackColor = true;
            button1.Click += button1_Click;
            // 
            // LJJ
            // 
            LJJ.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            LJJ.Location = new Point(469, 177);
            LJJ.Margin = new Padding(4, 5, 4, 5);
            LJJ.MinimumSize = new Size(1, 16);
            LJJ.Name = "LJJ";
            LJJ.Padding = new Padding(5);
            LJJ.ShowText = false;
            LJJ.Size = new Size(87, 29);
            LJJ.TabIndex = 15;
            LJJ.TagString = "0";
            LJJ.Text = "0";
            LJJ.TextAlignment = ContentAlignment.MiddleLeft;
            LJJ.Watermark = "";
            // 
            // SD
            // 
            SD.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            SD.Location = new Point(469, 131);
            SD.Margin = new Padding(4, 5, 4, 5);
            SD.MinimumSize = new Size(1, 16);
            SD.Name = "SD";
            SD.Padding = new Padding(5);
            SD.ShowText = false;
            SD.Size = new Size(87, 29);
            SD.TabIndex = 16;
            SD.Text = "0";
            SD.TextAlignment = ContentAlignment.MiddleLeft;
            SD.Watermark = "";
            // 
            // CC
            // 
            CC.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            CC.Location = new Point(469, 88);
            CC.Margin = new Padding(4, 5, 4, 5);
            CC.MinimumSize = new Size(1, 16);
            CC.Name = "CC";
            CC.Padding = new Padding(5);
            CC.ShowText = false;
            CC.Size = new Size(87, 29);
            CC.TabIndex = 17;
            CC.Text = "0";
            CC.TextAlignment = ContentAlignment.MiddleLeft;
            CC.Watermark = "";
            // 
            // PRESS
            // 
            PRESS.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            PRESS.Location = new Point(469, 45);
            PRESS.Margin = new Padding(4, 5, 4, 5);
            PRESS.MinimumSize = new Size(1, 16);
            PRESS.Name = "PRESS";
            PRESS.Padding = new Padding(5);
            PRESS.ShowText = false;
            PRESS.Size = new Size(87, 29);
            PRESS.TabIndex = 18;
            PRESS.Text = "0";
            PRESS.TextAlignment = ContentAlignment.MiddleLeft;
            PRESS.Watermark = "";
            // 
            // uiLabel9
            // 
            uiLabel9.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel9.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel9.Location = new Point(389, 177);
            uiLabel9.Name = "uiLabel9";
            uiLabel9.Size = new Size(64, 29);
            uiLabel9.TabIndex = 12;
            uiLabel9.Text = "力矩";
            uiLabel9.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel10
            // 
            uiLabel10.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel10.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel10.Location = new Point(389, 131);
            uiLabel10.Name = "uiLabel10";
            uiLabel10.Size = new Size(64, 29);
            uiLabel10.TabIndex = 13;
            uiLabel10.Text = "湿度";
            uiLabel10.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel11
            // 
            uiLabel11.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel11.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel11.Location = new Point(389, 88);
            uiLabel11.Name = "uiLabel11";
            uiLabel11.Size = new Size(64, 29);
            uiLabel11.TabIndex = 14;
            uiLabel11.Text = "温度";
            uiLabel11.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel12
            // 
            uiLabel12.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel12.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel12.Location = new Point(389, 45);
            uiLabel12.Name = "uiLabel12";
            uiLabel12.Size = new Size(64, 29);
            uiLabel12.TabIndex = 11;
            uiLabel12.Text = "压力";
            uiLabel12.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // NZ
            // 
            NZ.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            NZ.Location = new Point(282, 177);
            NZ.Margin = new Padding(4, 5, 4, 5);
            NZ.MinimumSize = new Size(1, 16);
            NZ.Name = "NZ";
            NZ.Padding = new Padding(5);
            NZ.ShowText = false;
            NZ.Size = new Size(87, 29);
            NZ.TabIndex = 7;
            NZ.Text = "0";
            NZ.TextAlignment = ContentAlignment.MiddleLeft;
            NZ.Watermark = "";
            // 
            // DY
            // 
            DY.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            DY.Location = new Point(282, 131);
            DY.Margin = new Padding(4, 5, 4, 5);
            DY.MinimumSize = new Size(1, 16);
            DY.Name = "DY";
            DY.Padding = new Padding(5);
            DY.ShowText = false;
            DY.Size = new Size(87, 29);
            DY.TabIndex = 8;
            DY.Text = "0";
            DY.TextAlignment = ContentAlignment.MiddleLeft;
            DY.Watermark = "";
            // 
            // ZY
            // 
            ZY.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            ZY.Location = new Point(282, 88);
            ZY.Margin = new Padding(4, 5, 4, 5);
            ZY.MinimumSize = new Size(1, 16);
            ZY.Name = "ZY";
            ZY.Padding = new Padding(5);
            ZY.ShowText = false;
            ZY.Size = new Size(87, 29);
            ZY.TabIndex = 9;
            ZY.Text = "0";
            ZY.TextAlignment = ContentAlignment.MiddleLeft;
            ZY.Watermark = "";
            // 
            // ZL
            // 
            ZL.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            ZL.Location = new Point(282, 45);
            ZL.Margin = new Padding(4, 5, 4, 5);
            ZL.MinimumSize = new Size(1, 16);
            ZL.Name = "ZL";
            ZL.Padding = new Padding(5);
            ZL.ShowText = false;
            ZL.Size = new Size(87, 29);
            ZL.TabIndex = 10;
            ZL.Text = "0";
            ZL.TextAlignment = ContentAlignment.MiddleLeft;
            ZL.Watermark = "";
            // 
            // uiLabel5
            // 
            uiLabel5.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel5.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel5.Location = new Point(202, 177);
            uiLabel5.Name = "uiLabel5";
            uiLabel5.Size = new Size(64, 29);
            uiLabel5.TabIndex = 4;
            uiLabel5.Text = "内阻";
            uiLabel5.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel6
            // 
            uiLabel6.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel6.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel6.Location = new Point(202, 131);
            uiLabel6.Name = "uiLabel6";
            uiLabel6.Size = new Size(64, 29);
            uiLabel6.TabIndex = 5;
            uiLabel6.Text = "电压";
            uiLabel6.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel7
            // 
            uiLabel7.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel7.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel7.Location = new Point(202, 88);
            uiLabel7.Name = "uiLabel7";
            uiLabel7.Size = new Size(64, 29);
            uiLabel7.TabIndex = 6;
            uiLabel7.Text = "噪音";
            uiLabel7.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel8
            // 
            uiLabel8.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel8.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel8.Location = new Point(202, 45);
            uiLabel8.Name = "uiLabel8";
            uiLabel8.Size = new Size(64, 29);
            uiLabel8.TabIndex = 3;
            uiLabel8.Text = "重量";
            uiLabel8.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // JD
            // 
            JD.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            JD.Location = new Point(94, 177);
            JD.Margin = new Padding(4, 5, 4, 5);
            JD.MinimumSize = new Size(1, 16);
            JD.Name = "JD";
            JD.Padding = new Padding(5);
            JD.ShowText = false;
            JD.Size = new Size(87, 29);
            JD.TabIndex = 2;
            JD.Text = "0";
            JD.TextAlignment = ContentAlignment.MiddleLeft;
            JD.Watermark = "";
            // 
            // GD
            // 
            GD.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            GD.Location = new Point(94, 131);
            GD.Margin = new Padding(4, 5, 4, 5);
            GD.MinimumSize = new Size(1, 16);
            GD.Name = "GD";
            GD.Padding = new Padding(5);
            GD.ShowText = false;
            GD.Size = new Size(87, 29);
            GD.TabIndex = 2;
            GD.Text = "0";
            GD.TextAlignment = ContentAlignment.MiddleLeft;
            GD.Watermark = "";
            // 
            // KD
            // 
            KD.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            KD.Location = new Point(94, 88);
            KD.Margin = new Padding(4, 5, 4, 5);
            KD.MinimumSize = new Size(1, 16);
            KD.Name = "KD";
            KD.Padding = new Padding(5);
            KD.ShowText = false;
            KD.Size = new Size(87, 29);
            KD.TabIndex = 2;
            KD.Text = "0";
            KD.TextAlignment = ContentAlignment.MiddleLeft;
            KD.Watermark = "";
            // 
            // CD
            // 
            CD.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            CD.Location = new Point(94, 45);
            CD.Margin = new Padding(4, 5, 4, 5);
            CD.MinimumSize = new Size(1, 16);
            CD.Name = "CD";
            CD.Padding = new Padding(5);
            CD.ShowText = false;
            CD.Size = new Size(87, 29);
            CD.TabIndex = 2;
            CD.Text = "0";
            CD.TextAlignment = ContentAlignment.MiddleLeft;
            CD.Watermark = "";
            // 
            // uiLabel4
            // 
            uiLabel4.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel4.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel4.Location = new Point(14, 177);
            uiLabel4.Name = "uiLabel4";
            uiLabel4.Size = new Size(64, 29);
            uiLabel4.TabIndex = 1;
            uiLabel4.Text = "角度";
            uiLabel4.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel3
            // 
            uiLabel3.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel3.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel3.Location = new Point(14, 131);
            uiLabel3.Name = "uiLabel3";
            uiLabel3.Size = new Size(64, 29);
            uiLabel3.TabIndex = 1;
            uiLabel3.Text = "高度";
            uiLabel3.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel2
            // 
            uiLabel2.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel2.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel2.Location = new Point(14, 88);
            uiLabel2.Name = "uiLabel2";
            uiLabel2.Size = new Size(64, 29);
            uiLabel2.TabIndex = 1;
            uiLabel2.Text = "宽度";
            uiLabel2.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // uiLabel1
            // 
            uiLabel1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLabel1.ForeColor = Color.FromArgb(48, 48, 48);
            uiLabel1.Location = new Point(14, 45);
            uiLabel1.Name = "uiLabel1";
            uiLabel1.Size = new Size(64, 29);
            uiLabel1.TabIndex = 0;
            uiLabel1.Text = "长度";
            uiLabel1.TextAlign = ContentAlignment.MiddleLeft;
            // 
            // Log
            // 
            Log.FillColor = Color.FromArgb(255, 224, 192);
            Log.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            Log.Location = new Point(10, 643);
            Log.Margin = new Padding(3, 4, 3, 4);
            Log.MinimumSize = new Size(1, 1);
            Log.Name = "Log";
            Log.Padding = new Padding(2);
            Log.ScrollBarStyleInherited = false;
            Log.ShowText = false;
            Log.Size = new Size(1000, 92);
            Log.TabIndex = 2;
            Log.TextAlignment = ContentAlignment.MiddleCenter;
            // 
            // uiLight1
            // 
            uiLight1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiLight1.Location = new Point(976, 2);
            uiLight1.Margin = new Padding(2, 3, 2, 3);
            uiLight1.MinimumSize = new Size(1, 1);
            uiLight1.Name = "uiLight1";
            uiLight1.OnColor = Color.FromArgb(224, 224, 224);
            uiLight1.Radius = 34;
            uiLight1.Size = new Size(34, 37);
            uiLight1.TabIndex = 3;
            uiLight1.Text = "uiLight1";
            // 
            // uiSwitch1
            // 
            uiSwitch1.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            uiSwitch1.Location = new Point(898, 6);
            uiSwitch1.Margin = new Padding(2, 3, 2, 3);
            uiSwitch1.MinimumSize = new Size(1, 1);
            uiSwitch1.Name = "uiSwitch1";
            uiSwitch1.Size = new Size(73, 31);
            uiSwitch1.TabIndex = 4;
            uiSwitch1.Text = "uiSwitch1";
            uiSwitch1.ValueChanged += uiSwitch1_ValueChanged;
            // 
            // uiLedDisplay1
            // 
            uiLedDisplay1.BackColor = Color.Transparent;
            uiLedDisplay1.BorderColor = Color.White;
            uiLedDisplay1.BorderInColor = Color.Transparent;
            uiLedDisplay1.ForeColor = Color.Red;
            uiLedDisplay1.LedBackColor = Color.Silver;
            uiLedDisplay1.Location = new Point(693, 8);
            uiLedDisplay1.Margin = new Padding(2, 3, 2, 3);
            uiLedDisplay1.Name = "uiLedDisplay1";
            uiLedDisplay1.Size = new Size(201, 34);
            uiLedDisplay1.TabIndex = 5;
            uiLedDisplay1.Text = "22:53:00";
            // 
            // uiLedDisplay2
            // 
            uiLedDisplay2.BackColor = Color.Black;
            uiLedDisplay2.BorderColor = Color.Transparent;
            uiLedDisplay2.BorderInColor = Color.Transparent;
            uiLedDisplay2.ForeColor = Color.Lime;
            uiLedDisplay2.LedBackColor = Color.Gray;
            uiLedDisplay2.Location = new Point(584, 6);
            uiLedDisplay2.Margin = new Padding(2, 3, 2, 3);
            uiLedDisplay2.Name = "uiLedDisplay2";
            uiLedDisplay2.Size = new Size(105, 34);
            uiLedDisplay2.TabIndex = 6;
            uiLedDisplay2.Text = "0";
            // 
            // splitContainer1
            // 
            splitContainer1.Location = new Point(581, 45);
            splitContainer1.Margin = new Padding(2, 3, 2, 3);
            splitContainer1.Name = "splitContainer1";
            // 
            // splitContainer1.Panel1
            // 
            splitContainer1.Panel1.Controls.Add(RunLog);
            // 
            // splitContainer1.Panel2
            // 
            splitContainer1.Panel2.Controls.Add(ErorrLog);
            splitContainer1.Size = new Size(429, 250);
            splitContainer1.SplitterDistance = 210;
            splitContainer1.SplitterWidth = 3;
            splitContainer1.TabIndex = 7;
            // 
            // RunLog
            // 
            RunLog.FillColor = Color.FromArgb(0, 192, 0);
            RunLog.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            RunLog.Location = new Point(3, 4);
            RunLog.Margin = new Padding(3, 4, 3, 4);
            RunLog.MinimumSize = new Size(1, 1);
            RunLog.Name = "RunLog";
            RunLog.Padding = new Padding(2);
            RunLog.ScrollBarStyleInherited = false;
            RunLog.ShowText = false;
            RunLog.Size = new Size(204, 242);
            RunLog.TabIndex = 0;
            RunLog.TextAlignment = ContentAlignment.MiddleCenter;
            // 
            // ErorrLog
            // 
            ErorrLog.FillColor = Color.Fuchsia;
            ErorrLog.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
            ErorrLog.Location = new Point(3, 4);
            ErorrLog.Margin = new Padding(3, 4, 3, 4);
            ErorrLog.MinimumSize = new Size(1, 1);
            ErorrLog.Name = "ErorrLog";
            ErorrLog.Padding = new Padding(2);
            ErorrLog.ScrollBarStyleInherited = false;
            ErorrLog.ShowText = false;
            ErorrLog.Size = new Size(210, 242);
            ErorrLog.TabIndex = 1;
            ErorrLog.TextAlignment = ContentAlignment.MiddleCenter;
            // 
            // timer1
            // 
            timer1.Interval = 1000;
            // 
            // Form1
            // 
            AutoScaleDimensions = new SizeF(7F, 17F);
            AutoScaleMode = AutoScaleMode.Font;
            BackColor = Color.Black;
            ClientSize = new Size(1031, 748);
            Controls.Add(splitContainer1);
            Controls.Add(uiLedDisplay2);
            Controls.Add(uiLedDisplay1);
            Controls.Add(uiSwitch1);
            Controls.Add(uiLight1);
            Controls.Add(Log);
            Controls.Add(uiGroupBox1);
            Controls.Add(Data);
            FormBorderStyle = FormBorderStyle.FixedSingle;
            Margin = new Padding(2, 3, 2, 3);
            MaximizeBox = false;
            Name = "Form1";
            Text = "上位机";
            Load += Form1_Load;
            ((System.ComponentModel.ISupportInitialize)Data).EndInit();
            uiGroupBox1.ResumeLayout(false);
            splitContainer1.Panel1.ResumeLayout(false);
            splitContainer1.Panel2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
            splitContainer1.ResumeLayout(false);
            ResumeLayout(false);
        }

        #endregion

        private Sunny.UI.UIDataGridView Data;
        private Sunny.UI.UIGroupBox uiGroupBox1;
        private Sunny.UI.UIRichTextBox Log;
        private Sunny.UI.UILight uiLight1;
        private Sunny.UI.UISwitch uiSwitch1;
        private Sunny.UI.UILedDisplay uiLedDisplay1;
        private Sunny.UI.UILedDisplay uiLedDisplay2;
        private SplitContainer splitContainer1;
        private Sunny.UI.UITextBox CD;
        private Sunny.UI.UILabel uiLabel4;
        private Sunny.UI.UILabel uiLabel3;
        private Sunny.UI.UILabel uiLabel2;
        private Sunny.UI.UILabel uiLabel1;
        private Sunny.UI.UITextBox JD;
        private Sunny.UI.UITextBox GD;
        private Sunny.UI.UITextBox KD;
        private Sunny.UI.UITextBox LJJ;
        private Sunny.UI.UITextBox SD;
        private Sunny.UI.UITextBox CC;
        private Sunny.UI.UITextBox PRESS;
        private Sunny.UI.UILabel uiLabel9;
        private Sunny.UI.UILabel uiLabel10;
        private Sunny.UI.UILabel uiLabel11;
        private Sunny.UI.UILabel uiLabel12;
        private Sunny.UI.UITextBox NZ;
        private Sunny.UI.UITextBox DY;
        private Sunny.UI.UITextBox ZY;
        private Sunny.UI.UITextBox ZL;
        private Sunny.UI.UILabel uiLabel5;
        private Sunny.UI.UILabel uiLabel6;
        private Sunny.UI.UILabel uiLabel7;
        private Sunny.UI.UILabel uiLabel8;
        private Sunny.UI.UIRichTextBox RunLog;
        private Sunny.UI.UIRichTextBox ErorrLog;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewTextBoxColumn Column6;
        private DataGridViewTextBoxColumn Column7;
        private DataGridViewTextBoxColumn Column8;
        private DataGridViewTextBoxColumn Column9;
        private DataGridViewTextBoxColumn Column10;
        private DataGridViewTextBoxColumn Column11;
        private DataGridViewTextBoxColumn Column12;
        private DataGridViewTextBoxColumn Column13;
        private DataGridViewTextBoxColumn Column14;
        private DataGridViewTextBoxColumn Column15;
        private System.Windows.Forms.Timer timer1;
        private Button button1;
    }
}
using SqlSugar;

namespace 自动化上位机设计
{

    //实体与数据库结构一样
    //数据是自增需要加上IsIdentity
    //数据库是主键需要加上IsPrimaryKey
    //注意:要完全和数据库一致2个属性
    [SugarTable("EntryClass")]
    public class EntryClass
    {
        public string Len { get; set; }
        public string Width { get; set; }
        public string Hight { get; set; }
        public string R { get; set; }

        public string Weit { get; set; }
        public string ZY { get; set; }
        public string DC { get; set; }
        public string DR { get; set; }

        public string YL { get; set; }
        public string WD { get; set; }
        public string SD { get; set; }
        public string LJ { get; set; }
    }
}
using SqlSugar;

namespace 自动化上位机设计
{
    public class SqlHelper
    {

        public SqlSugarClient db = GetSql();

        /// <summary>
        /// 获得数据库对象
        /// </summary>
        /// <returns></returns>
        private static SqlSugarClient GetSql()
        {
            string FilePath = Environment.CurrentDirectory + @"\Config\Data.db";
            SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = $"Data Source={FilePath}", // SQLite 连接字符串
                DbType = DbType.Sqlite, // 指定数据库类型为 SQLite
                IsAutoCloseConnection = true, // 自动关闭连接
                InitKeyType = InitKeyType.Attribute//从实体特性中读取主键自增列信息
            });

            // 创建数据库
            db.DbMaintenance.CreateDatabase();

            return db;
        }


        /// <summary>
        /// 创建数据表
        /// </summary>
        public void CreateTable<T>()
        {
            //两种方法都能创建表
            //db.CodeFirst.InitTables(typeof(Student));
            db.CodeFirst.InitTables<T>();
        }


    }
}
using Newtonsoft.Json;
using SimpleTCP;
using SqlSugar;
using System.IO.Ports;
using System.Text;

namespace 自动化上位机设计
{
    public partial class Form1 : Form
    {


        SqlHelper sqlHelper = new SqlHelper();
        SqlSugarClient dbContent = null;
        bool IsRun = false;
        int Count = 0;

        //数据收集对象
        EntryClass Datas = new EntryClass();

        //网络通讯客户端:长度测试仪器
        SimpleTcpClient client = new SimpleTcpClient(); //设备1
        SimpleTcpClient client2 = new SimpleTcpClient();//设备2
        SimpleTcpClient client3 = new SimpleTcpClient();//设备3
        SimpleTcpClient client4 = new SimpleTcpClient();//设备4       

        //串口设备
        SerialPort serialPort = new SerialPort();
        SerialPort serialPort2 = new SerialPort();
        SerialPort serialPort3 = new SerialPort();
        SerialPort serialPort4 = new SerialPort();

        //网络服务端设备
        SimpleTcpServer server = new SimpleTcpServer();
        SimpleTcpServer server2 = new SimpleTcpServer();
        SimpleTcpServer server3 = new SimpleTcpServer();
        SimpleTcpServer server4 = new SimpleTcpServer();

        public Form1()
        {
            InitializeComponent();




            dbContent = sqlHelper.db;

            timer1.Enabled = true;
            timer1.Tick += Timer1_Tick;

            Task.Run(() =>
            {
                //设置编码格式,默认是UTF8
                client.StringEncoder = System.Text.ASCIIEncoding.UTF8;
                //设置分隔符,默认是0x13
                client.Delimiter = Encoding.ASCII.GetBytes("\r")[0];


                //设置编码格式,默认是UTF8
                client2.StringEncoder = System.Text.ASCIIEncoding.UTF8;
                //设置分隔符,默认是0x13
                client2.Delimiter = Encoding.ASCII.GetBytes("\r")[0];


                //设置编码格式,默认是UTF8
                client3.StringEncoder = System.Text.ASCIIEncoding.UTF8;
                //设置分隔符,默认是0x13
                client3.Delimiter = Encoding.ASCII.GetBytes("\r")[0];


                //设置编码格式,默认是UTF8
                client4.StringEncoder = System.Text.ASCIIEncoding.UTF8;
                //设置分隔符,默认是0x13
                client4.Delimiter = Encoding.ASCII.GetBytes("\r")[0];


                //初始化串口设备
                serialPort.PortName = "COM1";
                serialPort.BaudRate = 115200;
                serialPort.Parity = Parity.None;
                serialPort.DataBits = 8;
                serialPort.StopBits = StopBits.One;
                serialPort.DataReceived += (a, b) =>
                {
                    byte[] buffer = new byte[1024];
                    serialPort.Read(buffer, 0, buffer.Length);
                    string data = Encoding.UTF8.GetString(buffer);
                    //重量
                    Datas.Weit = data;
                };
                //初始化串口设备
                serialPort2.PortName = "COM3";
                serialPort2.BaudRate = 115200;
                serialPort2.Parity = Parity.None;
                serialPort2.DataBits = 8;
                serialPort2.StopBits = StopBits.One;
                serialPort2.DataReceived += (a, b) =>
                {
                    byte[] buffer = new byte[1024];
                    serialPort.Read(buffer, 0, buffer.Length);
                    string data = Encoding.UTF8.GetString(buffer);
                    //噪音
                    Datas.ZY = data;
                };
                //初始化串口设备
                serialPort3.PortName = "COM5";
                serialPort3.BaudRate = 115200;
                serialPort3.Parity = Parity.None;
                serialPort3.DataBits = 8;
                serialPort3.StopBits = StopBits.One;
                serialPort3.DataReceived += (a, b) =>
                {
                    byte[] buffer = new byte[1024];
                    serialPort.Read(buffer, 0, buffer.Length);
                    string data = Encoding.UTF8.GetString(buffer);
                    //电压
                    Datas.DC = data;
                };
                //初始化串口设备
                serialPort4.PortName = "COM7";
                serialPort4.BaudRate = 115200;
                serialPort4.Parity = Parity.None;
                serialPort4.DataBits = 8;
                serialPort4.StopBits = StopBits.One;
                serialPort4.DataReceived += (a, b) =>
                {
                    byte[] buffer = new byte[1024];
                    serialPort.Read(buffer, 0, buffer.Length);
                    string data = Encoding.UTF8.GetString(buffer);
                    //内阻
                    Datas.DR = data;
                };



                //收到分割数据的事件,遇到分隔符就会触发事件
                client.DelimiterDataReceived += (sender, msg) =>
                {
                    AddLog("DelimiterStr-" + DateTime.Now.ToString() + msg.MessageString);
                };

                //收到数据的事件,可以在这里实现自己的协议
                client.DataReceived += (sender, msg) =>
                {
                    //字节数组
                    AddLog("字节数组Data:" + BitConverter.ToString(msg.Data));
                    //字符串消息
                    AddLog("字符串消息RDataseivedStr:" + msg.MessageString);

                    //记录长度数据
                    Datas.Len = msg.MessageString;
                };



                //收到分割数据的事件,遇到分隔符就会触发事件
                client2.DelimiterDataReceived += (sender, msg) =>
                {
                    AddLog("DelimiterStr-" + DateTime.Now.ToString() + msg.MessageString);
                };

                //收到数据的事件,可以在这里实现自己的协议
                client2.DataReceived += (sender, msg) =>
                {
                    //字节数组
                    AddLog("字节数组Data:" + BitConverter.ToString(msg.Data));
                    //字符串消息
                    AddLog("字符串消息RDataseivedStr:" + msg.MessageString);

                    //记录长度数据
                    Datas.Width = msg.MessageString;
                };



                //收到分割数据的事件,遇到分隔符就会触发事件
                client3.DelimiterDataReceived += (sender, msg) =>
                {
                    AddLog("DelimiterStr-" + DateTime.Now.ToString() + msg.MessageString);
                };

                //收到数据的事件,可以在这里实现自己的协议
                client3.DataReceived += (sender, msg) =>
                {
                    //字节数组
                    AddLog("字节数组Data:" + BitConverter.ToString(msg.Data));
                    //字符串消息
                    AddLog("字符串消息RDataseivedStr:" + msg.MessageString);

                    //记录长度数据
                    Datas.Hight = msg.MessageString;
                };




                //收到分割数据的事件,遇到分隔符就会触发事件
                client4.DelimiterDataReceived += (sender, msg) =>
                {
                    AddLog("DelimiterStr-" + DateTime.Now.ToString() + msg.MessageString);
                };

                //收到数据的事件,可以在这里实现自己的协议
                client4.DataReceived += (sender, msg) =>
                {
                    //字节数组
                    AddLog("字节数组Data:" + BitConverter.ToString(msg.Data));
                    //字符串消息
                    AddLog("字符串消息RDataseivedStr:" + msg.MessageString);

                    //记录数据
                    Datas.R = msg.MessageString;
                };



                //收到分割数据的事件,遇到分隔符就会触发事件
                server.DelimiterDataReceived += (sender, msg) =>
                {
                    AddLog("DelimiterStr-" + DateTime.Now.ToString() + msg.MessageString);
                };

                //收到数据的事件,可以在这里实现自己的协议
                server.DataReceived += (sender, msg) =>
                {
                    //字节数组
                    AddLog("字节数组Data:" + BitConverter.ToString(msg.Data));
                    //字符串消息
                    AddLog("字符串消息RDataseivedStr:" + msg.MessageString);

                    //记录数据
                    Datas.YL = msg.MessageString;
                };
                //收到分割数据的事件,遇到分隔符就会触发事件
                server2.DelimiterDataReceived += (sender, msg) =>
                {
                    AddLog("DelimiterStr-" + DateTime.Now.ToString() + msg.MessageString);
                };

                //收到数据的事件,可以在这里实现自己的协议
                server2.DataReceived += (sender, msg) =>
                {
                    //字节数组
                    AddLog("字节数组Data:" + BitConverter.ToString(msg.Data));
                    //字符串消息
                    AddLog("字符串消息RDataseivedStr:" + msg.MessageString);

                    //记录数据
                    Datas.WD = msg.MessageString;
                };
                //收到分割数据的事件,遇到分隔符就会触发事件
                server3.DelimiterDataReceived += (sender, msg) =>
                {
                    AddLog("DelimiterStr-" + DateTime.Now.ToString() + msg.MessageString);
                };

                //收到数据的事件,可以在这里实现自己的协议
                server3.DataReceived += (sender, msg) =>
                {
                    //字节数组
                    AddLog("字节数组Data:" + BitConverter.ToString(msg.Data));
                    //字符串消息
                    AddLog("字符串消息RDataseivedStr:" + msg.MessageString);

                    //记录数据
                    Datas.SD = msg.MessageString;
                };
                //收到分割数据的事件,遇到分隔符就会触发事件
                server4.DelimiterDataReceived += (sender, msg) =>
                {
                    AddLog("DelimiterStr-" + DateTime.Now.ToString() + msg.MessageString);
                };

                //收到数据的事件,可以在这里实现自己的协议
                server4.DataReceived += (sender, msg) =>
                {
                    //字节数组
                    AddLog("字节数组Data:" + BitConverter.ToString(msg.Data));
                    //字符串消息
                    AddLog("字符串消息RDataseivedStr:" + msg.MessageString);

                    //记录数据
                    Datas.LJ = msg.MessageString;
                };


                try
                {

                    client.Connect("127.0.0.1", 8899);
                    client2.Connect("127.0.0.1", 8899);
                    client3.Connect("127.0.0.1", 8899);
                    client4.Connect("127.0.0.1", 8899);
                    serialPort.Open();
                    serialPort2.Open();
                    serialPort3.Open();
                    serialPort4.Open();
                    server.Start(9900);
                    server.Start(9901);
                    server.Start(9902);
                    server.Start(9903);
                }
                catch (Exception)
                {

                }
            });
        }

        private void Timer1_Tick(object? sender, EventArgs e)
        {
            this.Invoke(() =>
            {
                uiLedDisplay1.Text = DateTime.Now.ToString("HH:mm:ss");
            });
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            try
            {
                string json = File.ReadAllText(path);
                EntryClass? data = JsonConvert.DeserializeObject<EntryClass>(json);
                if (data != null)
                {
                    //加载参数
                    CD.Text = data.Len;
                    KD.Text = data.Width;
                    GD.Text = data.Hight;
                    JD.Text = data.R;
                    ZL.Text = data.Weit;
                    ZY.Text = data.ZY;
                    DY.Text = data.DC;
                    NZ.Text = data.DR;
                    PRESS.Text = data.YL;
                    CC.Text = data.WD;
                    SD.Text = data.SD;
                    LJJ.Text = data.LJ;
                }
            }
            catch (Exception ex)
            {

            }

            sqlHelper.CreateTable<EntryClass>();

            //开始批量插入数据
            Task.Run(() => { AddData(); });
        }

        private void AddData()
        {

            while (true)
            {
                if (!IsRun) continue;

                //Datas.Len = new Random().Next(200, 300).ToString();
                //Datas.Width = new Random().Next(40, 300).ToString();
                //Datas.Hight = new Random().Next(150, 250).ToString();

                // Datas.R = new Random().Next(10, 360).ToString();
                // Datas.Weit = new Random().Next(20, 30).ToString();
                //Datas.ZY = new Random().Next(50, 90).ToString();
                //Datas.DC = new Random().Next(40, 300).ToString();
                //Datas.DR = new Random().Next(400, 600).ToString();
                //Datas.YL = new Random().Next(28, 88).ToString();
                //Datas.WD = new Random().Next(89, 900).ToString();
                //Datas.SD = new Random().Next(234, 454).ToString();
                //Datas.LJ = new Random().Next(67, 89).ToString();

                //没有测量长度则不增加数据
                if (string.IsNullOrEmpty(Datas.Len) || string.IsNullOrEmpty(Datas.Width)
                    || string.IsNullOrWhiteSpace(Datas.Hight) || string.IsNullOrWhiteSpace(Datas.R) ||
                    string.IsNullOrWhiteSpace(Datas.Weit) || string.IsNullOrWhiteSpace(Datas.ZY) ||
                     string.IsNullOrWhiteSpace(Datas.DC) || string.IsNullOrWhiteSpace(Datas.DR) ||
                      string.IsNullOrWhiteSpace(Datas.YL) || string.IsNullOrWhiteSpace(Datas.WD) ||
                       string.IsNullOrWhiteSpace(Datas.SD) || string.IsNullOrWhiteSpace(Datas.LJ)) continue;

                //数据放入数据库中
                dbContent.Insertable(Datas).ExecuteCommand();

                this.Invoke(() =>
                {


                    //参数展示到集合中
                    Data.Rows.Add(Datas.Len, Datas.Width, Datas.Hight, Datas.R, Datas.Weit, Datas.ZY,
                        Datas.DC, Datas.DR, Datas.YL, Datas.WD, Datas.SD, Datas.LJ,
                        DateTime.Now.ToShortTimeString(), "OK", "测试数据");

                    //计数
                    Count++;
                    uiLedDisplay2.Text = Count.ToString();

                    //打印日志
                    RunLog.AppendText("设备运行中,数据已加入到数据库\r\n");
                    ErorrLog.AppendText("设备运行中,数据已加入到数据库\r\n");
                    Log.AppendText("设备运行中,数据已加入到数据库\r\n");

                    //清空已经记录的数据
                    Datas.Len = "";
                    Datas.Width = "";
                    Datas.Hight = "";
                    Datas.R = "";
                    Datas.Weit = "";
                    Datas.ZY = "";
                    Datas.DC = "";
                    Datas.DR = "";
                    Datas.YL = "";
                    Datas.WD = "";
                    Datas.SD = "";
                    Datas.LJ = "";

                });

                Thread.Sleep(2000);
            }
        }

        private void uiSwitch1_ValueChanged(object sender, bool value)
        {
            if (uiSwitch1.Active)
            {
                uiLight1.OnColor = Color.Green;
                IsRun = true;
                RunLog.AppendText("设备启动。。。\r\n");
                ErorrLog.AppendText("设备启动。。。\r\n");
                Log.AppendText("设备启动。。。\r\n");
            }
            else
            {
                uiLight1.OnColor = Color.Red;
                IsRun = false;
                RunLog.AppendText("设备停止。。。\r\n");
                ErorrLog.AppendText("设备停止。。。\r\n");
                Log.AppendText("设备停止。。。\r\n");
            }
        }



        private void AddLog(string msg)
        {
            this.Invoke(() =>
            {
                //打印日志
                RunLog.AppendText($"{msg}\r\n");
                ErorrLog.AppendText($"{msg}\r\n");
                Log.AppendText($"{msg}\r\n");
            });
        }


        private string path = Directory.GetCurrentDirectory() + "/Para.json";
        private void button1_Click(object sender, EventArgs e)
        {

            //加载参数
            EntryClass data = new EntryClass();
            data.Len = CD.Text;
            data.Width = KD.Text;
            data.Hight = GD.Text;
            data.R = JD.Text;
            data.Weit = ZL.Text;
            data.ZY = ZY.Text;
            data.DC = DY.Text;
            data.DR = NZ.Text;
            data.YL = PRESS.Text;
            data.WD = CC.Text;
            data.SD = SD.Text;
            data.LJ = LJJ.Text;

            string json = JsonConvert.SerializeObject(data);
            File.WriteAllText(path, json);
        }
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

code_shenbing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值