• 大小: 0.43M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-04-26
  • 语言: C#
  • 标签: C#  S7  siemens  

资源简介

s7.net

资源截图

代码片段和文件信息

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.     74240  2020-11-26 09:41  S7_1500_Test\.vs\S7_1500_Test\v15\.suo

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

     文件     651264  2020-11-26 09:42  S7_1500_Test\.vs\S7_1500_Test\v15\Server\sqlite3\storage.ide

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

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

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

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

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

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

     文件     120700  2018-09-20 11:41  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.sln

     文件        189  2018-09-20 11:27  S7_1500_Test\WindowsFormsApp1\App.config

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

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

     文件      15360  2020-11-25 16:21  S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe

     文件        189  2018-09-20 11:27  S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe.config

     文件      26112  2020-11-25 16:21  S7_1500_Test\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.pdb

     文件       5738  2020-11-25 16:21  S7_1500_Test\WindowsFormsApp1\Form1.cs

     文件      14612  2020-11-25 16:21  S7_1500_Test\WindowsFormsApp1\Form1.Designer.cs

     文件       5817  2020-11-25 16:21  S7_1500_Test\WindowsFormsApp1\Form1.resx

     文件        868  2018-09-20 11:27  S7_1500_Test\WindowsFormsApp1\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7436  2018-09-20 11:42  S7_1500_Test\WindowsFormsApp1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2020-11-25 16:21  S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csproj.CopyComplete

     文件         42  2020-11-26 09:03  S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csproj.CoreCompileInputs.cache

     文件       4047  2020-11-25 13:07  S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csproj.FileListAbsolute.txt

     文件       1012  2020-11-25 16:21  S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csproj.GenerateResource.cache

     文件      49476  2020-11-26 09:03  S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csprojAssemblyReference.cache

     文件      10954  2018-09-21 09:22  S7_1500_Test\WindowsFormsApp1\obj\Debug\S7_1500_Test.csprojResolveAssemblyReference.cache

     文件          0  2018-09-20 11:27  S7_1500_Test\WindowsFormsApp1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-09-20 11:27  S7_1500_Test\WindowsFormsApp1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

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

评论

共有 条评论