Commit 9e6a0e4b authored by 潘栩锋's avatar 潘栩锋 🚴

优化 IPLCProxySystemService 直接使用 Reflect_ServiceClient 作为远程代理

添加 Reflect_ServiceClient 添加 数据改变时,判断是否服务器发送过来的数据
修改 SetPLCUpdatePlan 修改 接口 函数 的参数
parent 33cc7eba
......@@ -27,6 +27,12 @@ namespace FObjBase.Reflect
/// 已经收到了 CALL_GetAllProperties, 全部属性都与服务器一致
/// </summary>
public bool IsSynced { get; private set; }
/// <summary>
/// 当前 INotifyPropertyChanged 对象 引发了 PropertyChanged, 是由于 接收到数据导致的
/// </summary>
public bool IsInPushValue { get; protected set; }
class AnyEvent
{
public string name;
......@@ -268,7 +274,7 @@ namespace FObjBase.Reflect
void request_PUSH_PropertyChanged(Reflect_OBJ_INTERFACE.ReflectData rData)
{
ignoreSet = true;
IsInPushValue = true;
var node = COMMON.FindNode(rootNode, rData.name);
if (node == null)
{
......@@ -280,7 +286,7 @@ namespace FObjBase.Reflect
string json = rData.data.ToString();
JsonConvert.PopulateObject(json, node.Obj);
IsInPushValue = false;
ignoreSet = false;
}
void request_PUSH_Event(Reflect_OBJ_INTERFACE.ReflectData rData)
......
......@@ -10,90 +10,33 @@ using System.Text;
namespace FLY.OBJComponents.Client
{
public class PLCProxySystemServiceClient : FObj, IPLCProxySystemService, IPropertyOpt
public class PLCProxySystemServiceClient : FObjBase.Reflect.Reflect_SeviceClient, IPLCProxySystemService
{
public Dictionary<string, INotifyPropertyChanged> ObjNames { get; private set; }
protected override Type InterfaceType => typeof(IPLCProxySystemService);
public bool IsConnected { get; private set; } = false;
SyncPropServiceClient syncPropServiceClient;
/// <summary>
/// 与PLC连接成功
/// </summary>
public bool IsConnectedWithPLC { get; set; } = false;
IFConn mConn;
UInt32 mServerID;
public event PropertyChangedEventHandler PropertyChanged;
public PLCProxySystemServiceClient(UInt32 serverID, Dictionary<string, INotifyPropertyChanged> objnames)
{
mServerID = serverID;
ObjNames = objnames;
syncPropServiceClient = new SyncPropServiceClient(
serverID + 1,
new Dictionary<string, INotifyPropertyChanged> {
{".", this }
});
}
public UInt32[] GetIDs()
{
return new UInt32[] { ID,
syncPropServiceClient.ID
};
}
public PLCProxySystemServiceClient(UInt32 serviceId) : base(serviceId) { }
public PLCProxySystemServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
public override void ConnectNotify(IFConn from)
{
mConn = from;
IsConnected = from.IsConnected;
if (from.IsConnected)
{
CurrObjSys.SenseConfigEx(mConn, mServerID, ID,
0xffffffff, SENSE_CONFIG.ADD);
}
}
#region IPLCProxySystemService
public void FeedPlan(long planID)
{
PLCOS_OBJ_INTERFACE.Pack_FeedPlanRequest pack = new PLCOS_OBJ_INTERFACE.Pack_FeedPlanRequest()
{
planid = planID
};
string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_FEED_PLAN, Misc.Converter.StringToBytes(json));
Call(nameof(FeedPlan), new { planID });
}
public void RemovePlan(long planID)
{
PLCOS_OBJ_INTERFACE.Pack_RemovePlanRequest pack = new PLCOS_OBJ_INTERFACE.Pack_RemovePlanRequest()
{
planid = planID
};
string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_REMOVE_PLAN, Misc.Converter.StringToBytes(json));
Call(nameof(RemovePlan), new { planID });
}
public void SetPlan(string objname, IEnumerable<string> propertynames, long planID)
{
PLCOS_OBJ_INTERFACE.Pack_SetPlanRequest pack = new PLCOS_OBJ_INTERFACE.Pack_SetPlanRequest()
{
objname = objname,
propertyNames = propertynames,
planid = planID
};
string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_SET_PLAN, Misc.Converter.StringToBytes(json));
Call(nameof(SetPlan), new { objname, propertynames, planID });
}
/// <summary>
......@@ -104,47 +47,8 @@ namespace FLY.OBJComponents.Client
/// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param>
public void SetPlan(string objname, IEnumerable<string> propertynames, AsyncCBHandler asyncDelegate, object asyncContext)
{
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request pack = new PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request()
{
objname = objname,
propertyNames = propertynames,
};
string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_SET_PLAN2, Misc.Converter.StringToBytes(json), asyncDelegate, asyncContext);
Call(nameof(SetPlan), new { objname, propertynames}, asyncDelegate, asyncContext);
}
#endregion
public string[] GetSyncPropNames()
{
return new string[] {
nameof(IsConnectedWithPLC)
};
}
public string[] GetNoSyncPropNames()
{
return null;
}
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, AsyncCBHandler asyncDelegate, object asyncContext)
{
switch (funcid)
{
case PLCOS_OBJ_INTERFACE.CALL_SET_PLAN2:
{
string json = Misc.Converter.BytesToString(retdata);
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse reponse = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse>(json);
//SetPlanReponseHandler setPlanReponseHandler = (SetPlanReponseHandler)asyncDelegate;
asyncDelegate(asyncContext, reponse.planid);
//setPlanReponseHandler(reponse.planid, asyncContext);
}
break;
}
}
}
}
......@@ -16,14 +16,14 @@ namespace FLY.OBJComponents.Client
string objname;
IEnumerable<string> propertynames;
public SetPLCUpdatePlan(IPLCProxySystemService plsos, INotifyPropertyChanged obj, IEnumerable<string> propertynames)
public SetPLCUpdatePlan(IPLCProxySystemService plsos, string objname, IEnumerable<string> propertynames)
{
PLCos = plsos;
this.propertynames = propertynames;
this.objname = PLCos.ObjNames.First((kv) => kv.Value == obj).Key;
this.objname = objname;// PLCos.ObjNames.First((kv) => kv.Value == obj).Key;
PLCos.PropertyChanged += PLCos_PropertyChanged;
timer = new DispatcherTimer()//120s 内必须再次注册
{
......@@ -36,23 +36,43 @@ namespace FLY.OBJComponents.Client
PLCos.FeedPlan(planid);
}
};
if (((PLCProxySystemServiceClient)PLCos).IsConnected)
if(IsTimeToSetPlan())
{
PLCos.SetPlan( this.objname, this.propertynames, (asyncContext,retData) =>
PLCos.SetPlan(this.objname, this.propertynames, (asyncContext, retData) =>
{
long planid = (long)retData;
this.planid = planid;
timer.Start();
}, null);
}
if (PLCos is PLCProxySystemServiceClient)
PLCos.PropertyChanged += PLCos_PropertyChanged;
}
bool IsTimeToSetPlan()
{
if (PLCos is PLCProxySystemServiceClient)
{
var _PLCos = PLCos as PLCProxySystemServiceClient;
if (_PLCos.IsConnected)
{
return true;
}
else {
return false;
}
}
else {
return true;
}
}
private void PLCos_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsConnected")
if (e.PropertyName == nameof(PLCProxySystemServiceClient.IsConnected))
{
if (((PLCProxySystemServiceClient)PLCos).IsConnected)
var _PLCos = PLCos as PLCProxySystemServiceClient;
if (_PLCos.IsConnected)
{
PLCos.SetPlan(objname, propertynames, (asyncContext, retData) =>
{
......
......@@ -17,10 +17,6 @@ namespace FLY.OBJComponents.IService
/// 与PLC连接成功
/// </summary>
bool IsConnectedWithPLC { get; }
/// <summary>
/// 对象名称
/// </summary>
Dictionary<string, INotifyPropertyChanged> ObjNames { get; }
/// <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