• 大小: 1.00M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-06-17
  • 语言: C#
  • 标签: s7-200  smart  西门子  200  S7  

资源简介

c#与西门子s7-200 smart 通讯实例 内附S7TCPDLL.dll

【使用说明】

在bin文件夹debug,config文件打开配置PLC IP地址,CPU 的信息
修改配置文件
[PlcComTCP]
IP=192.168.0.1  //PLC IP地址
Rack=0          //PLC 机架
Slot=1          //PLC 插槽

注,PLC和电脑 IP必须在同一网段

S7TCPDLL使用方法
1)添加引用,然后倒入命名空间
using S7TCPDLL;
2)实例化函数 S7Client
例如:   S7Client client = new S7Client();
然后利用VS开发平台智能感知的功能可选择相应函数
例如调用置位函数 SetBitQB(0, 0)
       首先实例化函数S7Client client = new S7Client();
       然后 client.SetBitQB(0, 0);
调用其他函数类似。

资源截图

代码片段和文件信息

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 S7TCPDLL;

namespace S7_200_SMART_PROJECT
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
        S7Client client = new S7Client();
        int status; bool connectstate=false;
        string ReadBuf; int Result; string path;
        string TxtSlot;
        string TxtIP;
        string TxtRack;
        private void Form1_Load(object sender EventArgs e)
        {

            connectIP();
        }

        private void timer1_Tick(object sender EventArgs e)
        {

            ovalShape1.Fillstyle = 1 - ovalShape1.Fillstyle;
            byte[] EBBuffer = new byte[1];
            int result =client.EBRead(0 EBBuffer.Length EBBuffer);
            if (result == 0)
            {
                iO_Instructions2.AAValue = client.ReadBitQB(0 6);    //Q0.6
                iO_Instructions3.AAValue = client.ReadBitQB(0 5);
                iO_Instructions4.AAValue = client.ReadBitQB(0 4);
                iO_Instructions5.AAValue = client.ReadBitQB(0 3);
                iO_Instructions6.AAValue = client.ReadBitQB(0 2);
                iO_Instructions7.AAValue = client.ReadBitQB(0 1);
                iO_Instructions8.AAValue = client.ReadBitIB(0 4);   //I0.4
                iO_Instructions9.AAValue = client.ReadBitIB(0 3);
                iO_Instructions10.AAValue = client.ReadBitIB(0 2);
                iO_Instructions11.AAValue = client.ReadBitIB(0 1);

                //////////////////////////////////////////////////
                iO_Instructions12.AAValue = client.ReadBitQB(0 6);   //Q1.0
                iO_Instructions13.AAValue = client.ReadBitQB(0 5);   //Q1.1
                iO_Instructions1.AAValue = client.ReadBitV(800 6);

                ////////////////////////////////////////////////////
                TbxVD100.Text = client.VRead_REAL(100).ToString();
            }
            else
            {
                client.Disconnect();
                ovalShape2.BackColor = Color.Red;
                ovalShape1.BackColor = Color.Transparent;
                connectIP(); 
            }
        }

        public void connectIP()
        {
            path = Application.StartupPath + @“\config.ini“;
            TxtIP = IniFile.ReadIniData(“PlcComTCP“ “IP“ ““ path);
            TxtRack = IniFile.ReadIniData(“PlcComTCP“ “Rack“ ““ path);
            TxtSlot = IniFile.ReadIniData(“PlcComTCP“ “Slot“ ““ path);
            
            
            int Rack = Convert.ToInt32(TxtRack); int Slot =Convert.ToInt32(TxtSlot);
            client.SetConnectionType(3);
           // int result = client.ConnectTo(“172.18.28.249“ 0 1);
            int  R

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-01-22 11:11  S7200SMART(C#VS2013)\
     目录           0  2021-04-19 20:53  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\
     文件        4195  2017-02-19 22:07  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\.gitignore
     目录           0  2021-04-19 20:53  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\.vs\
     目录           0  2021-04-19 20:53  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\.vs\S7_200_SMART_PROJECT\
     目录           0  2021-04-19 20:53  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\.vs\S7_200_SMART_PROJECT\v14\
     文件       44032  2021-04-19 20:55  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\.vs\S7_200_SMART_PROJECT\v14\.suo
     目录           0  2021-01-22 10:53  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\DLL\
     文件      284672  2021-01-22 10:26  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\DLL\S7TCPDLL.dll
     文件        1075  2017-02-19 22:07  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\LICENSE
     文件         230  2017-02-19 22:07  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\README.md
     文件         533  2019-09-26 18:29  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\ReadMeFirst.txt
     目录           0  2021-04-19 20:54  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\
     文件         184  2019-09-21 17:03  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\App.config
     文件       40699  2021-04-19 20:54  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Form1.Designer.cs
     文件        7985  2021-04-19 20:54  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Form1.cs
     文件       23626  2021-04-19 20:54  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Form1.resx
     文件        3393  2019-09-24 15:08  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\IO_Instructions.Designer.cs
     文件        3025  2019-09-24 15:08  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\IO_Instructions.cs
     文件        5817  2019-06-21 15:21  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\IO_Instructions.resx
     文件         532  2019-09-24 15:08  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Program.cs
     目录           0  2021-01-22 10:53  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Properties\
     文件        1342  2019-09-18 09:04  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Properties\AssemblyInfo.cs
     文件        2880  2019-09-24 15:08  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Properties\Resources.Designer.cs
     文件        5612  2019-09-18 09:04  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Properties\Resources.resx
     文件        1120  2019-09-24 15:08  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Properties\Settings.Designer.cs
     文件         249  2019-09-18 09:04  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\Properties\Settings.settings
     文件        5130  2019-09-26 18:51  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\S7_200_SMART_PROJECT.csproj
     文件         228  2019-09-24 17:29  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\S7_200_SMART_PROJECT.csproj.user
     目录           0  2021-01-22 10:53  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\bin\
     目录           0  2021-04-19 20:55  S7200SMART(C#VS2013)\S7200SMART(C#VS2013)\S7PROJECT\bin\Debug\
............此处省略65个文件信息

评论

共有 条评论