Files
sy_hx_pbl_backend/Infrastructure/PLC/PCLTool.cs

51 lines
1.1 KiB
C#
Raw Normal View History

2024-11-07 20:17:39 +08:00
using HslCommunication;
using HslCommunication.Profinet.Siemens;
using Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DOAN.Infrastructure.PLC
{
public class PCLTool
{
// private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static SiemensS7Net siemensTcpNet = null;
public bool ConnectPLC()
{
siemensTcpNet= new SiemensS7Net(SiemensPLCS.S1200, "192.168.0.100")
{
ConnectTimeOut = 5000
};
OperateResult connect = siemensTcpNet.ConnectServer();
if (connect.IsSuccess)
{
// 连接成功
Console.WriteLine("connect success");
return true;
}
else
{
// 连接失败,输出原因
Console.WriteLine("connect failed:" + connect.Message);
return false;
}
}
public void ConnectClose()
{
siemensTcpNet.ConnectClose();
}
}
}