Files
SamplePreSystem-CS/SamplePre.ProcessBll/BLL/CommunicationBll.cs
2026-04-30 11:34:41 +08:00

81 lines
2.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}
}