81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using Models.Const;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace SamplePre.ProcessBll.BLL
|
||
{
|
||
public class CommunicationBll
|
||
{
|
||
|
||
|
||
/// <summary>
|
||
/// 读取PLC状态数据-数组
|
||
/// </summary>
|
||
/// <param name="Dbno"></param>
|
||
/// <param name="start"></param>
|
||
/// <param name="lenth"></param>
|
||
/// <returns></returns>
|
||
public ushort[] ReadSateData(int Dbno, int start, int lenth)
|
||
{
|
||
|
||
if (SystemConst.ProtocolType == Communication.CommProtocolType.S7)
|
||
{
|
||
//读取下位机状态
|
||
ushort[] data1 = SystemConst.MasterPLC.ReadArraysShort(Dbno, start, lenth);
|
||
|
||
return data1;
|
||
}
|
||
|
||
//这里应该增加一个协议数据解析层,解析后的格式返回给UI,后续完善
|
||
///
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 写入plc指令,字节数组
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <param name="Dbno"></param>
|
||
/// <param name="start"></param>
|
||
/// <param name="bytes"></param>
|
||
/// <returns></returns>
|
||
public bool WritePlcData<T>(int Dbno, int start, T[] bytes)
|
||
{
|
||
bool val = false;
|
||
//if (SystemConst.ProtocolType == Communication.CommProtocolType.S7)
|
||
//{
|
||
//写入PLC
|
||
val = SystemConst.MasterPLC.WriteArraysBtye(Dbno, start, bytes);
|
||
//}
|
||
//else if (SystemConst.ProtocolType == Communication.CommProtocolType.ModbusTcp)
|
||
//{
|
||
// //写入PLC
|
||
// val = SystemConst.MasterPLC.WriteArraysBtye(Dbno, start, bytes);
|
||
//}
|
||
|
||
|
||
return val;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 写plc数据,单数据
|
||
/// </summary>
|
||
/// <param name="Dbno"></param>
|
||
/// <param name="obj"></param>
|
||
/// <returns></returns>
|
||
public bool WriteSingleData(string Dbno, object obj)
|
||
{
|
||
//写入PLC
|
||
var val = SystemConst.MasterPLC.WriteSingleData(Dbno, obj);
|
||
|
||
return val;
|
||
}
|
||
|
||
|
||
}
|
||
}
|