using BPASmartClient.Modbus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BPASmartClient.PLC
{
///
/// PLC读取参数
///
internal class PLCReadParameter
{
///
/// 读取类型
///
internal CommandType CmdType { get; set; }
///
/// 地址
///
internal string Address { get; set; }
///
/// 长度
///
internal ushort Length { get; set; }
///
/// 配置转模型
///
/// M,M0.3,3;M,M100.0,16;M,M235.0,1;M,M102,7;M,M103,6;VW,VW372,1
/// 读取参数模型
public static List DeSerialize(string content)
{
List result = new List();
var wholeTemp = content.Split(';');
foreach (var temp in wholeTemp)
{
if (temp.Contains(","))
{
var subTemp = temp.Split(',');
if (null != subTemp && subTemp.Length == 3)
{
PLCReadParameter parameter = new PLCReadParameter();
switch (subTemp[0])
{
case "M":
parameter.CmdType = CommandType.Coils;
break;
case "VW":
parameter.CmdType = CommandType.HoldingRegisters;
break;
}
parameter.Address = subTemp[1];
parameter.Length = ushort.Parse(subTemp[2]);
result.Add(parameter);
}
}
}
return result;
}
}
}