c# 西门子 PLC S7

c# 西门子 PLC S7

下载地址:https://github.com/S7NetPlus/s7netplus

S7.Net 与 S7-200,S7-300,S7-400,S7-1200 和 S7-1500 兼容。

// 创建一个 PLC 实例,连接和断开连接
Plc plc = new Plc(CpuType.S7200Smart, "192.168.2.1", 0, 0);
// 连接到 PLC
plc.Open();

//public object Read(string variable)
bool resultRun = (bool)plc.Read("DB1.DBX112.1");

tbLogLine.AppendText("resultRun:" + resultRun + Environment.NewLine);

bool resultStop = (bool)plc.Read("DB1.DBX112.2");
tbLogLine.AppendText("resultStop:" + resultStop + Environment.NewLine);

//double val = 35.687;
//plc.Write("DB102.DBD4", val.ConvertToUInt());

//double result = ((uint)plc.Read("DB102.DBD560")).ConvertToDouble();
//double result = ((uint)plc.Read("DB1.DBD100")).ConvertToDouble();

// 断开连接 PLC

plc.Close();

 

发表回复

您的电子邮箱地址不会被公开。