You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/Tool/PlcConnect.cs

51 lines
1.2 KiB
C#

3 months ago
using System;
3 months ago
3 months ago
using HslCommunication;
3 months ago
using HslCommunication.LogNet;
3 months ago
using HslCommunication.Profinet.AllenBradley;
using HslCommunication.Profinet.Siemens;
3 months ago
using Newtonsoft.Json;
3 months ago
namespace Tool
{
public class PlcConnect
{
private static readonly Lazy<AllenBradleyNet> lazy = new Lazy<AllenBradleyNet>(() => new PlcConnect().CreateAb());
public static AllenBradleyNet Instance => lazy.Value;
private PlcConnect()
{
3 months ago
3 months ago
}
3 months ago
3 months ago
private AllenBradleyNet CreateAb()
{
var rfidSetting = RfidSetting.Current;
2 months ago
AllenBradleyNet plc = new AllenBradleyNet();
plc.Slot = 0;
plc.CommunicationPipe = new HslCommunication.Core.Pipe.PipeTcpNet(rfidSetting.PlcIp, 44818)
{
ConnectTimeOut = 5000, // 连接超时时间,单位毫秒
ReceiveTimeOut = 10000, // 接收设备数据反馈的超时时间
SleepTime = 0,
SocketKeepAliveTime = -1,
IsPersistentConnection = true,
};
return plc;
3 months ago
}
3 months ago
2 months ago
public OperateResult Write(string db, string value)
3 months ago
{
return Instance.Write(db, value);
}
3 months ago
}
}