Commit 5f82430a authored by 潘栩锋's avatar 潘栩锋 🚴

添加 ModbusMapper 添加注解

parent 76075ffe
......@@ -173,7 +173,7 @@ namespace FLY.Modbus
DataToRegs dr = area_regs.regs[i];
if (endAddr < dr.addr)
{
//前面
//当前输入的全部PLC寄存器 在 dr的前面
break;
}
......@@ -192,10 +192,10 @@ namespace FLY.Modbus
if (plc_value[idx1] != vals.ElementAt(idx2))
{
plc_value[idx1] = vals.ElementAt(idx2);
area_regs.regs[i].isPlcValueChanged = true;
dr.isPlcValueChanged = true;//其中 一个PLC寄存器 被改变了
}
}
if (endAddr_act == dr.endAddr)
if (endAddr_act == dr.endAddr)//枚举到 dr 的最后一个寄存器了,触发动作
{
if (dr.isPlcValueChanged)
{
......@@ -366,6 +366,11 @@ namespace FLY.Modbus
/// 需要被更新的 寄存器数量
/// </summary>
public int DRNeedUpdateCnt { get; private set; }
/// <summary>
/// 计划列表更新时间
/// </summary>
public DateTime PlanUpdateTime { get; private set; }
/// <summary>
/// 总寄存器数量
/// </summary>
......@@ -399,12 +404,9 @@ namespace FLY.Modbus
dr.isNeedUpdate = true;
}
}
//foreach (DataToRegs dr in DRmap)
//{
// dr.isNeedUpdate = true;
//}
DRNeedUpdateCnt = DRmap.Count((dr) => dr.isNeedUpdate);
DRNeedUpdateCnt = DRmap.Count((dr) => dr.isNeedUpdate);
PlanUpdateTime = DateTime.Now;
foreach (var areaManager in mAreaManager)
areaManager.MakePlan();
}
......
......@@ -41,7 +41,7 @@ namespace FLY.Modbus
if (!regs[i].isNeedUpdate)
continue;
if (addr == -1)
if (addr == -1)//上次的计划已经结束,重新来
{
addr = regs[i].addr;
UInt16[] plc_value = (UInt16[])regs[i].plcValue;
......@@ -55,7 +55,7 @@ namespace FLY.Modbus
addr += maxOfOneRead;
num -= maxOfOneRead;
}
if (num > 0)
if (num > 0)//最后一些
plan.Add(new Plan(area, addr, num));
addr = -1;
}
......@@ -63,23 +63,29 @@ namespace FLY.Modbus
else
{
UInt16[] plc_value = (UInt16[])regs[i].plcValue;
int n = regs[i].addr + plc_value.Count() - 1 - addr + 1;
//新的 最后一个寄存器地址
int addr_end = regs[i].addr + plc_value.Count() - 1;
//总数量
int n = addr_end - addr + 1;
if (n <= maxOfOneRead)
{
//还没长于单次最大数量,累计进去
num = n;
}
else
{
//不行,太长,之前的截断,添加到 计划
plan_buffer.Add(new Plan(area, addr, num));
addr = -1;
//reg[i] 退回,下次再运算
i--;
}
}
}
if (addr != -1)
if (addr != -1)//上次还 添加到计划中
{
plan_buffer.Add(new Plan(area, addr, num));
addr = -1;
......
......@@ -14,7 +14,7 @@ namespace FLY.Modbus.WithThread
/// <summary>
/// 基于线程,所有动作都会堵塞,必须确保只有一个Task操作
/// </summary>
public class ClientTCP:INotifyPropertyChanged,IModbusClient
public class ClientTCP : INotifyPropertyChanged, IModbusClient
{
/// <summary>
/// 通信超时, 默认是 1s
......@@ -24,7 +24,7 @@ namespace FLY.Modbus.WithThread
/// socket 错误信息
/// </summary>
public string ErrMsg { get; set; }
/// <summary>
/// 连接成功
/// </summary>
......@@ -34,7 +34,7 @@ namespace FLY.Modbus.WithThread
/// 标识,modbus tcp的参数
/// </summary>
public byte UnitID = 1;
UInt16 tranid = 12;
UInt16 GetFreeTranID()
{
......@@ -46,6 +46,14 @@ namespace FLY.Modbus.WithThread
/// 远端地址
/// </summary>
public IPEndPoint RemoteEP { get; set; }
public string RemoteAddr {
get {
if (RemoteEP != null) {
return RemoteEP.ToString();
}
return null;
}
}
Socket sock;
public event PropertyChangedEventHandler PropertyChanged;
......
......@@ -206,16 +206,22 @@ namespace FLY.OBJComponents.Server
//object value = plc.GetNameData(e.Owener, e.PropertyName);
//这是从PLC 更新过来的,不需要向PLC写入
FObjBase.PollModule.Current.Dispatcher.Invoke(new SetValueHandler((owner, propertyname, value) =>
//FObjBase.PollModule.Current.Dispatcher.Invoke(new SetValueHandler((owner, propertyName, value) =>
//{
// isShield = true;
// Misc.PropertiesManager.SetValue(owner, propertyName, value);
// isShield = false;
//}), dr.owner, dr.propertyName, dr.value);
FObjBase.PollModule.Current.Dispatcher.Invoke(() =>
{
isShield = true;
Misc.PropertiesManager.SetValue(dr.owner, dr.propertyName, dr.value);
isShield = false;
}), dr.owner, dr.propertyName, dr.value);
});
}
delegate void SetValueHandler(object owner, string propertyname, object value);
//delegate void SetValueHandler(object owner, string propertyname, object value);
/// <summary>
/// 设置更新计划
/// </summary>
......
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