资源简介
西门子PLC使用C#读写PLC数据,采用S7 dll库连接下位,在上位显示相关数据。
代码片段和文件信息
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 Snap7;
using System.Threading;
namespace Snap7_read
{
public partial class Form1 : Form
{
private S7Client client1=new S7Client();
private S7Client client2 = new S7Client();
private byte[] DB_A = new byte[256];
private byte[] DB_B = new byte[256];
delegate void setTextCallback(string text);
private void SetText(string text)
{
if (this.textBox1.InvokeRequired)
{
while (!this.textBox1.IsHandleCreated)
{
if (this.textBox1.Disposing || this.textBox1.IsDisposed)
{
return;
}
}
setTextCallback d = new setTextCallback(SetText);
this.textBox1.Invoke(d new object[] { text });
}
else
{
this.textBox1.Text = text;
}
}
private void SetText1(string text)
{
if (this.textBox2.InvokeRequired)
{
while (!this.textBox2.IsHandleCreated)
{
if (this.textBox2.Disposing || this.textBox2.IsDisposed)
{
return;
}
}
setTextCallback d = new setTextCallback(SetText1);
this.textBox2.Invoke(d new object[] { text });
}
else
{
this.textBox2.Text = text;
}
}
private void ShowResult(int Result)
{
// This function returns a textual explaination of the error code
// TextError.Text = Client.ErrorText(Result);
}
private string Dump(TextBox Box byte[] Buffer int Size)
{
string str = ““;
// Declaration separated from the code for readability
int y;
//Box.Text = ““;
y = 0;
for (int c = 0; c < Size; c++)
{
String S = Convert.ToString(Buffer[c] 16);
if (S.Length == 1) S = “0“ + S;
str = str+ “0x“ + S + “ “;
y++;
if (y == 8)
{
y = 0;
str = str + (char)13 + (char)10;
}
}
return str;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
}
private void button2_Click(object sender EventArgs e)
{
Thread thread1 = new Thread(() =>
{
int result1 = client1.ConnectTo(“192.168.1.110“ 0 1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 2518 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\.gitattributes
....... 4305 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\.gitignore
....... 2518 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\NewRepo\.gitattributes
....... 4305 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\NewRepo\.gitignore
....... 184 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\App.config
....... 5074 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Form1.cs
....... 4382 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Form1.Designer.cs
....... 5889 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Form1.resx
....... 500 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Program.cs
....... 1282 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Properties\AssemblyInfo.cs
....... 2762 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Properties\Resources.Designer.cs
....... 5496 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Properties\Resources.resx
....... 1067 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Properties\Settings.Designer.cs
....... 242 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Properties\Settings.settings
....... 3565 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Snap7 read.csproj
....... 108239 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\snap7.net.cs
....... 1104 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read.sln
目录 0 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read\Properties
目录 0 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\NewRepo
目录 0 2018-10-29 14:55 Snap7-read-master\Snap7-read-master\Snap7 read
目录 0 2018-10-29 14:55 Snap7-read-master\Snap7-read-master
目录 0 2019-06-24 14:52 Snap7-read-master
----------- --------- ---------- ----- ----
153432 22
相关资源
- vb调用c#编写的串口DLL文件(vb源码
- BouncyCastle C#源码
- 拱猪扑克牌游戏C#源码
- 各类称重仪表C#源码
- C#坦克大战源代码全部用C#编写
- C#源码:批量自动去除图片白边
- [C#源码]内存搜索修改像金山游侠一下
- C#源码让windows系统待机休眠
- C#图书管理系统源码(含数据库)-附
- c#编写的绘图软件源码
- [C#源码]超市项目BS架构
- Modbus通讯协议-C#源码
- 发票套打[全C#源码]
- apk信息查看C#源码
- S7.NET-EXE.rar
- c#图书管理系统C#源码和SQL数据库
- 客户端根据服务器端的指令弹出提示
- 图书租借管理系统(C#源码 MySQL)
- [源码] C#编程 - 轻松入侵全班同学电脑
- 远程桌面控制C#源码
- 大学生就业咨询系统(C#源码)
- 餐饮管理系统(C#源码)
- 二手物品交易网站C#源码
- C#实现串口通讯教程以及源码
- 新闻发布系统源码ASP.net C#源码
- 基于asp.net的家庭财务管理系统收支管
- 模仿简单网站购物网站(C# 源代码)
- Visual+C#从入门到精通.第8版(源码)
- 智能排课系统C#源码
- 酒店管理系统(c#源码)137332
评论
共有 条评论