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

43 lines
1.1 KiB
C#

3 months ago
using System;
using HslCommunication.Profinet.AllenBradley;
using HslCommunication.Profinet.Siemens;
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
private void Init()
{
// 授权示例 Authorization example
if (!HslCommunication.Authorization.SetAuthorizationCode(RfidSetting.Current.HslKey))
{
Console.WriteLine( "Authorization failed! The current program can only be used for 8 hours!" );
return; // 激活失败应该退出系统
}
}
3 months ago
private AllenBradleyNet CreateAb()
{
3 months ago
Init();
3 months ago
var rfidSetting = RfidSetting.Current;
AllenBradleyNet ab = new AllenBradleyNet();
ab.IpAddress = rfidSetting.PlcIp;
ab.Port = rfidSetting.Port;
ab.ConnectServer();
return ab;
}
}
}