电视剧
c winform(C# WinForm对接PLC实现数据采集)

一、效果展示

主界面

C# WinForm对接PLC实现数据采集nerror="javascript:errorimg.call(this);">

实时记录

C# WinForm对接PLC实现数据采集nerror="javascript:errorimg.call(this);">

历史记录


C# WinForm对接PLC实现数据采集nerror="javascript:errorimg.call(this);">

二、VS2022


界面设计


C# WinForm对接PLC实现数据采集nerror="javascript:errorimg.call(this);">

引用HslCommunication



引用System.Data.SQLite


C# WinForm对接PLC实现数据采集nerror="javascript:errorimg.call(this);">

三、代码展示

Form1.cs

using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.ComponentModel;using System.Data;using System.Data.Common;using System.Data.Odbc;using System.Data.SqlClient;using System.Data.SQLite;using System.Diagnostics;using System.Drawing;using System.IO;using System.Linq;using System.Runtime.InteropServices;using System.Text;using System.Text.Regularexpressions;using System.Threading;using System.Threading.Tasks;using System.Windows.Forms;using System.Windows.Forms.DataVisualization.Charting;using HslCommunication;using HslCommunication.Basicframework;using HslCommunication.Profinet.Siemens;using 自定图标类;using static System.Net.Mime.MediaTypeNames;using static System.Windows.Forms.VisualStyles.VisualStyleElement;namespace PLC数据采集{    public partial class Form1 : Form    {        #region 通信字段        SiemensS7Net SimaticS7Net;        #endregion        #region 图表字段        List<Chart> charts= new List<Chart>();        List<chartClass> chartClasses= new List<chartClass>();        List<string> st = new List<string>();        List<string> type = new List<string>();        List<int> ints= new List<int>();        #endregion        int[] 值;        bool 停止 = true;        List<List<int>> 总点 = new List<List<int>>();//历史显示的列表        //新建一个需要连接的数据库        SQLiteConnection  实时数据库连接 = new SQLiteConnection();        List<string> 表单名 = new List<string>();        List<chartClass> 历史图表列表 = new List<chartClass>();        List<Chart> 历史图表 = new List<Chart>();        SQLiteConnection 历史数据库;//新建数据库连接对象        public Form1()        {            InitializeComponent();            //Control.CheckForIllegalCrossThreadCalls = false;        }        private void 连接_Click(object sender, EventArgs e)        {            SimaticS7Net = new SiemensS7Net(SiemensPLCS.S1500, IP地址.Text);//设定连接目标            OperateResult connect = SimaticS7Net.ConnectServer();//建立长连接            //判断是否长连接成功            if (connect.IsSuccess)            {                连接btn.Enabled= false;                断开btn.Enabled = true;                //MessageBox.Show(StringResources.Language.ConnectedSuccess);            }            else            {                MessageBox.Show(StringResources.Language.ConnectedFailed);            }        }        private void 断开_Click(object sender, EventArgs e)        {            OperateResult connect = SimaticS7Net.ConnectClose();            if (connect.IsSuccess)            {                连接btn.Enabled = true;                断开btn.Enabled = false;                MessageBox.Show("断开成功");            }            else            {                MessageBox.Show("断开失败");            }        }        private void 保存_Click(object sender, EventArgs e)        {            保存dataview();        }        private void 启动btn_Click(object sender, EventArgs e)        {            type.Clear();            st.Clear();            启动btn.Enabled = false;            停止 = false;            //获取DataGridView中每行的数据            st.Clear();            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)            {                st.Add(dataGridView1.Rows[i].Cells[0].Value.ToString());                type.Add(dataGridView1.Rows[i].Cells[1].Value.ToString());            }            tabPage5.Controls.Clear();            charts.Clear();            for (int i = 0; i < st.Count; i++)            {                chartClass c = new chartClass(st[i], type[i]);                chartClasses.Add(c);                charts.Add(c.返回图表());                charts[i].Dock = DockStyle.Top;                tabPage5.Controls.Add(charts[i]);            }            值 = new int[st.Count];            for (int i = 0; i < st.Count; i++)            {                Thread TH = new Thread(获取数据);                TH.Name = i.ToString();                TH.Start();            }            Task tsk2 = new Task(实时图表);            tsk2.Start();            #region 写入数据库            连接数据库();            //新建表单            for (int i = 0; i < st.Count; i++)            {                SQLiteCommand command = new SQLiteCommand();//新建命令对象                SQLiteTransaction sqltra = 实时数据库连接.BeginTransaction();                string 表单名 = st[i] + @";" + type[i];                command.Connection = 实时数据库连接;                command.CommandText = "CREATE TABLE \"" + 表单名 + "\" (序号 INTEGER, 值 INTEGER, PRIMARY KEY(序号));";                command.ExecuteNonQuery();                sqltra.Commit();                command.Dispose();            }            Task.Run(循环写入数据库);            //循环写入数据库();            //for (int i = 0; i < st.Count; i++)            //{            //    Thread sa = new Thread(循环写入数据库);            //    sa.Name = i.ToString();            //    sa.Start();            //}            #endregion        }        void 实时图表()        {            while (!停止)            {                Thread.Sleep(1);                int I = 0;                if (值.Length == st.Count)                {                    foreach (var s in st)                    {                         if (charts[I].Series[0].Points.Count >= 500)                        {                            Invoke(new Action(() => {                                charts[I].Series[0].Points.RemoveAt(0);                            }));                        }                        Invoke(new Action(() => {                            charts[I].Series[0].Points.AddY(值[I]);                            charts[I].Update();                        }));                        I++;                    }                 }                I = 0;             }        }        void 获取数据()        {            int i = Convert.ToInt32(Thread.CurrentThread.Name);            switch (type[i])            {                case "bool":                    while (!停止)                    {                        Thread.Sleep(10);                        值[i] = Convert.ToInt32(SimaticS7Net.ReadBool(st[i]).Content);                    }                    break;                case "int":                    while (!停止)                    {                        Thread.Sleep(10);                        值[i] = Convert.ToInt32(SimaticS7Net.ReadInt32(st[i]).Content);                    }                    break;            }        }        void 连接数据库()        {            //File.Delete("AA.db");            string s = DateTime.Now.ToString("yyyy.MM.dd  H.m.ss");            s = "Data Source=" + s + ".db;Version=3;";             实时数据库连接 = new SQLiteConnection(s);//没有数据库则自动创建            实时数据库连接.Open();//打开数据库,生成db文件        }        void 循环写入数据库()        {            int 输入int = Convert.ToInt32(Thread.CurrentThread.Name);            SQLiteCommand command = new SQLiteCommand();//新建命令对象            command.Connection = 实时数据库连接;//和数据库连接            SQLiteTransaction tr = 实时数据库连接.BeginTransaction();//事务开始            int j = 0;            while (!停止)            {                Thread.Sleep(10);                for (int i = 0; i < st.Count; i++)                {                    string 表单名 = st[i] + @";" + type[i];                    command.CommandText = "INSERT INTO \"" + 表单名 + "\"(值) VALUES('" + 值[i] + "')";                    command.ExecuteNonQuery();                }                if (j>=50)                {                    tr.Commit();//提交事务                    tr = 实时数据库连接.BeginTransaction();//事务开始                    j = 0;                }                else                {                    j++;                }            }            if (j > 0)             tr.Commit();//提交事务            tr.Dispose();        }        public void 保存dataview()        {            //实例化一个保存文件对话框            SaveFileDialog sf = new SaveFileDialog();            //设置文件保存类型            sf.Filter = "txt文件|*.txt";            //如果用户没有输入扩展名,自动追加后缀            sf.AddExtension = true;            //设置标题            sf.Title = "写文件";            //如果用户点击了保存按钮            if (sf.ShowDialog() == DialogResult.OK)            {                //实例化一个文件流--->与写入文件相关联                FileStream fs = new FileStream(sf.FileName, FileMode.Create);                //实例化一个StreamWriter-->与fs相关联                StreamWriter sw = new StreamWriter(fs);                //开始写入                if (this.dataGridView1.Rows.Count < 1)                {                    MessageBox.Show("没有数据!导出失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                }                else                {                    string st = "";                    for (int i = 0; i < this.dataGridView1.Rows.Count - 1; i++)                    {                        for (int j = 0; j < this.dataGridView1.Columns.Count; j++)                        {                            st += this.dataGridView1.Rows[i].Cells[j].Value.ToString()+@";";                        }                        st = Regex.Replace(st, ";$", "");//替换掉字符串末尾的分号                        sw.WriteLine(st);                        st = "";                    }                    //sw.Write(this.textBox1.Text);                    //清空缓冲区                    sw.Flush();                    //关闭流                    sw.Close();                    fs.Close();                    MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                }            }        }        public void 加载到dataview中()        {            FileDialog fd = new OpenFileDialog();            if (fd.ShowDialog() == DialogResult.OK)            {                string[] list;                string st = fd.FileName;                using (StreamReader sr = new StreamReader(st))                {                    int i = 0;                    while (!sr.EndOfStream)                    {                        list = sr.ReadLine().Split(';');                        int index = this.dataGridView1.Rows.Add();                        for (int j = 0; j < list.Length; j++)                        {                            this.dataGridView1.Rows[index].Cells[j].Value = list[j];                        }                        i++;                    }                }            }            fd.Dispose();        }        private void 停止btn_Click(object sender, EventArgs e)        {            启动btn.Enabled = true;            停止 = true;        }        private void 加载Btn_Click(object sender, EventArgs e)        {            加载到dataview中();        }        private void Form1_FormClosed(object sender, FormClosedEventArgs e)        {            停止 = true;            Environment.Exit(0);        }        private void 打开历史btn_Click(object sender, EventArgs e)        {            OpenFileDialog op = new OpenFileDialog();//打开文件对话对象            if (op.ShowDialog() == DialogResult.OK)//打开选择文件框            {                string s = op.FileName;//获取文件路径及名称                历史数据库 = new SQLiteConnection("Data Source = "+s+"; Version = 3;");//设定连接数据库的名称和版本;                历史数据库.Open(); //连接数据库            }            else            {                return;            }            SQLiteCommand command = new SQLiteCommand(@"select name from sqlite_master where type='table' order by name;", 历史数据库);//连接数据库并执行指令;            SQLiteDataReader dataReader= command.ExecuteReader();//新建datareader对象;            表单名.Clear();//清空数据            while (dataReader.Read())//重复读取表单名,直到读取结束;            {                表单名.Add(dataReader["name"].ToString());//获取表单的名字            }            dataReader.Close();//必须关闭不然后面读取报错;            历史图表列表.Clear() ;//清空数据            历史图表.Clear();//清空数据            tabPage4.Controls.Clear();//清空页面中已有的图表            for (int i = 0; i < 表单名.Count; i++)            {                string[] ii = 表单名[i].Split(';');//数据库定的是:   M0.0;bool                chartClass c = new chartClass(ii[0], ii[1]);//新建图表对象                历史图表列表.Add(c);//存储进历史图表列表里面                历史图表.Add(c.返回图表());//存进历史图表里面                历史图表[i].Dock = DockStyle.Top;//设定为顶部靠齐                tabPage4.Controls.Add(历史图表[i]);//图表添加至tabpage页面            }            string sql = "SELECt  * FROM\"" + 表单名[0] +"\"  order by 序号 desc;";//倒序            command = new SQLiteCommand(sql, 历史数据库);//指定的数据库并执行指令;            dataReader = command.ExecuteReader();//定义数据读取器rdr获取传回的数据            dataReader.Read();//读取第一行数据;            int 最大序号 = Convert.ToInt32(dataReader["序号"]);//根据列名获取值            dataReader.Close();            //设定滑块值            hScrollBar1.Value = 0;            if (最大序号 > 500)            {                hScrollBar1.Enabled = true;                hScrollBar1.Maximum = 最大序号 - 500;            }            else                hScrollBar1.Enabled = false;            //设定点            总点.Clear();            for (int i = 0; i < 表单名.Count; i++)            {                总点.Add(null);            }            for (int i = 0; i < 表单名.Count; i++)            {                更新历史数据(i);                //Thread th = new Thread(更新历史数据);                //th.Name = i.ToString();                //th.Start();            }        }        void 更新历史数据(int 输入int)        {            List<int> list是是是 = new List<int>();            int 上限 = 0, 下限 = 0;            下限 = Convert.ToInt32(hScrollBar1.Value);            上限 = 下限 + 500;            string sql = "SELECt * FROM \"" + 表单名[输入int] + "\" WHERe [序号]<=" + 上限 + " AND [序号]>=" + 下限;            SQLiteCommand command = new SQLiteCommand(sql, 历史数据库);            SQLiteDataReader sqlrd = command.ExecuteReader();            while (sqlrd.Read())            {                list是是是.Add(Convert.ToInt32(sqlrd["值"]));            }            总点[输入int] = list是是是;            Invoke(new Action(() =>            {                历史图表[输入int].Series[0].Points.DataBindY(总点[输入int]);            }));        }        private void hScrollBar1_ValueChanged(object sender, EventArgs e)        {            //for (int i = 0; i < 表单名.Count; i++)            //{            //    Thread th = new Thread(更新历史数据);            //    th.Name = i.ToString();            //    th.Start();            //}            if (总点.Count>0)            {                for (int i = 0; i < 表单名.Count; i++)                {                    更新历史数据(i);                }            }        }    }}

Form1.Designer.cs

namespace PLC数据采集{    partial class Form1    {        /// <summary>        /// 必需的设计器变量。        /// </summary>        private System.ComponentModel.IContainer components = null;        /// <summary>        /// 清理所有正在使用的资源。        /// </summary>        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>        protected override void Dispose(bool disposing)        {            if (disposing && (components != null))            {                components.Dispose();            }            base.Dispose(disposing);        }        #region Windows 窗体设计器生成的代码        /// <summary>        /// 设计器支持所需的方法 - 不要修改        /// 使用代码编辑器修改此方法的内容。        /// </summary>        private void InitializeComponent()        {            this.tabPage3 = new System.Windows.Forms.TabPage();            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();            this.tabControl3 = new System.Windows.Forms.TabControl();            this.tabPage4 = new System.Windows.Forms.TabPage();            this.打开历史btn = new System.Windows.Forms.Button();            this.tabPage2 = new System.Windows.Forms.TabPage();            this.tabControl2 = new System.Windows.Forms.TabControl();            this.tabPage5 = new System.Windows.Forms.TabPage();            this.groupBox1 = new System.Windows.Forms.GroupBox();            this.启动btn = new System.Windows.Forms.Button();            this.停止btn = new System.Windows.Forms.Button();            this.tabPage1 = new System.Windows.Forms.TabPage();            this.groupBox2 = new System.Windows.Forms.GroupBox();            this.IP地址 = new System.Windows.Forms.TextBox();            this.label4 = new System.Windows.Forms.Label();            this.dataGridView1 = new System.Windows.Forms.DataGridView();            this.IO地址 = new System.Windows.Forms.DataGridViewTextBoxColumn();            this.数据类型 = new System.Windows.Forms.DataGridViewComboBoxColumn();            this.加载Btn = new System.Windows.Forms.Button();            this.label1 = new System.Windows.Forms.Label();            this.保存btn = new System.Windows.Forms.Button();            this.label2 = new System.Windows.Forms.Label();            this.断开btn = new System.Windows.Forms.Button();            this.连接btn = new System.Windows.Forms.Button();            this.tabControl1 = new System.Windows.Forms.TabControl();            this.hScrollBar1 = new System.Windows.Forms.HScrollBar();            this.tabPage3.SuspendLayout();            this.tableLayoutPanel1.SuspendLayout();            this.tabControl3.SuspendLayout();            this.tabPage2.SuspendLayout();            this.tabControl2.SuspendLayout();            this.groupBox1.SuspendLayout();            this.tabPage1.SuspendLayout();            this.groupBox2.SuspendLayout();            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();            this.tabControl1.SuspendLayout();            this.SuspendLayout();            //             // tabPage3            //             this.tabPage3.Controls.Add(this.tableLayoutPanel1);            this.tabPage3.Location = new System.Drawing.Point(4, 22);            this.tabPage3.Name = "tabPage3";            this.tabPage3.Padding = new System.Windows.Forms.Padding(3);            this.tabPage3.Size = new System.Drawing.Size(1110, 523);            this.tabPage3.TabIndex = 2;            this.tabPage3.Text = "历史记录";            this.tabPage3.UseVisualStyleBackColor = true;            //             // tableLayoutPanel1            //             this.tableLayoutPanel1.ColumnCount = 1;            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));            this.tableLayoutPanel1.Controls.Add(this.打开历史btn, 0, 0);            this.tableLayoutPanel1.Controls.Add(this.tabControl3, 0, 1);            this.tableLayoutPanel1.Controls.Add(this.hScrollBar1, 0, 2);            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;            this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 3);            this.tableLayoutPanel1.Name = "tableLayoutPanel1";            this.tableLayoutPanel1.RowCount = 3;            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 6.769826F));            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 93.23017F));            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));            this.tableLayoutPanel1.Size = new System.Drawing.Size(1104, 517);            this.tableLayoutPanel1.TabIndex = 3;            //             // tabControl3            //             this.tabControl3.Controls.Add(this.tabPage4);            this.tabControl3.Dock = System.Windows.Forms.DockStyle.Fill;            this.tabControl3.Location = new System.Drawing.Point(3, 36);            this.tabControl3.Name = "tabControl3";            this.tabControl3.SelectedIndex = 0;            this.tabControl3.Size = new System.Drawing.Size(1098, 457);            this.tabControl3.TabIndex = 3;            //             // tabPage4            //             this.tabPage4.AutoScroll = true;            this.tabPage4.Location = new System.Drawing.Point(4, 22);            this.tabPage4.Name = "tabPage4";            this.tabPage4.Padding = new System.Windows.Forms.Padding(3);            this.tabPage4.Size = new System.Drawing.Size(1090, 431);            this.tabPage4.TabIndex = 0;            this.tabPage4.Text = "历史数据";            this.tabPage4.UseVisualStyleBackColor = true;            //             // 打开历史btn            //             this.打开历史btn.Location = new System.Drawing.Point(3, 3);            this.打开历史btn.Name = "打开历史btn";            this.打开历史btn.Size = new System.Drawing.Size(75, 23);            this.打开历史btn.TabIndex = 2;            this.打开历史btn.Text = "打开历史";            this.打开历史btn.UseVisualStyleBackColor = true;            this.打开历史btn.Click += new System.EventHandler(this.打开历史btn_Click);            //             // tabPage2            //             this.tabPage2.AutoScroll = true;            this.tabPage2.Controls.Add(this.tabControl2);            this.tabPage2.Controls.Add(this.groupBox1);            this.tabPage2.Location = new System.Drawing.Point(4, 22);            this.tabPage2.Name = "tabPage2";            this.tabPage2.Padding = new System.Windows.Forms.Padding(3);            this.tabPage2.Size = new System.Drawing.Size(1110, 523);            this.tabPage2.TabIndex = 1;            this.tabPage2.Text = "实时采集";            this.tabPage2.UseVisualStyleBackColor = true;            //             // tabControl2            //             this.tabControl2.Controls.Add(this.tabPage5);            this.tabControl2.Dock = System.Windows.Forms.DockStyle.Fill;            this.tabControl2.Location = new System.Drawing.Point(3, 66);            this.tabControl2.Name = "tabControl2";            this.tabControl2.SelectedIndex = 0;            this.tabControl2.Size = new System.Drawing.Size(1104, 454);            this.tabControl2.TabIndex = 3;            //             // tabPage5            //             this.tabPage5.AutoScroll = true;            this.tabPage5.Location = new System.Drawing.Point(4, 22);            this.tabPage5.Name = "tabPage5";            this.tabPage5.Padding = new System.Windows.Forms.Padding(3);            this.tabPage5.Size = new System.Drawing.Size(1096, 428);            this.tabPage5.TabIndex = 0;            this.tabPage5.Text = "实时数据";            this.tabPage5.UseVisualStyleBackColor = true;            //             // groupBox1            //             this.groupBox1.Controls.Add(this.启动btn);            this.groupBox1.Controls.Add(this.停止btn);            this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;            this.groupBox1.Location = new System.Drawing.Point(3, 3);            this.groupBox1.Name = "groupBox1";            this.groupBox1.Size = new System.Drawing.Size(1104, 63);            this.groupBox1.TabIndex = 2;            this.groupBox1.TabStop = false;            this.groupBox1.Text = "groupBox1";            //             // 启动btn            //             this.启动btn.Location = new System.Drawing.Point(6, 20);            this.启动btn.Name = "启动btn";            this.启动btn.Size = new System.Drawing.Size(75, 23);            this.启动btn.TabIndex = 0;            this.启动btn.Text = "启动";            this.启动btn.UseVisualStyleBackColor = true;            this.启动btn.Click += new System.EventHandler(this.启动btn_Click);            //             // 停止btn            //             this.停止btn.Location = new System.Drawing.Point(87, 20);            this.停止btn.Name = "停止btn";            this.停止btn.Size = new System.Drawing.Size(75, 23);            this.停止btn.TabIndex = 1;            this.停止btn.Text = "停止";            this.停止btn.UseVisualStyleBackColor = true;            this.停止btn.Click += new System.EventHandler(this.停止btn_Click);            //             // tabPage1            //             this.tabPage1.Controls.Add(this.groupBox2);            this.tabPage1.Location = new System.Drawing.Point(4, 22);            this.tabPage1.Name = "tabPage1";            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);            this.tabPage1.Size = new System.Drawing.Size(1110, 523);            this.tabPage1.TabIndex = 0;            this.tabPage1.Text = "通信设置";            this.tabPage1.UseVisualStyleBackColor = true;            //             // groupBox2            //             this.groupBox2.Controls.Add(this.IP地址);            this.groupBox2.Controls.Add(this.label4);            this.groupBox2.Controls.Add(this.dataGridView1);            this.groupBox2.Controls.Add(this.加载Btn);            this.groupBox2.Controls.Add(this.label1);            this.groupBox2.Controls.Add(this.保存btn);            this.groupBox2.Controls.Add(this.label2);            this.groupBox2.Controls.Add(this.断开btn);            this.groupBox2.Controls.Add(this.连接btn);            this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;            this.groupBox2.Location = new System.Drawing.Point(3, 3);            this.groupBox2.Name = "groupBox2";            this.groupBox2.Size = new System.Drawing.Size(1104, 517);            this.groupBox2.TabIndex = 13;            this.groupBox2.TabStop = false;            this.groupBox2.Text = "groupBox2";            //             // IP地址            //             this.IP地址.Location = new System.Drawing.Point(142, 112);            this.IP地址.Name = "IP地址";            this.IP地址.Size = new System.Drawing.Size(216, 21);            this.IP地址.TabIndex = 1;            this.IP地址.Text = "127.0.0.11";            //             // label4            //             this.label4.AutoSize = true;            this.label4.Location = new System.Drawing.Point(619, 10);            this.label4.Name = "label4";            this.label4.Size = new System.Drawing.Size(65, 12);            this.label4.TabIndex = 8;            this.label4.Text = "IO采集设定";            //             // dataGridView1            //             this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {            this.IO地址,            this.数据类型});            this.dataGridView1.Location = new System.Drawing.Point(619, 25);            this.dataGridView1.Name = "dataGridView1";            this.dataGridView1.RowTemplate.Height = 23;            this.dataGridView1.Size = new System.Drawing.Size(245, 497);            this.dataGridView1.TabIndex = 7;            //             // IO地址            //             this.IO地址.HeaderText = "IO地址";            this.IO地址.Name = "IO地址";            //             // 数据类型            //             this.数据类型.HeaderText = "数据类型";            this.数据类型.Items.AddRange(new object[] {            "int",            "real",            "bool"});            this.数据类型.Name = "数据类型";            //             // 加载Btn            //             this.加载Btn.Location = new System.Drawing.Point(374, 110);            this.加载Btn.Name = "加载Btn";            this.加载Btn.Size = new System.Drawing.Size(75, 23);            this.加载Btn.TabIndex = 12;            this.加载Btn.Text = "加载IO";            this.加载Btn.UseVisualStyleBackColor = true;            this.加载Btn.Click += new System.EventHandler(this.加载Btn_Click);            //             // label1            //             this.label1.AutoSize = true;            this.label1.Location = new System.Drawing.Point(140, 77);            this.label1.Name = "label1";            this.label1.Size = new System.Drawing.Size(149, 12);            this.label1.TabIndex = 3;            this.label1.Text = "PLC型号: SIMATIC S7-1500";            //             // 保存btn            //             this.保存btn.Location = new System.Drawing.Point(471, 110);            this.保存btn.Name = "保存btn";            this.保存btn.Size = new System.Drawing.Size(75, 23);            this.保存btn.TabIndex = 11;            this.保存btn.Text = "保存";            this.保存btn.UseVisualStyleBackColor = true;            this.保存btn.Click += new System.EventHandler(this.保存_Click);            //             // label2            //             this.label2.AutoSize = true;            this.label2.Location = new System.Drawing.Point(89, 115);            this.label2.Name = "label2";            this.label2.Size = new System.Drawing.Size(41, 12);            this.label2.TabIndex = 4;            this.label2.Text = "IP地址";            //             // 断开btn            //             this.断开btn.Enabled = false;            this.断开btn.Location = new System.Drawing.Point(471, 72);            this.断开btn.Name = "断开btn";            this.断开btn.Size = new System.Drawing.Size(75, 23);            this.断开btn.TabIndex = 10;            this.断开btn.Text = "断开";            this.断开btn.UseVisualStyleBackColor = true;            this.断开btn.Click += new System.EventHandler(this.断开_Click);            //             // 连接btn            //             this.连接btn.Location = new System.Drawing.Point(374, 72);            this.连接btn.Name = "连接btn";            this.连接btn.Size = new System.Drawing.Size(75, 23);            this.连接btn.TabIndex = 9;            this.连接btn.Text = "连接";            this.连接btn.UseVisualStyleBackColor = true;            this.连接btn.Click += new System.EventHandler(this.连接_Click);            //             // tabControl1            //             this.tabControl1.Controls.Add(this.tabPage1);            this.tabControl1.Controls.Add(this.tabPage2);            this.tabControl1.Controls.Add(this.tabPage3);            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;            this.tabControl1.Location = new System.Drawing.Point(0, 0);            this.tabControl1.Name = "tabControl1";            this.tabControl1.SelectedIndex = 0;            this.tabControl1.Size = new System.Drawing.Size(1118, 549);            this.tabControl1.TabIndex = 0;            //             // hScrollBar1            //             this.hScrollBar1.Dock = System.Windows.Forms.DockStyle.Fill;            this.hScrollBar1.Location = new System.Drawing.Point(0, 496);            this.hScrollBar1.Name = "hScrollBar1";            this.hScrollBar1.Size = new System.Drawing.Size(1104, 21);            this.hScrollBar1.TabIndex = 4;            this.hScrollBar1.ValueChanged += new System.EventHandler(this.hScrollBar1_ValueChanged);            //             // Form1            //             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;            this.ClientSize = new System.Drawing.Size(1118, 549);            this.Controls.Add(this.tabControl1);            this.Name = "Form1";            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;            this.Text = "Form1";            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);            this.tabPage3.ResumeLayout(false);            this.tableLayoutPanel1.ResumeLayout(false);            this.tabControl3.ResumeLayout(false);            this.tabPage2.ResumeLayout(false);            this.tabControl2.ResumeLayout(false);            this.groupBox1.ResumeLayout(false);            this.tabPage1.ResumeLayout(false);            this.groupBox2.ResumeLayout(false);            this.groupBox2.PerformLayout();            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();            this.tabControl1.ResumeLayout(false);            this.ResumeLayout(false);        }        #endregion        private System.Windows.Forms.TabPage tabPage3;        private System.Windows.Forms.TabPage tabPage2;        private System.Windows.Forms.TabControl tabControl2;        private System.Windows.Forms.TabPage tabPage5;        private System.Windows.Forms.GroupBox groupBox1;        private System.Windows.Forms.Button 启动btn;        private System.Windows.Forms.Button 停止btn;        private System.Windows.Forms.TabPage tabPage1;        private System.Windows.Forms.Button 保存btn;        private System.Windows.Forms.Button 断开btn;        private System.Windows.Forms.Button 连接btn;        private System.Windows.Forms.Label label4;        private System.Windows.Forms.DataGridView dataGridView1;        private System.Windows.Forms.DataGridViewTextBoxColumn IO地址;        private System.Windows.Forms.DataGridViewComboBoxColumn 数据类型;        private System.Windows.Forms.Label label2;        private System.Windows.Forms.Label label1;        private System.Windows.Forms.TextBox IP地址;        private System.Windows.Forms.TabControl tabControl1;        private System.Windows.Forms.Button 加载Btn;        private System.Windows.Forms.GroupBox groupBox2;        private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;        private System.Windows.Forms.Button 打开历史btn;        private System.Windows.Forms.TabControl tabControl3;        private System.Windows.Forms.TabPage tabPage4;        private System.Windows.Forms.HScrollBar hScrollBar1;    }}


C#与PLC1200、200 Smart使用S7.NET通讯

C#实现西门子S7-1200、200 SMART PLC之间通信

C# WinForm实现欧姆龙PLC通信fins udp协议

C# WinForm对接PLC实现数据采集 (qq.com)


顶一下()     踩一下()

热门推荐

发表评论
0评