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.
lj_plc/DataBlockHelper/PlcConnect.cs

54 lines
1.3 KiB
C#

using HslCommunication.Instrument.DLT;
using HslCommunication.Profinet.Siemens;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace DataBlockHelper
{
public class PlcConnect
{
private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection());
public static SiemensS7Net Instance => lazy.Value;
private PlcConnect()
{
}
public SiemensS7Net SiemensS7NetConnection()
{
SiemensPLCS siemensPLCS = SiemensPLCS.S1500;
SiemensS7Net s7 = new SiemensS7Net(siemensPLCS);
s7.SetPersistentConnection();
12 months ago
s7.IpAddress = "172.18.4.100";
12 months ago
12 months ago
//s7.IpAddress = "192.168.1.110";
s7.Port = 102;
1 year ago
var su = s7.ConnectServer();
if (!su.IsSuccess)
{
12 months ago
s7.IpAddress = "192.168.0.100";
s7.Port = 7788;
var fn = s7.ConnectServer();
if (!fn.IsSuccess)
{
return new SiemensS7Net(siemensPLCS);
}
1 year ago
}
return s7;
}
}
}