using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using FObjBase;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FLY.Thick.Base.Common;
using Newtonsoft.Json;
using FLY.OBJComponents.Client;
namespace FLY.Thick.Base.Client
{
///
/// 系统参数服务 客户端代理
///
public class InitParamServiceClient : FObjServiceClient, IInitParamService
{
///
/// 系统参数服务 客户端代理 构造
///
/// 服务Id
public InitParamServiceClient(UInt32 id) : base(id) { }
///
/// 系统参数服务 客户端代理 构造
///
/// 服务Id
/// 连接器
public InitParamServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
#region 属性,成员变量的代理
///
/// 扫描架长
///
public int PosLength { get; set; } = 8900;
///
/// 自动归原点间距
///
public int AutoOrgInterval { get; set; } = 30;
///
/// 从 flyad7 获取的
///
public int PosOfGrid { get; set; } = 10;
///
/// timeGridAdv 使能
///
public bool IsTimeGridAdvEnabled { get; set; }
///
/// ad 滞后量 ms
///
public int ADLag { get; set; } = 0;
///
/// 编码器1 mm/pulse
///
public double Encoder1_mmpp { get; set; } = 0.1;
///
/// 设置的速度,与 实际速度比例
///
public double Speed1Scale { get; set; } =1;
///
/// 线速度来源
///
public FilmVSRC FilmVSrc { get; set; } = FilmVSRC.ROUND;
///
/// 最小线速度 m/min
///
public int FilmVThreshold { get; set; } = 5;
///
/// 编码器2 mm/pulse
///
public double Encoder2_mmpp { get; set; } = 0.1;
///
/// 编码器2 放大
///
public float Encoder2_comp { get; set; } = 1;
///
/// //1圈多少mm
///
public double MmOfR { get; set; } = 314;
///
/// 数据有效源
///
public DATAVALIDSRC DataValidSrc { get; set; } = DATAVALIDSRC.VALID;
///
/// 当数据有效状态改变,自动按F1,F3
///
public bool AutoF1F3 { get; set; }
///
/// 当数据有效状态 无效->有效 ,等待多久重新扫描 ,单位s
///
public int ReStartDelay { get; set; } = 5;
#region 速度
///
/// 扫描时速度
///
public UInt32 VScan { get; set; } = 8000;
///
/// 调试时速度,向前走,向后走
///
public UInt32 VJOG { get; set; } = 5000;
///
/// 精确速度 Velocity Of Accuracy 如: 机架修正, 样品取样, 机架信息获取
///
public UInt32 VAccuracy { get; set; } = 3000;
///
/// 开始速度 Start Velocity
///
public UInt32 SVelocity { get; set; } = 500;
///
/// 加速时间
///
public UInt32 ATime { get; set; } = 200;
///
/// 减速时间
///
public UInt32 DTime { get; set; } = 200;
///
/// 归0速度1
///
public UInt32 HVelocity1 { get; set; } = 5000;
///
/// 归0速度2
///
public UInt32 HVelocity2 { get; set; } = 1000;
#endregion
///
/// 有按样标定硬件
///
public bool HasProfileSample { get; set; }
///
/// 有小托辊
///
public bool HasHold { get; set; }
///
/// 数据库保存的月数
///
public int DBKeepMonth { get; set; }
///
/// 数据库路径
///
public string DbPath { get; set; }
#endregion
public void Apply()
{
INITPARAM_OBJ_INTERFACE.Pack_Params p = new INITPARAM_OBJ_INTERFACE.Pack_Params()
{
poslength = PosLength,
auto_org_interval = AutoOrgInterval,
isTimeGridAdvEnabled = IsTimeGridAdvEnabled,
adlag = ADLag,
encoder1_mmpp = Encoder1_mmpp,
speed1scale = Speed1Scale,
filmVSrc= FilmVSrc,
filmVThreshold = FilmVThreshold,
encoder2_mmpp = Encoder2_mmpp,
mmOfR = MmOfR,
encoder2_comp = Encoder2_comp,
data_valid_src = DataValidSrc,
autof1f3 = AutoF1F3,
restartDelay = ReStartDelay,
vscan = VScan,
vjog = VJOG,
vaccuracy = VAccuracy,
svelocity = SVelocity,
atime = ATime,
dtime = DTime,
hvelocity1 = HVelocity1,
hvelocity2 = HVelocity2,
hasProfileSample = HasProfileSample,
hasHold = HasHold,
dBKeepMonth = DBKeepMonth,
dbPath = DbPath
};
string json = JsonConvert.SerializeObject(p);
//获取所有数据,设置推送
CurrObjSys.SetValueEx(
mConn, mServerID, ID,
INITPARAM_OBJ_INTERFACE.SET_PARAMS,
Misc.Converter.StringToBytes(json));
}
public override void ConnectNotify(IFConn from)
{
base.ConnectNotify(from);
if (from.IsConnected)
{
//获取所有数据,设置推送
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
BORDERSEARCH_OBJ_INTERFACE.GET_PARAMS);
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID, 0xffffffff, SENSE_CONFIG.ADD);
}
}
public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case INITPARAM_OBJ_INTERFACE.GET_PARAMS:
{
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject(json);
PosLength = p.poslength;
AutoOrgInterval = p.auto_org_interval;
PosOfGrid = p.posOfGrid;
IsTimeGridAdvEnabled = p.isTimeGridAdvEnabled;
ADLag = p.adlag;
Encoder1_mmpp = p.encoder1_mmpp;
Speed1Scale = p.speed1scale;
FilmVSrc = p.filmVSrc;
FilmVThreshold = p.filmVThreshold;
Encoder2_mmpp = p.encoder2_mmpp;
Encoder2_comp = p.encoder2_comp;
MmOfR = p.mmOfR;
DataValidSrc = p.data_valid_src;
AutoF1F3 = p.autof1f3;
ReStartDelay = p.restartDelay;
VScan = p.vscan;
VJOG = p.vjog;
VAccuracy = p.vaccuracy;
SVelocity = p.svelocity;
ATime = p.atime;
DTime = p.dtime;
HVelocity1 = p.hvelocity1;
HVelocity2 = p.hvelocity2;
HasProfileSample = p.hasProfileSample;
HasHold = p.hasHold;
DBKeepMonth = p.dBKeepMonth;
DbPath = p.dbPath;
} break;
}
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
PushGetValue(from, srcid, infoid, infodata);
}
}
}