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

添加 ModbusMapper 添加注解

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