using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using FObjBase;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FLY.Thick.Blowing.IService;
using Misc;
using Newtonsoft.Json;
namespace FLY.Thick.Blowing.Client
{
public class BlowingFixServiceClient : BlowingServiceClient, IBlowingFixService
{
#region IRenZiJiaService 成员
#region 温修
///
/// 追边开始按钮自锁
///
public bool IsBtnSelfHold { get; set; }
public RenZiJiaFixEPCType EPCType { get; set; }
///
/// 采样时间, 默认2s
///
public TimeSpan SampleConsume { get; set; } = TimeSpan.FromSeconds(2);
///
/// 温修间隔,默认45分钟
///
public TimeSpan SampleInterval { get; set; } = TimeSpan.FromMinutes(45);
///
/// 当前温修计时,大于温修间隔就会去温修
///
public TimeSpan SampleTimer { get; protected set; } = TimeSpan.Zero;
///
/// 回到边界后,再等待一段时间,那就肯定找到边界了。 默认5s
///
public TimeSpan BackEdgeWait { get; set; } = TimeSpan.FromSeconds(5);
///
/// 采样得到的样品AD
///
public int SampleAD { get; protected set; } = -1;
///
/// 追边运行中!
///
public bool EPCIsRunning { get; set; }
#endregion
#endregion
public BlowingFixServiceClient(UInt32 serverid) : base(serverid) { }
public BlowingFixServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
#region 功能
public override void Apply()
{
base.Apply();
string json = JsonConvert.SerializeObject(new BLOWINGFIX_OBJ_INTERFACE.Pack_EPC()
{
epctype = EPCType,
sampleconsume = SampleConsume,
sampleinterval = SampleInterval,
backedgewait = BackEdgeWait,
isBtnSelfHold = IsBtnSelfHold
});
CurrObjSys.SetValueEx(
mConn, mServerID, ID,
BLOWINGFIX_OBJ_INTERFACE.SET_EPC,
Misc.Converter.StringToBytes(json));
}
public void EPCStart()
{
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
BLOWINGFIX_OBJ_INTERFACE.CALL_EPCSTART, null);
}
public void EPCStop()
{
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
BLOWINGFIX_OBJ_INTERFACE.CALL_EPCSTOP, null);
}
///
/// 获取 立式旋转架 的 膜距离增量
///
/// 开始时间
/// retdata = GetFilmLength3DReponse
///
public void GetADList(DateTime begin, AsyncCBHandler AsyncDelegate, object AsyncState)
{
string json = JsonConvert.SerializeObject(new GetADListRequest()
{
begin = begin
});
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
BLOWINGFIX_OBJ_INTERFACE.CALL_GETADLIST,
Misc.Converter.StringToBytes(json),
AsyncDelegate, AsyncState);
}
#endregion
public override void ConnectNotify(IFConn from)
{
base.ConnectNotify(from);
if (from.IsConnected)
{
//获取所有数据,设置推送
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
BLOWINGFIX_OBJ_INTERFACE.GET_EPC);
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
BLOWINGFIX_OBJ_INTERFACE.GET_EPCSTATE);
}
}
public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
base.PushGetValue(from, srcid, memid, infodata);
switch (memid)
{
case BLOWINGFIX_OBJ_INTERFACE.GET_EPC:
{
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject(json);
EPCType = p.epctype;
SampleConsume = p.sampleconsume;
SampleInterval = p.sampleinterval;
BackEdgeWait = p.backedgewait;
IsBtnSelfHold = p.isBtnSelfHold;
}break;
case BLOWINGFIX_OBJ_INTERFACE.GET_EPCSTATE:
{
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject(json);
SampleTimer = p.sampletimer;
EPCIsRunning = p.isrunning;
SampleAD = p.samplead;
}break;
}
}
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
{
switch (funcid)
{
case BLOWINGFIX_OBJ_INTERFACE.CALL_GETADLIST:
{
string json = Misc.Converter.BytesToString(retdata);
var p = JsonConvert.DeserializeObject(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
}
break;
}
}
}
}