Commit 58cc4b86 authored by 潘栩锋's avatar 潘栩锋 🚴

FilmPositionDetect 服务远程通讯

parent 35705dbc
using AutoMapper;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FObjBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Thick.Base.Client
{
/// <summary>
///
/// </summary>
public class FilmPositionDetectServiceClient : FObjServiceClient, IFilmPositionDetectService
{
static Mapper Mapper { get; } = new AutoMapper.Mapper(new MapperConfiguration(c =>
{
c.CreateMap<FilmPositionDetectServiceClient, FILMPOS_OBJ_INTERFACE.Pack_Params>();
}));
/// <summary>
/// AD 曲线服务 客户端代理
/// </summary>
/// <param name="id"></param>
public FilmPositionDetectServiceClient(UInt32 id) : base(id) { }
/// <summary>
/// AD 曲线服务 客户端代理
/// </summary>
/// <param name="serviceId">服务id</param>
/// <param name="connName">连接器</param>
public FilmPositionDetectServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
#region 状态
/// <summary>
/// 线速度 m/min
/// </summary>
public double FilmVelocity { get; protected set; }
/// <summary>
/// 膜位置, m
/// </summary>
public double FilmPosition { get; protected set; }
/// <summary>
/// 工作中
/// </summary>
public bool IsRunning { get; protected set; }
/// <summary>
/// 当前正在使用的 与机头测厚仪偏移,单位m
/// </summary>
public double VDistanceWithHeaderInUsed { get; protected set; }
/// <summary>
/// 当前正在使用的 激光探头与 X光的偏移,单位m
/// </summary>
public double VSensorOffsetInUsed { get; protected set; }
/// <summary>
/// 已经重新开始测量
/// </summary>
public bool HasReset { get; protected set; }
#endregion
#region 参数
/// <summary>
/// 线速度阀值,低于阀值,速度直接变为0
/// </summary>
public double FilmVThreshold { get; set; }
/// <summary>
/// 线速度来源
/// </summary>
public FilmVSRC FilmVSrc { get; set; }
/// <summary>
/// 线速度:编码器2 mm/pulse
/// </summary>
public double Encoder2_mmpp { get; set; }
/// <summary>
/// 线速度:1圈多少mm
/// </summary>
public double MmOfR { get; set; }
/// <summary>
/// 本测厚仪探头与机头测厚仪探头距离单位m
/// </summary>
public double VDistanceWithHeader { get; set; }
/// <summary>
/// 纵向光纤传感器与本测厚仪探头距离 单位m;
/// 修改此值,会改变纵向偏移
/// </summary>
public double VSensorOffset { get; set; }
#endregion
/// <summary>
/// 主轴激光传感器检测到 1->0 变化 事件
/// </summary>
public event FilmPosAt01EventHandler FilmPosAt01Event;
/// <summary>
/// 设置膜位置为某值
/// </summary>
/// <param name="filmPos">极片位置m</param>
public void Reset(double filmPos)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(filmPos);
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
FILMPOS_OBJ_INTERFACE.CALL_RESET, Misc.Converter.StringToBytes(json));
}
/// <summary>
/// 把膜位置设置为 -VDistanceWithHeader
/// </summary>
public void Reset()
{
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
FILMPOS_OBJ_INTERFACE.CALL_RESET_2, null);
}
/// <summary>
/// 清除 hasReset标志位
/// </summary>
public void ClearResetState()
{
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
FILMPOS_OBJ_INTERFACE.CALL_CLEAR_RESET, null);
}
/// <summary>
/// 服务器 从 机头得到的 0->1 事件,给机尾
/// </summary>
/// <param name="filmPos">极片位置m</param>
public void SetFilmPosAt01(double filmPos)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(filmPos);
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
FILMPOS_OBJ_INTERFACE.CALL_SET_FILMPOS_AT01, Misc.Converter.StringToBytes(json));
}
/// <summary>
/// 停止测量
/// </summary>
public void Stop()
{
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
FILMPOS_OBJ_INTERFACE.CALL_STOP, null);
}
/// <summary>
/// 启动测量
/// </summary>
public void Start()
{
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
FILMPOS_OBJ_INTERFACE.CALL_START, null);
}
public void Apply()
{
var p = Mapper.Map<FILMPOS_OBJ_INTERFACE.Pack_Params>(this);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
CurrObjSys.SetValueEx(
mConn, mServerID, ID,
FILMPOS_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,
FILMPOS_OBJ_INTERFACE.GET_PARAMS);
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
FILMPOS_OBJ_INTERFACE.GET_STATE);
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID, 0xffffffff,
SENSE_CONFIG.ADD);
}
}
public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case FILMPOS_OBJ_INTERFACE.GET_PARAMS:
{
string json = Misc.Converter.BytesToString(infodata);
Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
}
break;
case FILMPOS_OBJ_INTERFACE.GET_STATE:
{
string json = Misc.Converter.BytesToString(infodata);
Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
}
break;
}
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
switch (infoid)
{
case FILMPOS_OBJ_INTERFACE.PUSH_FilmPosAt01Event:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<FilmPosAt01EventArgs>(json);
FilmPosAt01Event?.Invoke(this, p);
}
break;
default:
PushGetValue(from, srcid, infoid, infodata);
break;
}
}
}
}
......@@ -56,6 +56,7 @@
<Compile Include="Client\CoatingSegmentServiceClient.cs" />
<Compile Include="Client\CurveServiceClient.cs" />
<Compile Include="Client\DynAreaServiceClient.cs" />
<Compile Include="Client\FilmPositionDetectServiceClient.cs" />
<Compile Include="Client\FixServiceClient.cs" />
<Compile Include="Client\FlyADServiceClient.cs" />
<Compile Include="Client\GageInfoServiceClient.cs" />
......@@ -100,6 +101,7 @@
<Compile Include="IService\ITDGageService.cs" />
<Compile Include="OBJ_INTERFACE\BOLTMAP_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\BORDERSEARCH_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\FILMPOS_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\Pack_StringList.cs" />
<Compile Include="OBJ_INTERFACE\COATINGSEGMENT_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\CURVE_OBJ_INTERFACE.cs" />
......@@ -121,6 +123,7 @@
<Compile Include="Server.OBJProxy\CoatingSegmentSearch_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\Curve_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\DynArea_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\FilmPositionDetect_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\Fix_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\FlyAD_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\GageInfo_OBJProxy.cs" />
......@@ -176,6 +179,9 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper">
<Version>9.0.0</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
......
......@@ -13,7 +13,7 @@ namespace FLY.Thick.Base.IService
/// 通过辊接近开关,或者编码器2;
/// 支持同步;
/// </summary>
public interface IFilmPositionDetect : INotifyPropertyChanged
public interface IFilmPositionDetectService : INotifyPropertyChanged
{
#region 状态
/// <summary>
......
using FLY.Thick.Base.Common;
using System;
namespace FLY.Thick.Base.OBJ_INTERFACE
{
public class FILMPOS_OBJ_INTERFACE
{
#region Pack
public class Pack_Params
{
public double FilmVThreshold;
public FilmVSRC FilmVSrc;
public double Encoder2_mmpp;
public double MmOfR;
public double VDistanceWithHeader;
public double VSensorOffset;
}
public class Pack_State
{
public double FilmVelocity;
public double FilmPosition;
public bool IsRunning;
public double VDistanceWithHeaderInUsed;
public double VSensorOffsetInUsed;
public bool HasReset;
}
#endregion
#region GetValue
/// <summary>
/// Pack_Params
/// </summary>
public const UInt16 GET_PARAMS = 0;
/// <summary>
/// reponse: Pack_State
/// </summary>
public const UInt16 GET_STATE = 1;
#endregion
#region SetValue
/// <summary>
/// Pack_Params
/// </summary>
public const UInt16 SET_PARAMS = 0;
#endregion
#region PushMsg
/// <summary>
/// Pack_Params
/// </summary>
public const UInt16 PUSH_PARAMS = 0;
/// <summary>
/// reponse: Pack_State
/// </summary>
public const UInt16 PUSH_STATE = 1;
/// <summary>
/// reponse:FilmPosAt01EventArgs
/// </summary>
public const UInt16 PUSH_FilmPosAt01Event = 2;
#endregion
#region Call
/// <summary>
/// request double
/// </summary>
public const UInt16 CALL_RESET = 0;
/// <summary>
///
/// </summary>
public const UInt16 CALL_RESET_2 = 1;
/// <summary>
///
/// </summary>
public const UInt16 CALL_CLEAR_RESET = 2;
/// <summary>
/// request double
/// </summary>
public const UInt16 CALL_SET_FILMPOS_AT01 = 3;
/// <summary>
///
/// </summary>
public const UInt16 CALL_STOP = 4;
/// <summary>
///
/// </summary>
public const UInt16 CALL_START = 5;
#endregion
}
}
using AutoMapper;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Thick.Base.Server.OBJProxy
{
public class FilmPositionDetect_OBJProxy : FObj
{
static Mapper Mapper { get; } = new AutoMapper.Mapper(new MapperConfiguration(c =>
{
c.CreateMap<IFilmPositionDetectService, FILMPOS_OBJ_INTERFACE.Pack_Params>();
c.CreateMap<IFilmPositionDetectService, FILMPOS_OBJ_INTERFACE.Pack_State>();
}));
#region 延时推送 MARKNO
const int MARKNO_PUSH_PARAMS = 1;
const int MARKNO_PUSH_STATE = 2;
#endregion
IFilmPositionDetectService filmPositionDetectService;
public FilmPositionDetect_OBJProxy(int objsys_idx, UInt32 id, IFilmPositionDetectService filmPositionDetectService) : base(objsys_idx)
{
ID = id;
this.filmPositionDetectService = filmPositionDetectService;
this.filmPositionDetectService.PropertyChanged += FilmPositionDetectService_PropertyChanged;
}
string[] propertyNames_params = new string[] {
"FilmVThreshold","FilmVSrc","Encoder2_mmpp","MmOfR","VDistanceWithHeader","VSensorOffset"
};
string[] propertyNames_state = new string[] {
"FilmVelocity",
"FilmPosition","IsRunning","VDistanceWithHeaderInUsed","VSensorOffsetInUsed","HasReset"
};
private void FilmPositionDetectService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (propertyNames_params.Contains(e.PropertyName))
{
FObjBase.PollModule.Current.Poll_JustOnce(
new PollModule.PollHandler(delegate ()
{
byte[] buf;
GetValue(null, 0, FILMPOS_OBJ_INTERFACE.GET_PARAMS, out buf);
CurrObjSys.PushObjInfoEx(
this, FILMPOS_OBJ_INTERFACE.PUSH_PARAMS,
buf);
}), this, MARKNO_PUSH_PARAMS);
}
else if (propertyNames_state.Contains(e.PropertyName))
{
FObjBase.PollModule.Current.Poll_JustOnce(
new PollModule.PollHandler(delegate ()
{
byte[] buf;
GetValue(null, 0, FILMPOS_OBJ_INTERFACE.GET_STATE, out buf);
CurrObjSys.PushObjInfoEx(
this, FILMPOS_OBJ_INTERFACE.PUSH_STATE,
buf);
}), this, MARKNO_PUSH_STATE);
}
}
public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
{
infodata = null;
switch (memid)
{
case FILMPOS_OBJ_INTERFACE.GET_PARAMS:
{
var p = Mapper.Map<FILMPOS_OBJ_INTERFACE.Pack_Params>(filmPositionDetectService);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
infodata = Misc.Converter.StringToBytes(json);
}
break;
case FILMPOS_OBJ_INTERFACE.GET_STATE:
{
var p = Mapper.Map<FILMPOS_OBJ_INTERFACE.Pack_State>(filmPositionDetectService);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
infodata = Misc.Converter.StringToBytes(json);
}
break;
}
}
public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case FILMPOS_OBJ_INTERFACE.SET_PARAMS:
{
string json = Misc.Converter.BytesToString(infodata);
Newtonsoft.Json.JsonConvert.PopulateObject(json, this.filmPositionDetectService);
}break;
}
}
public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
{
switch (funcid)
{
case FILMPOS_OBJ_INTERFACE.CALL_RESET:
{
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject<double>(json);
filmPositionDetectService.Reset(p);
}break;
case FILMPOS_OBJ_INTERFACE.CALL_RESET_2:
{
filmPositionDetectService.Reset();
}
break;
case FILMPOS_OBJ_INTERFACE.CALL_CLEAR_RESET:
{
filmPositionDetectService.ClearResetState();
}
break;
case FILMPOS_OBJ_INTERFACE.CALL_SET_FILMPOS_AT01:
{
string json = Misc.Converter.BytesToString(infodata);
var p = JsonConvert.DeserializeObject<double>(json);
filmPositionDetectService.SetFilmPosAt01(p);
}
break;
case FILMPOS_OBJ_INTERFACE.CALL_STOP:
{
filmPositionDetectService.Stop();
}
break;
case FILMPOS_OBJ_INTERFACE.CALL_START:
{
filmPositionDetectService.Start();
}
break;
}
}
}
}
......@@ -16,7 +16,7 @@ namespace FLY.Thick.Base.Server
/// 膜位置检测;
/// 通过辊接近开关,或者编码器2
/// </summary>
public class FilmPositionDetect : IFilmPositionDetect
public class FilmPositionDetect : IFilmPositionDetectService
{
#region 输入口定义
/// <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