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.

47 lines
1.2 KiB
C#

10 months ago
using HslCommunication.Profinet.Siemens;
using System;
namespace Mesnac.Action.ChemicalWeighing
{
public class PlcConnect
{
private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection());
public static SiemensS7Net Instance => lazy.Value;
private PlcConnect()
{
10 months ago
if (HslCommunication.Authorization.SetAuthorizationCode("ed1415f8-e06a-43ad-95f7-c04f7ae93b41"))
{
Console.WriteLine("HslCommunication激活成功!");
}
10 months ago
}
public SiemensS7Net SiemensS7NetConnection()
{
SiemensPLCS siemensPLCS = SiemensPLCS.S1500;
SiemensS7Net s7 = new SiemensS7Net(siemensPLCS);
10 months ago
10 months ago
//配料IP
10 months ago
s7.IpAddress = "192.168.10.130";
10 months ago
s7.Port = 102;
var su = s7.ConnectServer();
if (!su.IsSuccess)
{
10 months ago
s7.IpAddress = "192.168.10.130";
10 months ago
s7.Port = 102;
var su1 = s7.ConnectServer();
if (!su1.IsSuccess)
{
return new SiemensS7Net(siemensPLCS);
}
}
return s7;
}
}
}