现场PBL修改后代码提交
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using HslCommunication.Profinet.Inovance;
|
||||
using HslCommunication.Profinet.Siemens;
|
||||
using Infrastructure;
|
||||
using JinianNet.JNTemplate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -16,26 +17,40 @@ namespace DOAN.Infrastructure.PLC
|
||||
|
||||
// private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public static SiemensS7Net siemensTcpNet = null;
|
||||
public static bool ConnectPLC()
|
||||
public SiemensS7Net siemensTcpNet = null;
|
||||
public PLCTool()
|
||||
{
|
||||
siemensTcpNet = new SiemensS7Net(SiemensPLCS.S200Smart, "192.168.2.1")
|
||||
|
||||
this.siemensTcpNet = new SiemensS7Net(SiemensPLCS.S200Smart, "192.168.2.1")
|
||||
{
|
||||
ConnectTimeOut = 5000
|
||||
};
|
||||
OperateResult connect = siemensTcpNet.ConnectServer();
|
||||
if (connect.IsSuccess)
|
||||
};
|
||||
}
|
||||
|
||||
public bool ConnectPLC()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 连接成功
|
||||
Console.WriteLine("connect success");
|
||||
return true;
|
||||
OperateResult connect = siemensTcpNet.ConnectServer();
|
||||
if (connect.IsSuccess)
|
||||
{
|
||||
// 连接成功
|
||||
Console.WriteLine("PLC连接成功");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 连接失败,输出原因
|
||||
Console.WriteLine("PLC连接失败:" + connect.Message);
|
||||
throw new CustomException("connect failed:" + connect.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
// 连接失败,输出原因
|
||||
Console.WriteLine("connect failed:" + connect.Message);
|
||||
Console.WriteLine("PLC连接失败:" + e.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -46,7 +61,7 @@ namespace DOAN.Infrastructure.PLC
|
||||
/// <param name="addr"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static bool WriteBit(string addr, bool value)
|
||||
public bool WriteBit(string addr, bool value)
|
||||
{
|
||||
|
||||
OperateResult write = siemensTcpNet.Write(addr, value);
|
||||
@@ -58,7 +73,7 @@ namespace DOAN.Infrastructure.PLC
|
||||
/// </summary>
|
||||
/// <param name="addr"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ReadBit(string addr)
|
||||
public bool ReadBit(string addr)
|
||||
{
|
||||
|
||||
bool M100_7 = siemensTcpNet.ReadBool(addr).Content;
|
||||
@@ -67,7 +82,7 @@ namespace DOAN.Infrastructure.PLC
|
||||
|
||||
|
||||
|
||||
public static void ConnectClose()
|
||||
public void ConnectClose()
|
||||
{
|
||||
siemensTcpNet.ConnectClose();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user