Commit 8d7e0f47 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 modbus PLC 添加更多调试信息,可以在服务器查看

parent aaddf320
......@@ -26,6 +26,14 @@ namespace FLY.Modbus
/// PLC 首地址
/// </summary>
public int addr;
/// <summary>
/// 原始寄存器字符串
/// </summary>
public string regAddr;
/// <summary>
/// 原始 owner 名字
/// </summary>
public string ownerName;
/// <summary>
/// PLC 尾地址
......@@ -81,7 +89,7 @@ namespace FLY.Modbus
/// <param name="scale"></param>
/// <param name="owner"></param>
/// <param name="propertyname"></param>
public DataToRegs(ModbusMapper mapper, PLCAddressArea dataArea, int addr, REG_TYPE type, double scale, object owner, string propertyname)
public DataToRegs(ModbusMapper mapper, PLCAddressArea dataArea, int addr, REG_TYPE type, double scale, object owner, string propertyname, string regAddr, string ownerName)
{
this.mapper = mapper;
this.dataArea = dataArea;
......@@ -90,7 +98,8 @@ namespace FLY.Modbus
this.scale = scale;
this.owner = owner;
this.propertyName = string.Copy(propertyname);
this.regAddr = regAddr;
this.ownerName = ownerName;
if (type == REG_TYPE.BOOL)
{
plcValue = false;
......
......@@ -70,12 +70,12 @@ namespace FLY.Modbus
/// <param name="obj">Property 所属对象</param>
/// <param name="propertyname">Property Name</param>
/// <returns></returns>
public DataToRegs MapDataToRegs(PLCAddressArea dataArea, int addr, REG_TYPE type, double scale, object obj, string propertyname)
public DataToRegs MapDataToRegs(PLCAddressArea dataArea, int addr, REG_TYPE type, double scale, object obj, string propertyname, string regAddr, string ownerName)
{
DataToRegs dr = FindDataMap(obj, propertyname);
if (dr == null)
{
dr = new DataToRegs(this, dataArea, addr, type, scale, obj, propertyname);
dr = new DataToRegs(this, dataArea, addr, type, scale, obj, propertyname, regAddr, ownerName);
DRmap.Add(dr);
DRmap.Sort(delegate (DataToRegs X, DataToRegs Y)
{
......
......@@ -55,14 +55,30 @@ namespace FLY.Modbus
/// </summary>
public string PropertyName;
/// <summary>
/// 原始寄存器地址
/// </summary>
public string RegAddr;
public override string ToString()
{
return OwnerName + "." + PropertyName + " dev" + DeviceIndex + " [" + Mode + "](" + Addr + ")";
return $"{OwnerName}.{PropertyName} ({RegAddr})=dev{DeviceIndex}[{Mode}]({Addr})";
}
}
/// <summary>
/// 版本
/// </summary>
public string Version;
/// <summary>
/// 设备列表
/// </summary>
public List<PLCDevice> Devices = new List<PLCDevice>();
/// <summary>
/// 寄存器列表
/// </summary>
public List<PLCVariable> Variables = new List<PLCVariable>();
}
}
......@@ -86,15 +86,23 @@ namespace FLY.OBJComponents.Server
{
throw new Exception($"DeviceIndex = {var.DeviceIndex} var.Addr={var.Addr} var.Type={var.Type} 不能转换为 C#类型");
}
DataToRegs dr = plc.MapDataToRegs(
ModbusMapper.TranslateToPLCAddressArea(var.Mode),
var.Addr,
reg_type,
var.Scale,
this.ObjNames[var.OwnerName],
var.PropertyName);
if (dr != null)
drs.Add(dr);
try
{
DataToRegs dr = plc.MapDataToRegs(
ModbusMapper.TranslateToPLCAddressArea(var.Mode),
var.Addr,
reg_type,
var.Scale,
this.ObjNames[var.OwnerName],
var.PropertyName,
var.RegAddr,
var.OwnerName);
if (dr != null)
drs.Add(dr);
}
catch (Exception e) {
throw e;
}
}
foreach (var plc in this.PLCs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment