C#与S7PLC通讯-基于S7协议

程序引用S7.NET.dll文件

 
 

程序主要实现与S71500一个整数的读写示例。

 
 

程序界面


程序

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 WindowsFormsApplication1

{

public
partial
class
Form1 : Form

{

Plc s71500;

public Form1()

{

InitializeComponent();

}

 
 

private
void btnLink_Click(object sender, EventArgs e)

{

s71500 = new
Plc(CpuType.S71500,txtAddress.Text,Convert.ToInt16(txtRack.Text),Convert.ToInt16(txtSlot.Text));

s71500.Open();

}

 
 

private
void btnBreak_Click(object sender, EventArgs e)

{

s71500.Close();

}

 
 

private
void btnRead_Click(object sender, EventArgs e)

{

short MyPlcData= ((ushort)s71500.Read(“DB” + txtDB.Text + “.” + “DBW” + txtStart.Text)).ConvertToShort();

txtValue.Text= MyPlcData.ToString();

}

 
 

private
void btnWrite_Click(object sender, EventArgs e)

{

s71500.Write(“DB” + txtDB.Text + “.” + “DBW” + txtStart.Text, Convert.ToInt16(txtValue.Text));

}

}

}

 
 

PLC程序


Author: 徐大军

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注