• 大小: 0.44M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-05-01
  • 语言: C#
  • 标签: 1500  西门子  00  通讯  C#  

资源简介

这是我在实际项目中使用的一个例子,很完整,里面注释很详细

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using S7.Net;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        //定义PLC类型
        Plc S71500;      
        public Form1()
        {
            InitializeComponent();
           
        }
        private void Form1_Load(object sender EventArgs e)
        {

            //下拉框添加数据类型项
            Data_Type.Items.Add(“Bool“);
            Data_Type.Items.Add(“Int“);
            Data_Type.Items.Add(“DInt“);
            Data_Type.Items.Add(“Real“);
            Data_Type.Text = “Real“;

            //使能、禁止按钮操作
            button1.Enabled = true;
            button2.Enabled = false;
            Read_Data.Enabled = false;
            Write_Data.Enabled = false;
        }
        
        private void label4_Click(object sender EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
        {

        }

        private void button1_Click(object sender EventArgs e)
        {
            //创建PLC对象
            S71500 = new Plc(CpuType.S71500 IP_Address.Text Convert.ToInt16(Rack.Text)
                Convert.ToInt16(Slot.Text));

            //调用S7.NET中的方法连接PLC
            S71500.Open();

            //连接成功后使能操作按钮
            if (S71500.IsConnected)
            {
                button1.Enabled = false;
                button2.Enabled = true;
                Read_Data.Enabled = true;
                Write_Data.Enabled = true;
                textBox1.Text = “已连接到PLC“;
            }
            else
                textBox1.Text = “PLC 连接不成功,请检查IP地址、机架、插槽等是否正确“;
            
        }

        private void button2_Click(object sender EventArgs e)
        {
            //调用S7.NET中的方法断开PLC
            S71500.Close();

            //断开成功后使能操作按钮
            if (!S71500.IsConnected)
            {
                button1.Enabled = true;
                button2.Enabled = false;
                Read_Data.Enabled = false;
                Write_Data.Enabled = false;
                textBox1.Text = “PLC断开成功“;
            }
           else
                textBox1.Text = “PLC断开不成功“;

        }

        private void Read_Data_Click(object sender EventArgs e)
        {
            int Data_Type_Value = 0;
            if (Data_Type.Text == “Bool“) Data_Type_Value = 1;
            else if (Data_Type.Text == “Int“) Data_Type_Value = 2;
            else if (Data_Type.Text == “DInt“) Data_Type_Value = 3;
            else if (Data_Type.Text == “Real“) Data_Type_Value = 4;
            else Data_Type_Value = 0;

            switch (Data_Type_Value)
            {
                case 1:
                     Current_Value.Text = Convert.ToString(S71500.Read(DataType.DataBloc

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     60416  2018-09-21 09:22  S7_1500_Test\S7_1500_Test\.vs\S7_1500_Test\v15\.suo

     文件          0  2018-09-20 11:27  S7_1500_Test\S7_1500_Test\.vs\S7_1500_Test\v15\Server\sqlite3\db.lock

     文件     618496  2018-09-21 09:22  S7_1500_Test\S7_1500_Test\.vs\S7_1500_Test\v15\Server\sqlite3\storage.ide

     文件      65536  2018-07-11 21:00  S7_1500_Test\S7_1500_Test\packages\S7netplus.0.3.0\lib\net452\S7.Net.dll

     文件      21424  2018-07-11 21:00  S7_1500_Test\S7_1500_Test\packages\S7netplus.0.3.0\lib\net452\S7.Net.pdb

     文件      65536  2018-07-11 21:00  S7_1500_Test\S7_1500_Test\packages\S7netplus.0.3.0\lib\netstandard1.3\S7.Net.dll

     文件      21368  2018-07-11 21:00  S7_1500_Test\S7_1500_Test\packages\S7netplus.0.3.0\lib\netstandard1.3\S7.Net.pdb

     文件      65536  2018-07-11 21:00  S7_1500_Test\S7_1500_Test\packages\S7netplus.0.3.0\lib\netstandard2.0\S7.Net.dll

     文件      21424  2018-07-11 21:00  S7_1500_Test\S7_1500_Test\packages\S7netplus.0.3.0\lib\netstandard2.0\S7.Net.pdb

     文件     120700  2018-09-20 11:41  S7_1500_Test\S7_1500_Test\packages\S7netplus.0.3.0\S7netplus.0.3.0.nupkg

     文件       1136  2018-09-20 13:47  S7_1500_Test\S7_1500_Test\S7_1500_Test.sln

    ..A..H.     14848  2019-10-25 16:12  S7_1500_Test\S7_1500_Test\S7_1500_Test.v12.suo

     文件        184  2019-10-25 10:47  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\App.config

     文件      65536  2018-07-11 21:00  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\bin\Debug\S7.Net.dll

     文件      21424  2018-07-11 21:00  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\bin\Debug\S7.Net.pdb

     文件      15360  2018-09-21 09:22  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe

     文件        184  2019-10-25 10:47  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe.config

     文件      24064  2018-09-21 09:22  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.pdb

     文件      24224  2019-10-25 10:48  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.vshost.exe

     文件        184  2019-10-25 10:47  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.vshost.exe.config

     文件        490  2017-09-29 21:43  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.vshost.exe.manifest

     文件       5738  2019-10-25 16:12  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\Form1.cs

     文件      14490  2018-09-20 17:06  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\Form1.Designer.cs

     文件       5817  2018-09-20 17:06  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\Form1.resx

     文件        865  2019-10-25 10:47  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7273  2019-10-25 10:47  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2018-09-21 09:22  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csproj.CopyComplete

     文件         42  2018-09-20 16:20  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csproj.CoreCompileInputs.cache

     文件       3086  2019-10-25 10:48  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csproj.FileListAbsolute.txt

     文件        904  2019-10-25 10:47  S7_1500_Test\S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csproj.GenerateResource.Cache

............此处省略41个文件信息

评论

共有 条评论