Commit 4a487a06 authored by 潘栩锋's avatar 潘栩锋 🚴

1.

Merge remote-tracking branch 'origin/feature-AdvTrendData-20191123' into dev6.0

2. getsample界面通过容器获取gageinfo
parents 419b7d69 bf850c30
...@@ -40,22 +40,11 @@ namespace FLY.Thick.Base.UI ...@@ -40,22 +40,11 @@ namespace FLY.Thick.Base.UI
/// <summary> /// <summary>
/// 初始化 /// 初始化
/// </summary> /// </summary>
/// <param name="dynAreaService"></param> /// <param name="container">容器</param>
/// <param name="initParam"></param>
/// <param name="gageService"></param>
/// <param name="warningReasonWindow"></param>
[InjectionMethod] [InjectionMethod]
public void Init( public void Init(IUnityContainer container)
IDynAreaService dynAreaService,
IInitParamService initParam,
ITDGageService gageService,
WarningReasonWindow warningReasonWindow)
{ {
viewModel.Init( container.BuildUp(viewModel);
dynAreaService.DynArea,
initParam,
gageService,
warningReasonWindow);
} }
} }
/// <summary> /// <summary>
......
...@@ -11,6 +11,7 @@ using System.Text; ...@@ -11,6 +11,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Threading; using System.Windows.Threading;
using Unity;
namespace FLY.Thick.Base.UI namespace FLY.Thick.Base.UI
{ {
...@@ -79,15 +80,23 @@ namespace FLY.Thick.Base.UI ...@@ -79,15 +80,23 @@ namespace FLY.Thick.Base.UI
}); });
} }
/// <summary>
/// 初始化
/// </summary>
/// <param name="dynAreaService"></param>
/// <param name="initParam"></param>
/// <param name="gageService"></param>
/// <param name="warningReasonWindow"></param>
[InjectionMethod]
public void Init( public void Init(
DynArea dynArea, IDynAreaService dynAreaService,
IInitParamService initParam, IInitParamService initParam,
ITDGageService gageService, ITDGageService gageService,
WarningReasonWindow warningReasonWindow) WarningReasonWindow warningReasonWindow)
{ {
mTDGageService = gageService; mTDGageService = gageService;
mDynArea = dynArea; mDynArea = dynAreaService.DynArea;
mInitParam = initParam; mInitParam = initParam;
mWindow = warningReasonWindow; mWindow = warningReasonWindow;
......
...@@ -59,6 +59,10 @@ ...@@ -59,6 +59,10 @@
<TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="CRC" /> <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="CRC" />
<ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding HasCRC}"/> <ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding HasCRC}"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Style="{StaticResource ResourceKey=TextBlockStyle_FieldHeaderEditable}" Text="不使用AD盒速度" />
<ToggleButton Style="{StaticResource ToggleButtonStyle1}" IsChecked="{Binding IsCalSpeed}" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="5" > <StackPanel Orientation="Vertical" Margin="5" >
<TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="脉冲/数据格" /> <TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="脉冲/数据格" />
<TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding PosOfGrid}" /> <TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Text="{Binding PosOfGrid}" />
......
using System; using FLY.Thick.Base.IService;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.UI;
using Unity; using Unity;
using System.ComponentModel;
namespace FLY.Thick.Base.UI namespace FLY.Thick.Base.UI
{ {
/// <summary> /// <summary>
...@@ -40,10 +29,10 @@ namespace FLY.Thick.Base.UI ...@@ -40,10 +29,10 @@ namespace FLY.Thick.Base.UI
} }
[InjectionMethod] [InjectionMethod]
public void Init( public void Init(
IUnityContainer container, IUnityContainer container,
IGetSampleService getSampleService, IGetSampleService getSampleService,
IInitParamService initParamService, IInitParamService initParamService,
IGageInfoService gageInfoService) IGageInfoService gageInfoService)
{ {
this.getSampleService = getSampleService; this.getSampleService = getSampleService;
...@@ -95,7 +84,7 @@ namespace FLY.Thick.Base.UI ...@@ -95,7 +84,7 @@ namespace FLY.Thick.Base.UI
FLY.ControlLibrary.Window_Tip.Show("应用成功", FLY.ControlLibrary.Window_Tip.Show("应用成功",
null, null,
TimeSpan.FromSeconds(2)); TimeSpan.FromSeconds(2));
} }
private void button_getorgad_Click(object sender, RoutedEventArgs e) private void button_getorgad_Click(object sender, RoutedEventArgs e)
...@@ -146,33 +135,35 @@ namespace FLY.Thick.Base.UI ...@@ -146,33 +135,35 @@ namespace FLY.Thick.Base.UI
TimeSpan.FromSeconds(2)); TimeSpan.FromSeconds(2));
return; return;
} }
sampleCell.OrgAD = (ad1+ad2)/2; sampleCell.OrgAD = (ad1 + ad2) / 2;
} }
} }
FLY.ControlLibrary.Window_Tip.Show("设置完成", FLY.ControlLibrary.Window_Tip.Show("设置完成",
null, null,
TimeSpan.FromSeconds(2)); TimeSpan.FromSeconds(2));
} }
private void button_gageinfo_Click(object sender, RoutedEventArgs e) private void button_gageinfo_Click(object sender, RoutedEventArgs e)
{ {
if (container.IsRegistered<Page>("pgGageInfo")) Page p = (container.IsRegistered<Page>("pgGageInfo")) ? container.Resolve<Page>("pgGageInfo") : new PgGageInfo();
{ container.BuildUp(p);
var p = container.Resolve<Page>("pgGageInfo"); NavigationService.Navigate(p);
NavigationService.Navigate(p);
}
else
{
var p = container.Resolve<PgGageInfo>();
//PgGageInfo p = new PgGageInfo();
//container.BuildUp(p);
NavigationService.Navigate(p);
}
} }
private void btnGetTempDatasClick(object sender, RoutedEventArgs e)
{
getSampleService.GetTempFilterDatas((asyncContext, retData) =>
{
var ll = retData as List<List<TempFilterData>>;
tempdatas.ItemsSource = ll;
FLY.ControlLibrary.Window_Tip.Show("加载完成",
$"共加载{ll.Count()}列数据",
TimeSpan.FromSeconds(2));
}, null);
}
} }
public class GetSampleVm : INotifyPropertyChanged public class GetSampleVm : INotifyPropertyChanged
...@@ -245,7 +236,7 @@ namespace FLY.Thick.Base.UI ...@@ -245,7 +236,7 @@ namespace FLY.Thick.Base.UI
public bool IsChanged { get; set; } public bool IsChanged { get; set; }
} }
public class GetSampleVmUt:INotifyPropertyChanged public class GetSampleVmUt : INotifyPropertyChanged
{ {
public GetSampleVmUt() public GetSampleVmUt()
{ {
...@@ -327,8 +318,8 @@ namespace FLY.Thick.Base.UI ...@@ -327,8 +318,8 @@ namespace FLY.Thick.Base.UI
#endregion #endregion
} }
/// <summary> /// <summary>
/// 列表转序号 /// 列表转序号
...@@ -381,7 +372,7 @@ namespace FLY.Thick.Base.UI ...@@ -381,7 +372,7 @@ namespace FLY.Thick.Base.UI
//在 设计模式中, View为null, 所以下面必须判断 //在 设计模式中, View为null, 所以下面必须判断
if (cv != null) if (cv != null)
{ {
switch (cv.IndexOf(value)) switch (cv.IndexOf(value))
{ {
case 0: case 0:
return "正向"; return "正向";
......
...@@ -42,6 +42,10 @@ namespace FLY.Thick.Base.Client ...@@ -42,6 +42,10 @@ namespace FLY.Thick.Base.Client
} }
} }
} }
/// <summary>
/// 通过脉冲计算速度,不使用AD盒的输出
/// </summary>
public bool IsCalSpeed { get; set; } = true;
public int PosLen { get; set; } public int PosLen { get; set; }
...@@ -82,7 +86,8 @@ namespace FLY.Thick.Base.Client ...@@ -82,7 +86,8 @@ namespace FLY.Thick.Base.Client
posoffset = PosOffset, posoffset = PosOffset,
jogvelocity = JogVelocity, jogvelocity = JogVelocity,
hasCRC = HasCRC, hasCRC = HasCRC,
gridsmooth = GridSmooth gridsmooth = GridSmooth,
IsCalSpeed = IsCalSpeed
}; };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p); string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
...@@ -189,6 +194,7 @@ namespace FLY.Thick.Base.Client ...@@ -189,6 +194,7 @@ namespace FLY.Thick.Base.Client
Ratio02 = p.ratio02; Ratio02 = p.ratio02;
HasCRC = p.hasCRC; HasCRC = p.hasCRC;
GridSmooth = p.gridsmooth; GridSmooth = p.gridsmooth;
IsCalSpeed = p.IsCalSpeed;
} break; } break;
} }
} }
......
...@@ -72,6 +72,22 @@ namespace FLY.Thick.Base.Client ...@@ -72,6 +72,22 @@ namespace FLY.Thick.Base.Client
[JsonProperty] [JsonProperty]
public int Window { get; set; } public int Window { get; set; }
/// <summary>
/// 使用%方式检查异常
/// </summary>
[JsonProperty]
public bool IsCheckByPercent { get; set; } = true;
/// <summary>
/// 异常% 单位%
/// </summary>
[JsonProperty]
public double ErrPercent { get; set; } = 2;
/// <summary>
/// 异常值
/// </summary>
[JsonProperty]
public int ErrValue { get; set; } = 200;
/// <summary> /// <summary>
/// 样品 /// 样品
/// </summary> /// </summary>
...@@ -109,6 +125,9 @@ namespace FLY.Thick.Base.Client ...@@ -109,6 +125,9 @@ namespace FLY.Thick.Base.Client
velocity = Velocity, velocity = Velocity,
range = Range, range = Range,
window = Window, window = Window,
IsCheckByPercent = IsCheckByPercent,
ErrPercent =ErrPercent,
ErrValue = ErrValue,
search = Search, search = Search,
samples = from sample in Samples samples = from sample in Samples
select select
...@@ -175,7 +194,10 @@ namespace FLY.Thick.Base.Client ...@@ -175,7 +194,10 @@ namespace FLY.Thick.Base.Client
Range = p.range; Range = p.range;
Velocity = p.velocity; Velocity = p.velocity;
Window = p.window; Window = p.window;
Search = p.search; IsCheckByPercent = p.IsCheckByPercent;
ErrPercent = p.ErrPercent;
ErrValue = p.ErrValue;
for (int i = 0; i < Samples.Count() && i < p.samples.Count(); i++) for (int i = 0; i < Samples.Count() && i < p.samples.Count(); i++)
{ {
var sample_src = p.samples.ElementAt(i); var sample_src = p.samples.ElementAt(i);
...@@ -186,6 +208,7 @@ namespace FLY.Thick.Base.Client ...@@ -186,6 +208,7 @@ namespace FLY.Thick.Base.Client
sample_desp.OrgAD = sample_src.orgad; sample_desp.OrgAD = sample_src.orgad;
sample_desp.Position = sample_src.position; sample_desp.Position = sample_src.position;
} }
Search = p.search;
for (int i = 0; i < Features.Count() && i < p.features.Count(); i++) for (int i = 0; i < Features.Count() && i < p.features.Count(); i++)
{ {
var feature_src = p.features.ElementAt(i); var feature_src = p.features.ElementAt(i);
...@@ -230,6 +253,23 @@ namespace FLY.Thick.Base.Client ...@@ -230,6 +253,23 @@ namespace FLY.Thick.Base.Client
{ {
PushGetValue(from, srcid, infoid, infodata); PushGetValue(from, srcid, infoid, infodata);
} }
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
{
switch (funcid) {
case GETSAMPLE_OBJ_INTERFACE.CALL_GET_TEMPDATAS:
{
string json = Misc.Converter.BytesToString(retdata);
var reponse = Newtonsoft.Json.JsonConvert.DeserializeObject<List<List<TempFilterData>>>(json);
(AsyncDelegate as AsyncCBHandler)(AsyncState, reponse);
}
break;
}
}
public void GetTempFilterDatas(AsyncCBHandler asyncCB, object asyncContext)
{
CurrObjSys.CallFunctionEx(mConn, mServerID, ID, GETSAMPLE_OBJ_INTERFACE.CALL_GET_TEMPDATAS, null, asyncCB, asyncContext);
}
} }
} }
...@@ -6,9 +6,13 @@ using FLY.Thick.Base.Common; ...@@ -6,9 +6,13 @@ using FLY.Thick.Base.Common;
using System.ComponentModel; using System.ComponentModel;
using Newtonsoft.Json; using Newtonsoft.Json;
using PropertyChanged; using PropertyChanged;
using FObjBase;
namespace FLY.Thick.Base.IService namespace FLY.Thick.Base.IService
{ {
/// <summary>
///
/// </summary>
public interface IGetSampleService:INotifyPropertyChanged public interface IGetSampleService:INotifyPropertyChanged
{ {
/// <summary> /// <summary>
...@@ -36,7 +40,18 @@ namespace FLY.Thick.Base.IService ...@@ -36,7 +40,18 @@ namespace FLY.Thick.Base.IService
/// </summary> /// </summary>
int Window { get; set; } int Window { get; set; }
/// <summary>
/// 使用%方式检查异常
/// </summary>
bool IsCheckByPercent { get; set; }
/// <summary>
/// 异常%
/// </summary>
double ErrPercent { get; set; }
/// <summary>
/// 异常值
/// </summary>
int ErrValue { get; set; }
/// <summary> /// <summary>
/// 参数:样品点参数 /// 参数:样品点参数
/// </summary> /// </summary>
...@@ -60,6 +75,36 @@ namespace FLY.Thick.Base.IService ...@@ -60,6 +75,36 @@ namespace FLY.Thick.Base.IService
/// 应用 /// 应用
/// </summary> /// </summary>
void Apply(); void Apply();
/// <summary>
/// 返回 List(List(TempFilterData))
/// </summary>
/// <param name="asyncCB"></param>
/// <param name="asyncContext"></param>
void GetTempFilterDatas(AsyncCBHandler asyncCB, object asyncContext);
}
/// <summary>
/// 采样记录
/// </summary>
public class TempFilterData
{
/// <summary>
/// 采集时间
/// </summary>
public DateTime Time { get; set; }
/// <summary>
/// Ad值
/// </summary>
public int Ad { get; set; }
/// <summary>
/// 滤波后的AD值
/// </summary>
public int FilterAd { get; set; }
/// <summary>
/// 复位
/// </summary>
public bool IsReset { get; set; }
} }
/// <summary> /// <summary>
......
...@@ -24,6 +24,7 @@ namespace FLY.Thick.Base.OBJ_INTERFACE ...@@ -24,6 +24,7 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
public UInt32 jogvelocity; public UInt32 jogvelocity;
public bool hasCRC; public bool hasCRC;
public int gridsmooth; public int gridsmooth;
public bool IsCalSpeed;
} }
......
...@@ -31,6 +31,9 @@ namespace FLY.Thick.Base.OBJ_INTERFACE ...@@ -31,6 +31,9 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
public UInt32 velocity; public UInt32 velocity;
public int range; public int range;
public int window; public int window;
public bool IsCheckByPercent;
public double ErrPercent;
public int ErrValue;
public IEnumerable<Pack_Params_SampleCell> samples; public IEnumerable<Pack_Params_SampleCell> samples;
public int search; public int search;
public IEnumerable<Pack_Params_SampleFeature> features; public IEnumerable<Pack_Params_SampleFeature> features;
...@@ -74,5 +77,13 @@ namespace FLY.Thick.Base.OBJ_INTERFACE ...@@ -74,5 +77,13 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
public const UInt16 PUSH_PARAMS = 0; public const UInt16 PUSH_PARAMS = 0;
public const UInt16 PUSH_STATE = 1; public const UInt16 PUSH_STATE = 1;
#endregion #endregion
#region CallFunction
/// <summary>
/// request:null
/// reponse:List(List(TempFilterData))
/// </summary>
public const UInt16 CALL_GET_TEMPDATAS = 0;
#endregion
} }
} }
...@@ -36,6 +36,7 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -36,6 +36,7 @@ namespace FLY.Thick.Base.Server.OBJProxy
if ((e.PropertyName == "LocalEP") || if ((e.PropertyName == "LocalEP") ||
(e.PropertyName == "HasCRC") || (e.PropertyName == "HasCRC") ||
(e.PropertyName == "GridSmooth") || (e.PropertyName == "GridSmooth") ||
(e.PropertyName == "IsCalSpeed") ||
(e.PropertyName == "PosOfGrid") || (e.PropertyName == "PosOfGrid") ||
(e.PropertyName == "PosLen") || (e.PropertyName == "PosLen") ||
(e.PropertyName == "MotorType") || (e.PropertyName == "MotorType") ||
...@@ -69,6 +70,7 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -69,6 +70,7 @@ namespace FLY.Thick.Base.Server.OBJProxy
ep = mFlyAD.LocalEP.ToString(), ep = mFlyAD.LocalEP.ToString(),
hasCRC = mFlyAD.HasCRC, hasCRC = mFlyAD.HasCRC,
gridsmooth = mFlyAD.GridSmooth, gridsmooth = mFlyAD.GridSmooth,
IsCalSpeed = mFlyAD.IsCalSpeed,
posofgrid = mFlyAD.PosOfGrid, posofgrid = mFlyAD.PosOfGrid,
motortype = (MOTORTYPE) mFlyAD.MotorType, motortype = (MOTORTYPE) mFlyAD.MotorType,
poslen = mFlyAD.PosLen, poslen = mFlyAD.PosLen,
...@@ -98,6 +100,7 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -98,6 +100,7 @@ namespace FLY.Thick.Base.Server.OBJProxy
mFlyAD.HasCRC = p.hasCRC; mFlyAD.HasCRC = p.hasCRC;
mFlyAD.GridSmooth = p.gridsmooth; mFlyAD.GridSmooth = p.gridsmooth;
mFlyAD.IsCalSpeed = p.IsCalSpeed;
var ep = Misc.StringConverter.ToIPEndPoint(p.ep); var ep = Misc.StringConverter.ToIPEndPoint(p.ep);
if(!mFlyAD.LocalEP.Equals(ep)) if(!mFlyAD.LocalEP.Equals(ep))
mFlyAD.Connect(ep); mFlyAD.Connect(ep);
......
...@@ -97,7 +97,9 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -97,7 +97,9 @@ namespace FLY.Thick.Base.Server.OBJProxy
(e.PropertyName == "Velocity") || (e.PropertyName == "Velocity") ||
(e.PropertyName == "Range") || (e.PropertyName == "Range") ||
(e.PropertyName == "Window") || (e.PropertyName == "Window") ||
(e.PropertyName == "OnePointIsOffset") || (e.PropertyName == "IsCheckByPercent") ||
(e.PropertyName == "ErrPercent") ||
(e.PropertyName == "ErrValue") ||
(e.PropertyName == "Search")) (e.PropertyName == "Search"))
{ {
push_params(); push_params();
...@@ -122,25 +124,31 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -122,25 +124,31 @@ namespace FLY.Thick.Base.Server.OBJProxy
range = mGetSampleService.Range, range = mGetSampleService.Range,
velocity = mGetSampleService.Velocity, velocity = mGetSampleService.Velocity,
window = mGetSampleService.Window, window = mGetSampleService.Window,
search = mGetSampleService.Search, IsCheckByPercent = mGetSampleService.IsCheckByPercent,
samples = from sample in mGetSampleService.Samples ErrPercent = mGetSampleService.ErrPercent,
ErrValue = mGetSampleService.ErrValue,
search = mGetSampleService.Search
};
p.samples = (from sample in mGetSampleService.Samples
select
new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleCell()
{
enable = sample.Enable,
justForCheck = sample.JustForCheck,
orgad = sample.OrgAD,
position = sample.Position
});
p.features = (from feature in mGetSampleService.Features
select select
new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleCell() new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleFeature()
{ {
enable = sample.Enable, enable = feature.Enable,
justForCheck = sample.JustForCheck, startpos = feature.StartPos,
orgad = sample.OrgAD, endpos = feature.EndPos
position = sample.Position });
},
features = from feature in mGetSampleService.Features
select
new GETSAMPLE_OBJ_INTERFACE.Pack_Params_SampleFeature()
{
enable = feature.Enable,
startpos = feature.StartPos,
endpos = feature.EndPos
}
};
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p); string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
infodata = Misc.Converter.StringToBytes(json); infodata = Misc.Converter.StringToBytes(json);
} break; } break;
...@@ -188,6 +196,9 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -188,6 +196,9 @@ namespace FLY.Thick.Base.Server.OBJProxy
mGetSampleService.Range = p.range; mGetSampleService.Range = p.range;
mGetSampleService.Velocity = p.velocity; mGetSampleService.Velocity = p.velocity;
mGetSampleService.Window = p.window; mGetSampleService.Window = p.window;
mGetSampleService.IsCheckByPercent = p.IsCheckByPercent;
mGetSampleService.ErrPercent = p.ErrPercent;
mGetSampleService.ErrValue = p.ErrValue;
mGetSampleService.Search = p.search; mGetSampleService.Search = p.search;
for(int i=0;i<mGetSampleService.Samples.Count() && i<p.samples.Count();i++) for(int i=0;i<mGetSampleService.Samples.Count() && i<p.samples.Count();i++)
...@@ -215,5 +226,20 @@ namespace FLY.Thick.Base.Server.OBJProxy ...@@ -215,5 +226,20 @@ namespace FLY.Thick.Base.Server.OBJProxy
} break; } break;
} }
} }
public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
{
switch (funcid) {
case GETSAMPLE_OBJ_INTERFACE.CALL_GET_TEMPDATAS:
{
mGetSampleService.GetTempFilterDatas((context,retdata) =>
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(retdata);
CurrObjSys.PushCallFunctionEx(from, srcid, ID, magic, funcid, Misc.Converter.StringToBytes(json));
}, null);
}break;
}
}
} }
} }
...@@ -15,6 +15,11 @@ namespace FLY.Thick.Base.Server ...@@ -15,6 +15,11 @@ namespace FLY.Thick.Base.Server
/// </summary> /// </summary>
public class BorderSearch : IBorderSearchService, INotifyPropertyChanged, Misc.ISaveToXml public class BorderSearch : IBorderSearchService, INotifyPropertyChanged, Misc.ISaveToXml
{ {
/// <summary>
/// 报警测试
/// </summary>
public static FLY.OBJComponents.Common.ERRNO BORDER_ERRNO_NOFILM = new FLY.OBJComponents.Common.ERRNO() { Code = 50, Descrption = "边界异常,没有被测物" };
#region 延时执行,Markno #region 延时执行,Markno
public const int MARKNO_SAVE = 1; public const int MARKNO_SAVE = 1;
#endregion #endregion
...@@ -124,6 +129,7 @@ namespace FLY.Thick.Base.Server ...@@ -124,6 +129,7 @@ namespace FLY.Thick.Base.Server
#endregion #endregion
OBJComponents.Server.WarningSystem warningSystem;
private string param_path = "bordersearch.xml"; private string param_path = "bordersearch.xml";
public BorderSearch() public BorderSearch()
{ {
...@@ -151,6 +157,11 @@ namespace FLY.Thick.Base.Server ...@@ -151,6 +157,11 @@ namespace FLY.Thick.Base.Server
}; };
Load(); Load();
} }
public void Init(OBJComponents.Server.WarningSystem warningSystem)
{
this.warningSystem = warningSystem;
}
void Default() void Default()
{ {
Enable = false; Enable = false;
...@@ -589,8 +600,10 @@ namespace FLY.Thick.Base.Server ...@@ -589,8 +600,10 @@ namespace FLY.Thick.Base.Server
int borderend_grid;//validend_grid; int borderend_grid;//validend_grid;
if (!FindFilm_Threshold(dat, validbegin_grid, validend_grid, TempAD, TempRange, out borderbegin_grid, out borderend_grid)) if (!FindFilm_Threshold(dat, validbegin_grid, validend_grid, TempAD, TempRange, out borderbegin_grid, out borderend_grid))
{
warningSystem.Add(BORDER_ERRNO_NOFILM.Code, BORDER_ERRNO_NOFILM.Descrption, OBJComponents.Common.ERR_STATE.ON);
return false; return false;
}
//N2 只是用来判断一下膜够不够宽而已,没用 //N2 只是用来判断一下膜够不够宽而已,没用
int N2_grid = (N2*3+SensorWidth) / posOfGrid; int N2_grid = (N2*3+SensorWidth) / posOfGrid;
...@@ -605,9 +618,8 @@ namespace FLY.Thick.Base.Server ...@@ -605,9 +618,8 @@ namespace FLY.Thick.Base.Server
FindFilm_Break(dat, sensor_grid, filter_grid, ref borderbegin_grid, ref borderend_grid); FindFilm_Break(dat, sensor_grid, filter_grid, ref borderbegin_grid, ref borderend_grid);
} }
int idx = 0; int idx = (direction == DIRECTION.FORWARD) ? 0 : 1;
if (direction == DIRECTION.BACKWARD)
idx = 1;
//转为 脉冲 //转为 脉冲
border[idx].Begin = (borderbegin_grid + gridBegin) * posOfGrid; border[idx].Begin = (borderbegin_grid + gridBegin) * posOfGrid;
border[idx].End = (borderend_grid +gridBegin) * posOfGrid; border[idx].End = (borderend_grid +gridBegin) * posOfGrid;
......
...@@ -38,6 +38,11 @@ namespace FLY.Thick.Base.Server ...@@ -38,6 +38,11 @@ namespace FLY.Thick.Base.Server
/// </summary> /// </summary>
public int FLYAD7_GridSmooth { get; set; } = 0; public int FLYAD7_GridSmooth { get; set; } = 0;
/// <summary>
/// 电脑计算速度,不通过AD盒获取
/// </summary>
public bool FLYAD7_IsCalSpeed { get; set; } = true;
#endregion #endregion
private string param_path = "sysparam.xml"; private string param_path = "sysparam.xml";
...@@ -58,7 +63,8 @@ namespace FLY.Thick.Base.Server ...@@ -58,7 +63,8 @@ namespace FLY.Thick.Base.Server
return; return;
if ((e.PropertyName == "FLYAD7EP")|| if ((e.PropertyName == "FLYAD7EP")||
(e.PropertyName == "FLYAD7_HasCRC")|| (e.PropertyName == "FLYAD7_HasCRC")||
(e.PropertyName == "FLYAD7_GridSmooth") (e.PropertyName == "FLYAD7_GridSmooth")||
(e.PropertyName == "FLYAD7_IsCalSpeed")
) )
{ {
Save(); Save();
...@@ -91,7 +97,7 @@ namespace FLY.Thick.Base.Server ...@@ -91,7 +97,7 @@ namespace FLY.Thick.Base.Server
"FLYAD7EP", "FLYAD7EP",
"FLYAD7_HasCRC", "FLYAD7_HasCRC",
"FLYAD7_GridSmooth", "FLYAD7_GridSmooth",
"DBPath" "FLYAD7_IsCalSpeed"
}; };
} }
} }
......
using System; using FLY.Thick.Base.IService;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace FLY.Thick.Base.Server namespace FLY.Thick.Base.Server
{ {
/// <summary>
/// 样品修正 滤波
/// </summary>
public class TempFilter public class TempFilter
{ {
DateTime sampleTime; DateTime sampleTime;
int sampleFailure; int sampleFailure;
int swfilterCnt; int swfilterCnt;
/// <summary>
/// 滤波器
/// </summary>
class SWFilter class SWFilter
{ {
/// <summary>
/// 缓存区
/// </summary>
int[] buffer; int[] buffer;
/// <summary>
/// 缓存区大小
/// </summary>
int bufferSize; int bufferSize;
/// <summary>
/// 队列尾
/// </summary>
int lastData; int lastData;
/// <summary>
/// 默认值
/// </summary>
int initvalue; int initvalue;
public SWFilter(int buffersize) public SWFilter(int buffersize)
...@@ -44,7 +63,7 @@ namespace FLY.Thick.Base.Server ...@@ -44,7 +63,7 @@ namespace FLY.Thick.Base.Server
window--; window--;
} }
if (cnt == 0) return initvalue; if (cnt == 0) return initvalue;
return (int)(sum / cnt + 0.5); return (int)Math.Round(sum / cnt);
} }
public void Clear(int initvalue) public void Clear(int initvalue)
...@@ -65,7 +84,7 @@ namespace FLY.Thick.Base.Server ...@@ -65,7 +84,7 @@ namespace FLY.Thick.Base.Server
public void SetSize(int buffersize) public void SetSize(int buffersize)
{ {
if (buffersize != this.bufferSize) if (this.bufferSize != buffersize)
{ {
this.bufferSize = buffersize; this.bufferSize = buffersize;
...@@ -78,8 +97,14 @@ namespace FLY.Thick.Base.Server ...@@ -78,8 +97,14 @@ namespace FLY.Thick.Base.Server
SWFilter swfilter; SWFilter swfilter;
int tempBIndex; int tempBIndex;
int[] tempBuf = new int[3]; int[] tempBuf = new int[3];
/// <summary>
/// 前一个AD值
/// </summary>
int preValue; int preValue;
/// <summary>
///
/// </summary>
public TempFilter() public TempFilter()
{ {
sampleFailure = 0; sampleFailure = 0;
...@@ -90,20 +115,40 @@ namespace FLY.Thick.Base.Server ...@@ -90,20 +115,40 @@ namespace FLY.Thick.Base.Server
preValue = -1; preValue = -1;
} }
/// <summary>
/// 复位失败次数
/// </summary>
public void ResetSampleFailure() public void ResetSampleFailure()
{ {
sampleFailure = 0; sampleFailure = 0;
} }
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool IsSampleFailure() public bool IsSampleFailure()
{ {
if (sampleFailure < 0) return true; if (sampleFailure < 0) return true;
return false; return false;
} }
/// <summary>
/// 输入原始AD值,输出滤波后AD值
/// </summary>
/// <param name="ad"></param>
/// <returns></returns>
public int CalSampleAD(int ad) public int CalSampleAD(int ad)
{ {
int originAD; return CalSampleAD(ad, out int originAD);
return CalSampleAD(ad, out originAD);
} }
/// <summary>
/// 输入原始AD值,输出滤波后AD值
/// </summary>
/// <param name="ad"></param>
/// <param name="originAD"></param>
/// <returns></returns>
public int CalSampleAD(int ad, out int originAD) public int CalSampleAD(int ad, out int originAD)
{ {
originAD = 0; originAD = 0;
...@@ -137,7 +182,7 @@ namespace FLY.Thick.Base.Server ...@@ -137,7 +182,7 @@ namespace FLY.Thick.Base.Server
if (delta > 0.01 * Math.Abs(preValue))//跳到超过 1% ,有问题 if (delta > 0.01 * Math.Abs(preValue))//跳到超过 1% ,有问题
{ {
if (tempBIndex < 1) // Sudden Changed! Need 3 times to confirm. if (tempBIndex < 1) // 突变!! 需要2次确认 因为可能只是很大的噪声
{ {
tempBIndex++; tempBIndex++;
tempBuf[tempBIndex] = ad; tempBuf[tempBIndex] = ad;
...@@ -173,10 +218,93 @@ namespace FLY.Thick.Base.Server ...@@ -173,10 +218,93 @@ namespace FLY.Thick.Base.Server
preValue = swfilter.CalValue(swfilterCnt); preValue = swfilter.CalValue(swfilterCnt);
return preValue; return preValue;
} }
/// <summary>
/// 移动滤波窗口大小
/// </summary>
/// <param name="window"></param>
public void SetWindow(int window) public void SetWindow(int window)
{ {
if (window < 50) if (window < 50)
swfilterCnt = window; swfilterCnt = window;
} }
} }
/// <summary>
/// 样品修正 滤波, 返回N分钟内数据的均值。
/// 如果波动较大,提示异常
/// </summary>
public class TempFilter2
{
List<TempFilterData> Datas = new List<TempFilterData>();
TimeSpan keepTime = TimeSpan.FromMinutes(6);
/// <summary>
///
/// </summary>
public TempFilter2()
{
}
/// <summary>
///
/// </summary>
/// <param name="ad">原始AD</param>
/// <param name="filterTime">滤波时间</param>
/// <returns>滤波后Ad</returns>
public int CalSampleAD(int ad, TimeSpan filterTime)
{
if (filterTime.TotalSeconds <= 0)
{
filterTime = TimeSpan.Zero;
}
keepTime = TimeSpan.FromMinutes(Math.Max(6, filterTime.TotalMinutes * 3));
var now = DateTime.Now;
Datas.RemoveAll(d => d.Time < now - keepTime);
Datas.Add(new TempFilterData()
{
Ad = ad,
FilterAd = ad,
Time = now
});
double sum = 0;
int cnt = 0;
for (int i = 0; i < Datas.Count(); i++)
{
var d = Datas[Datas.Count()-1-i];
if (d.Time >= (now - filterTime) && d.IsReset == false)
{
sum += d.Ad;
cnt++;
}
else {
break;
}
}
if (cnt > 0)
{
Datas.Last().FilterAd = (int)Math.Round(sum / cnt);
}
return Datas.Last().FilterAd;
}
/// <summary>
///
/// </summary>
public void Reset()
{
var now = DateTime.Now;
Datas.RemoveAll(d => d.Time < now - keepTime);
Datas.Add(new TempFilterData() { IsReset = true, Time = DateTime.Now });
}
public List<TempFilterData> GetDatas()
{
return Datas;
}
}
} }
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