You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.2 KiB
99 lines
3.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Module.DB.Model;
|
|
using Module.Common;
|
|
|
|
namespace Module.Plc.Profinet.Tool
|
|
{
|
|
/// <summary>
|
|
/// 读写PLC中IO参数应用类
|
|
/// </summary>
|
|
public class PlcIOUtils
|
|
{
|
|
/// <summary>
|
|
/// 读取T1的IO数据
|
|
/// </summary>
|
|
public MonitorModel ReadIoDataT1()
|
|
{
|
|
try
|
|
{
|
|
MonitorModel t1MonitorModel = null;
|
|
if (PublicParams.T1ConnectPlc)
|
|
{
|
|
t1MonitorModel = new MonitorModel();
|
|
var readerX = PlcCommon.DeltaTcpNetClient01.ReadBool("X0.0", 80);
|
|
var readerY = PlcCommon.DeltaTcpNetClient01.ReadBool("Y0.0", 82);
|
|
|
|
t1MonitorModel.InputData = new List<bool>();
|
|
if (readerX != null && readerX.Content != null && readerX.Content.Length > 0)
|
|
{
|
|
for (int i = 0; i < 80; i++)
|
|
{
|
|
t1MonitorModel.InputData.Add(readerX.Content[i]);
|
|
}
|
|
}
|
|
|
|
t1MonitorModel.OutputData = new List<bool>();
|
|
if (readerY != null && readerY.Content != null && readerY.Content.Length > 0)
|
|
{
|
|
for (int i = 0; i < 82; i++)
|
|
{
|
|
t1MonitorModel.OutputData.Add(readerY.Content[i]);
|
|
}
|
|
}
|
|
}
|
|
return t1MonitorModel;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取T2的IO数据
|
|
/// </summary>
|
|
public MonitorModel ReadIoDataT2()
|
|
{
|
|
try
|
|
{
|
|
MonitorModel t2MonitorModel = null;
|
|
if (PublicParams.T2ConnectPlc)
|
|
{
|
|
t2MonitorModel = new MonitorModel();
|
|
var readerX = PlcCommon.DeltaTcpNetClient02.ReadBool("X0.0", 80);
|
|
var readerY = PlcCommon.DeltaTcpNetClient02.ReadBool("Y0.0", 82);
|
|
|
|
t2MonitorModel.InputData = new List<bool>();
|
|
if (readerX != null && readerX.Content != null && readerX.Content.Length > 0)
|
|
{
|
|
for (int i = 0; i < 80; i++)
|
|
{
|
|
t2MonitorModel.InputData.Add(readerX.Content[i]);
|
|
}
|
|
}
|
|
|
|
t2MonitorModel.OutputData = new List<bool>();
|
|
if (readerY != null && readerY.Content != null && readerY.Content.Length > 0)
|
|
{
|
|
for (int i = 0; i < 82; i++)
|
|
{
|
|
t2MonitorModel.OutputData.Add(readerY.Content[i]);
|
|
}
|
|
}
|
|
}
|
|
return t2MonitorModel;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|