Commit 441a1a7e authored by 潘栩锋's avatar 潘栩锋 🚴

把V8的服务器多国语言部分,复制过来

parent 221b90d1
......@@ -115,8 +115,12 @@ namespace FLY.OBJComponents.Common
/// </summary>
public struct ERRNO
{
public UInt16 Code;
public string Descrption;
public int Code;
public string Description;
public override string ToString()
{
return $"[{Code}] {Description}";
}
}
public class PlcErrNos
......@@ -126,6 +130,6 @@ namespace FLY.OBJComponents.Common
/// <summary>
/// PLC连接断开
/// </summary>
public ERRNO ERRNO_PLC_DISCONNECTED = new ERRNO() { Code = 65535, Descrption = "PLC连接断开" };
public ERRNO ERRNO_PLC_DISCONNECTED = new ERRNO() { Code = 65535, Description = "PLC连接断开" };
}
}
......@@ -59,7 +59,7 @@ namespace FLY.OBJComponents.Server
//初始化 PLC连接断开的描述列表
int plcCnt = PLCos.PLCs.Count();
int errCode = plcErrCodeBegin;
string descrption = PlcErrNos.Instance.ERRNO_PLC_DISCONNECTED.Descrption;
string descrption = PlcErrNos.Instance.ERRNO_PLC_DISCONNECTED.Description;
for (int i = 0; i < plcCnt; i++)
{
plcDisconnectedErrMsgs.Add(new PlcDisconnectedErrMsg()
......
......@@ -86,7 +86,7 @@ namespace FLY.OBJComponents.Server
public void Add(ERRNO errno,bool canReset = true)
{
Add(errno.Code, errno.Descrption,canReset:canReset);
Add(errno.Code, errno.Description,canReset:canReset);
}
public void Remove(ERRNO errno)
{
......
using FLY.OBJComponents.IService;
using MultiLayout.UiModule;
using MultiLayout.UiModule;
using Misc;
using System;
using System.Collections.Generic;
......@@ -11,6 +11,7 @@ using System.Threading.Tasks;
using FLY.Thick.Base.UI;
using Unity;
using FLY.Thick.Base.Common;
using System.Windows;
namespace FLY.Thick.Base.UI.OnInit
{
......@@ -31,13 +32,13 @@ namespace FLY.Thick.Base.UI.OnInit
IUnityContainer container;
bool enableScanErrBigTip;
int warningTipId=-1;
int warningTipId = -1;
public int Level { get; }
public OnInitError(
IUnityContainer container,
ParamDictionary paramDictionary,
FLY.OBJComponents.IService.IWarningSystem2Service warningService,
int lv = 1)
ParamDictionary paramDictionary,
IWarningSystem2Service warningService,
int lv = 1)
{
Level = lv;
this.container = container;
......@@ -55,18 +56,19 @@ namespace FLY.Thick.Base.UI.OnInit
}
private void WarningService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(warningService.ReasonList)) {
if (e.PropertyName == nameof(warningService.ReasonList))
{
if (!enableScanErrBigTip)
return;
FObjBase.PollModule.Current.Poll_JustOnce(
new FObjBase.PollModule.PollHandler(delegate ()
{
List<int> errCodes = new List<int> { ERRNOs.Instance.SCAN_ERRNO_OVERCTRL.Code, ERRNOs.Instance.SCAN_ERRNO_OVERTOL.Code };
List<int> errCodes = new List<int> { ERRNOs.Instance.ERRNO_OVERCTRL.Code, ERRNOs.Instance.ERRNO_OVERTOL.Code };
var record = warningService.ReasonList;
if (record == null)
......@@ -94,22 +96,19 @@ namespace FLY.Thick.Base.UI.OnInit
}
return;
}
int errcode = rs.First().ErrCode;
string msg = rs.First().Description;
string description = rs.First().Description;
string path = paramDictionary.GetValue<string>(ParamDistItemKeys.WarningTipPath);
string msg = description;
//报警!!!!!!!!
//记录打开的报警提示框Id,用于以后关闭
warningTipId = FLY.ControlLibrary.Window_WarningTip.Show(
$"编码={errcode}",
msg,
TimeSpan.MaxValue,
warningTipId = FLY.ControlLibrary.Window_WarningTip.Show(null, msg, TimeSpan.MaxValue,
path,
warningService.Reset
);
}), this, MARKNO_WARNING_RING);
}
}
......
......@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace FLY.Thick.Base.Common
{
......@@ -13,28 +14,84 @@ namespace FLY.Thick.Base.Common
{
public static ERRNOs Instance { get; } = new ERRNOs();
public ERRNO BASE_ERRNO_ONBOOT = new ERRNO() { Code = 250, Descrption = "系统启动" };
public ERRNO BASE_ERRNO_RINGTEST = new ERRNO() { Code = 1, Descrption = "报警测试" };
public ERRNO BASE_ERRNO_AD_MIN = new ERRNO() { Code = 2, Descrption = "AD值太小" };
public ERRNO BASE_ERRNO_AD_MAX = new ERRNO() { Code = 3, Descrption = "AD值太大" };
public ERRNO BASE_ERRNO_EMERGENCY = new ERRNO() { Code = 4, Descrption = "急停" };
public ERRNO BASE_ERRNO_LIMIT = new ERRNO() { Code = 5, Descrption = "限位" };
public ERRNO BASE_ERRNO_FLYAD7DISCONNECTED = new ERRNO() { Code = 6, Descrption = "AD盒连接断开" };
public ERRNO BASE_ERRNO_LICENSE_TIP = new ERRNO() { Code = 7, Descrption = "授权将要过期" };
public ERRNO BASE_ERRNO_LICENSE = new ERRNO() { Code = 8, Descrption = "授权限制" };
public ERRNO BASE_ERRNO_FILE_ERR_RESTORE = new ERRNO() { Code = 9, Descrption = "数据文件异常,恢复不成功" };
public ERRNO BASE_ERRNO_FILE_RESTORE = new ERRNO() { Code = 10, Descrption = "数据文件异常,恢复成功" };
public ERRNO SCAN_ERRNO_OVERCTRL = new ERRNO() { Code = 11, Descrption = "扫描超控制报警" };
public ERRNO SCAN_ERRNO_OVERTOL = new ERRNO() { Code = 12, Descrption = "扫描超规格报警" };
public ERRNO BASE_ERRNO_DB = new ERRNO() { Code = 13, Descrption = "数据库异常,重建" };
public ERRNO BASE_ERRNO_TIMEGRIDADV = new ERRNO() { Code = 14, Descrption = "AD卡版本太低,不能启动 [高级AD数据]" };
public ERRNO BASE_ERRNO_DB_BACKUP = new ERRNO() { Code = 15, Descrption = "已经连续开机1个月,数据库需要备份归档,请尽快重启服务器" };
public ERRNO SCAN_ERRNO_FATAL = new ERRNO() { Code = 20, Descrption = "扫描异常,致命错误 必须停止扫描" };
public ERRNO SYNC_ERRNO_FATAL = new ERRNO() { Code = 21, Descrption = "同步异常,致命错误 必须停止扫描" };
public ERRNO MEASURE_SYNC_ERRNO_FATAL = new ERRNO() { Code = 22, Descrption = "测量同步参数异常,致命错误 必须停止" };
public ERRNO SAMPLE_ERRNO_Failure = new ERRNO() { Code = 60, Descrption = "样品取样出错" };
public ERRNOs()
{
string resourceName = $"dict.StringResource.ERRNO";
var rd_errnos = (ResourceDictionary)Application.Current.FindResource(resourceName);//异常直接让它出错
Type t = this.GetType();
var fields = t.GetFields();
foreach (var field in fields)
{
if (field.Name.StartsWith("ERRNO_"))
{
var errno = (ERRNO)field.GetValue(this);
errno.Description = ToDescription(rd_errnos, field.Name);
field.SetValue(this, errno);
}
}
}
string ToDescription(ResourceDictionary rd_errnos, string errNoKey)
{
string resourceName = $"str.ERRNO.{errNoKey}";
return (string)rd_errnos[resourceName];//异常直接让它出错
}
public virtual List<ERRNO> GetAll()
{
List<ERRNO> list = new List<ERRNO>();
Type t = this.GetType();
var fields = t.GetFields();
foreach (var field in fields)
{
if (field.Name.StartsWith("ERRNO_"))
{
var errno = (ERRNO)field.GetValue(this);
list.Add(errno);
}
}
list.Sort((e0, e1) =>
{
return e0.Code.CompareTo(e1.Code);
});
return list;
}
public ERRNO ERRNO_AUTH_EXP = new ERRNO() { Code = 0, Description = "AUTH_EXP" };//"授权过期" };
public ERRNO ERRNO_FLYAD7_DC = new ERRNO() { Code = 1, Description = "FLYAD7_DC" };//"AD盒连接断开" };
public ERRNO ERRNO_AD_MIN = new ERRNO() { Code = 2, Description = "AD_MIN" };//"AD值太小" };
public ERRNO ERRNO_AD_MAX = new ERRNO() { Code = 3, Description = "AD_MAX" };//"AD值太大" };
public ERRNO ERRNO_SCRAM = new ERRNO() { Code = 4, Description = "SCRAM" };//"急停" };
public ERRNO ERRNO_LIMIT = new ERRNO() { Code = 5, Description = "LIMIT" };//"限位" };
public ERRNO ERRNO_OVERTOL = new ERRNO() { Code = 6, Description = "OVERTOL" };//"扫描超规格报警" };
public ERRNO ERRNO_SCAN_FATAL = new ERRNO() { Code = 7, Description = "SCAN_FATAL" };//"扫描动作异常" };
public ERRNO ERRNO_SAMPLE_FATAL = new ERRNO() { Code = 8, Description = "SAMPLE_FATAL" };//"采样异常" };
public ERRNO ERRNO_ALARM_TEST = new ERRNO() { Code = 9, Description = "ALARM_TEST" };//"报警测试" };
public ERRNO ERRNO_WILL_EXP = new ERRNO() { Code = 10, Description = "WILL_EXP" };//"授权将要过期" };
public ERRNO ERRNO_OVERCTRL = new ERRNO() { Code = 11, Description = "OVERCTRL" };//"扫描超控制报警" };
public ERRNO ERRNO_DB_BACKUP = new ERRNO() { Code = 12, Description = "DB_BACKUP" };//"已经连续开机1个月,数据库需要备份归档,请尽快重启服务器" };
public ERRNO ERRNO_SAMPLE_ParamErr = new ERRNO() { Code = 20, Description = "SAMPLE_ParamErr" };//"采样出错:参数异常" };
public ERRNO ERRNO_SAMPLE_ADZero = new ERRNO() { Code = 21, Description = "SAMPLE_ADZero" };//"采样出错:AD值为0" };
public ERRNO ERRNO_SAMPLE_NoData = new ERRNO() { Code = 22, Description = "SAMPLE_NoData" };//"采样出错:没有采集数据" };
public ERRNO ERRNO_SAMPLE_FilterErr = new ERRNO() { Code = 23, Description = "SAMPLE_FilterErr" };//"采样出错:滤波数据与原始数据差异大" };
public ERRNO ERRNO_SAMPLE_PercentErr = new ERRNO() { Code = 24, Description = "SAMPLE_PercentErr" };//"采样出错:样品AD与上次差异大" };
public ERRNO ERRNO_SAMPLE_CrossErr = new ERRNO() { Code = 25, Description = "SAMPLE_CrossErr" };//"采样出错:样品比值与上次差异大" };
}
......
using FLY.Thick.Base.IService;
using FlyADBase;
using FObjBase;
using System;
using System.Collections.Generic;
......@@ -20,10 +21,10 @@ namespace FLY.Thick.Base.Common
/// 6.在Gage中 调用 FlyADIODefine.SetInstance(new FlyADIODefine());
/// 7.在Gage中 注册 AD盒事件, AD盒版本修改时,FlyADIODefine.SerVersion(version);
/// </summary>
public class FlyADIODefine: IFlyAdIoDefineService
public class FlyADIODefine : IFlyAdIoDefineService
{
protected static FlyADIODefine instance;
public static void SetInstance(FlyADIODefine flyADIODefine)
public static void SetInstance(FlyADIODefine flyADIODefine)
{
instance = flyADIODefine;
}
......@@ -31,70 +32,73 @@ namespace FLY.Thick.Base.Common
/// 子类 需要 重新 把子类对象 赋值给 Instance, 确保整个环境只用一个版本的 单例
/// </summary>
public static FlyADIODefine Instance => instance;
#region 输入口
/// <summary>
/// 扫描按钮信号
/// </summary>
public int InNo_Scan { get; protected set; } = 1 - 1;
/// <summary>
/// 归零信号
/// </summary>
[Description("归零信号")]
public int InNo_Org { get; protected set; } = 2 - 1;
/// <summary>
/// 正向限位
/// </summary>
[Description("正向限位")]
public int InNo_Limit_Forw { get; protected set; } = 3 - 1;
/// <summary>
/// 反向限位
/// </summary>
[Description("反向限位")]
public int InNo_Limit_Backw { get; protected set; } = 4 - 1;
/// <summary>
/// 数据有效
/// </summary>
[Description("数据有效")]
public int InNo_DataValid { get; protected set; } = 6 - 1;
/// <summary>
/// 急停 and 手动正转
/// </summary>
[Description("急停 & 手动正转")]
public int InNo_Manual_Forw { get; protected set; } = 7 - 1;
/// <summary>
/// 急停 and 手动反转
/// </summary>
[Description("急停 & 手动反转")]
public int InNo_Manual_Backw { get; protected set; } = 8 - 1;
/// <summary>
/// 同步输入信号
/// </summary>
[Description("同步输入信号")]
public int InNo_Sync { get; protected set; } = 9 - 1;
/// <summary>
/// 辊速信号
/// </summary>
[Description("辊速信号")]
public int InNo_Roll { get; protected set; } = 11 - 1;
/// <summary>
/// 控制主轴脉冲启动计数输入, o3 接 i11;
/// i11 为 0 计数停止
/// </summary>
[Description("主轴脉冲启动计数")]
public int InNo_Pos2OnOff { get; protected set; } = 11 - 1;
/// <summary>
/// 纵向光纤信号
/// </summary>
[Description("纵向光纤信号")]
public int InNo_VSign { get; protected set; } = 12 - 1;
#endregion
#region 输出口
/// <summary>
/// 扫描动作中
/// </summary>
[Description("扫描动作中")]
public int OutNo_Scan { get; protected set; } = 1 - 1;
/// <summary>
/// 变频器反转 VF0 是松下的变频器牌子
/// </summary>
......@@ -132,37 +136,36 @@ namespace FLY.Thick.Base.Common
#endregion
private int version = 2;
/// <summary>
/// 根据AD盒的版本,设置
/// </summary>
/// <param name="version"></param>
public virtual void SerVersion(int version)
IFlyAD flyAD;
public virtual void SetFlyAD(IFlyAD _flyAD)
{
this.version = version;
if (this.version == 3)
this.flyAD = _flyAD;
Misc.BindingOperations.SetBinding(flyAD, nameof(flyAD.HardwareVersion), () =>
{
InNo_Org = 13 - 1;
InNo_Limit_Forw = 14 - 1;
InNo_Limit_Backw = 16 - 1;
if (this.flyAD.HardwareVersion < 3)
{
InNo_Org = 2 - 1;
InNo_Limit_Forw = 3 - 1;
InNo_Limit_Backw = 4 - 1;
InNo_Roll = 15 - 1;
}
else
{
InNo_Org = 2 - 1;
InNo_Limit_Forw = 3 - 1;
InNo_Limit_Backw = 4 - 1;
InNo_Roll = 11 - 1;
}
else
{
InNo_Org = 13 - 1;
InNo_Limit_Forw = 14 - 1;
InNo_Limit_Backw = 16 - 1;
InNo_Roll = 11 - 1;
}
InNo_Roll = 15 - 1;
}
});
}
/// <summary>
/// 获取输入口 属性名
/// </summary>
/// <returns></returns>
protected virtual List<string> GetInputPropertyNames()
protected virtual List<string> GetInputPropertyNames()
{
List<string> reponse = new List<string>();
Type t = this.GetType();
......@@ -201,37 +204,45 @@ namespace FLY.Thick.Base.Common
public void GetIODefine(AsyncCBHandler asyncDelegate, object asyncContext)
{
//获取全部带 Description 的属性,且名字 InNo_XXX 或 OutNo_XXX
IODefineCollection reponse = new IODefineCollection();
IODefineCollection response = new IODefineCollection();
List<IODefine> list = new List<IODefine>();
reponse.List = list;
if (version == 3)
response.List = list;
if (flyAD.HardwareVersion < 3)
{
reponse.InCount = 16;
reponse.OutCount = 8;
response.InCount = 12;
response.OutCount = 4;
}
else {
reponse.InCount = 12;
reponse.OutCount = 4;
else
{
response.InCount = 16;
response.OutCount = 8;
}
var inputPropertyNames = GetInputPropertyNames();
var outputPropertyNames = GetOutputPropertyNames();
if (flyAD.MotorType != FlyADBase.MOTORTYPE.VF0)
{
//把 变频器 接口删除
outputPropertyNames.Remove(nameof(OutNo_VF0_Forw));
outputPropertyNames.Remove(nameof(OutNo_VF0_Backw));
outputPropertyNames.Remove(nameof(OutNo_VF0_Slow));
}
if (flyAD.MotorType == FlyADBase.MOTORTYPE.VF0)
{
//变频器 模式 没有扫描状态灯
outputPropertyNames.Remove(nameof(OutNo_Scan));
}
Type t = this.GetType();
foreach (var propertyName in inputPropertyNames)
{
var property = t.GetProperty(propertyName);
var attrs = property.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attrs.Count() == 0)
{
throw new Exception($"{propertyName} 没有写 [Description]");
}
var attr = attrs.First() as DescriptionAttribute;
string desp = attr.Description;
string desp = propertyName;
var index = (int)property.GetValue(this);
var iodefine = new IODefine()
......@@ -240,6 +251,7 @@ namespace FLY.Thick.Base.Common
Index = index,
Description = desp
};
list.Add(iodefine);
}
......@@ -247,14 +259,7 @@ namespace FLY.Thick.Base.Common
{
var property = t.GetProperty(propertyName);
var attrs = property.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attrs.Count() == 0)
{
throw new Exception($"{propertyName} 没有写 [Description]");
}
var attr = attrs.First() as DescriptionAttribute;
string desp = attr.Description;
string desp = propertyName;
var index = (int)property.GetValue(this);
var iodefine = new IODefine()
......@@ -266,7 +271,7 @@ namespace FLY.Thick.Base.Common
list.Add(iodefine);
}
asyncDelegate?.Invoke(asyncContext, reponse);
asyncDelegate?.Invoke(asyncContext, response);
}
}
}
......@@ -42,6 +42,8 @@
</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......@@ -162,6 +164,16 @@
<Folder Include="OBJ_INTERFACE\" />
<Folder Include="Server.OBJProxy\" />
</ItemGroup>
<ItemGroup>
<Page Include="Themes\StringResources\en\StringResource.ERRNO.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\StringResources\StringResource.ERRNO.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
......@@ -16,6 +16,8 @@ using Newtonsoft.Json;
using static Misc.ReverserInfo;
using FLY.Thick.Base.Common;
using AutoMapper;
using System.Reflection;
using FLY.OBJComponents.Common;
namespace FLY.Thick.Base.Server
{
......@@ -59,7 +61,7 @@ namespace FLY.Thick.Base.Server
/// 异常比例 单位不是%
/// </summary>
public double ErrPercent { get; set; } = 0.02;
/// <summary>
/// 异常值
/// </summary>
......@@ -84,12 +86,12 @@ namespace FLY.Thick.Base.Server
/// <summary>
/// 特征 相识度 0 正, 1 反
/// </summary>
public SampleFeature[] Features { get; set; }
public SampleFeature[] Features { get; set; }
#endregion
TempFilter2[] tempFilters;
DIRECTION[] directions;
/// <summary>
......@@ -119,8 +121,8 @@ namespace FLY.Thick.Base.Server
public event SampleChangedEventHandler SampleChangedEvent;
private string param_path;
public GSample():this("gsample.json")
public GSample() : this("gsample.json")
{
}
......@@ -136,7 +138,7 @@ namespace FLY.Thick.Base.Server
states = new SampleState[Samples.Count()];
for (int i = 0; i < Samples.Count(); i++)
tempFilters[i] = new TempFilter2();
Enable = true;
SampleRange = 100;//样品范围
Velocity = 200;//取样速度
......@@ -179,7 +181,7 @@ namespace FLY.Thick.Base.Server
public virtual void Init(
IFlyADClientAdv flyad,
IGageInfoService gageInfo,
OBJComponents.Server.WarningSystem2 warningSystem)
OBJComponents.Server.WarningSystem2 warningSystem)
{
this.flyad = flyad;
this.mGageInfo = gageInfo;
......@@ -189,7 +191,7 @@ namespace FLY.Thick.Base.Server
}
public bool Load()
public bool Load()
{
return GSampleJsonDb.Load(this, param_path);
}
......@@ -197,7 +199,7 @@ namespace FLY.Thick.Base.Server
/// <summary>
/// 保存
/// </summary>
public bool Save()
public bool Save()
{
return GSampleJsonDb.Save(this, param_path);
}
......@@ -211,12 +213,13 @@ namespace FLY.Thick.Base.Server
public virtual void Reset(int scanbegin, int scanend)
{
last_sampleData = null;
for (int i = 0; i < Samples.Count(); i++) {
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
int pos = sample.Position;
directions[i] = (Math.Abs(pos - scanbegin) < Math.Abs(pos - scanend)) ? Misc.DIRECTION.BACKWARD : Misc.DIRECTION.FORWARD;
sample.AD = -1;
states[i] = SampleState.ReadyToCapture;
tempFilters[i].Reset();
......@@ -237,7 +240,7 @@ namespace FLY.Thick.Base.Server
/// </summary>
/// <param name="direction"></param>
/// <returns>当没有样品,也没有特征,返回null</returns>
public Range GetSampleRange(Misc.DIRECTION direction)
public Range GetSampleRange(Misc.DIRECTION direction)
{
int b, e;
if (GetSampleRange(direction, out b, out e))
......@@ -256,12 +259,12 @@ namespace FLY.Thick.Base.Server
/// <param name="start"></param>
/// <param name="end"></param>
/// <returns>当没有样品,也没有特征,返回False</returns>
public virtual bool GetSampleRange(Misc.DIRECTION direction, out int start,out int end)
public virtual bool GetSampleRange(Misc.DIRECTION direction, out int start, out int end)
{
start = 0;
end = 0;
bool valid = false;
int b=0, e=0;
int b = 0, e = 0;
int r_idx = (direction == Misc.DIRECTION.FORWARD) ? 0 : 1;
if (Features[r_idx].Enable)
......@@ -271,7 +274,7 @@ namespace FLY.Thick.Base.Server
valid = true;
}
for(int i=0;i< Samples.Count(); i++)
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
if ((sample.Enable) && (directions[i] == direction))
......@@ -318,29 +321,29 @@ namespace FLY.Thick.Base.Server
/// 检测参数合法性
/// </summary>
/// <returns></returns>
protected bool CheckParamIsValid()
protected bool CheckParamIsValid()
{
//样品位置 要在 范围
foreach(SampleCell sample in Samples)
foreach (SampleCell sample in Samples)
{
if (sample.Enable)
{
if(((sample.Position - SampleRange)<0) || ((sample.Position+SampleRange)>= flyad.PosLen))
{
if (((sample.Position - SampleRange) < 0) || ((sample.Position + SampleRange) >= flyad.PosLen))
return false;
}
}
foreach(SampleFeature feature in Features)
foreach (SampleFeature feature in Features)
{
if (feature.Enable)
{
if(((feature.StartPos - SearchRange)<0) || ((feature.EndPos+SearchRange)>= flyad.PosLen))
{
if (((feature.StartPos - SearchRange) < 0) || ((feature.EndPos + SearchRange) >= flyad.PosLen))
return false;
}
}
return true;
}
/// <summary>
/// 样品取样,推送给thickm, 参数一定合法,不用检测
/// </summary>
......@@ -348,11 +351,11 @@ namespace FLY.Thick.Base.Server
public void Do(Misc.DIRECTION direction)
{
int[] dat;
flyad.GetGrid(direction,0, flyad.PosLen/flyad.PosOfGrid, out dat);
flyad.GetGrid(direction, 0, flyad.PosLen / flyad.PosOfGrid, out dat);
Do(direction, 0, dat);
}
bool CalGridOffset(SampleFeature psr, Misc.DIRECTION direction,int grid_start, int[] buf, out int grid_offset)
bool CalGridOffset(SampleFeature psr, Misc.DIRECTION direction, int grid_start, int[] buf, out int grid_offset)
{
grid_offset = 0;
//检测机架数据,当为空时,不能作相识性计算
......@@ -416,7 +419,7 @@ namespace FLY.Thick.Base.Server
/// 设置这个方向 全部样品为失败
/// </summary>
/// <param name="direction"></param>
void SetFailure(Misc.DIRECTION direction)
void SetFailure(Misc.DIRECTION direction)
{
for (int i = 0; i < Samples.Count(); i++)
{
......@@ -459,7 +462,7 @@ namespace FLY.Thick.Base.Server
}
return true;
}
enum GetSampleAdResult
enum GetSampleAdResult
{
OK,
/// <summary>
......@@ -475,7 +478,7 @@ namespace FLY.Thick.Base.Server
/// </summary>
FilterErr
}
GetSampleAdResult GetSampleAd(SampleCell sample, TempFilter2 tempre, int grid_start, int[] buf, int grid_offset, out int ad)
GetSampleAdResult GetSampleAd(SampleCell sample, TempFilter2 tempre, int grid_start, int[] buf, int grid_offset, out int ad)
{
//获取grid 数据
int posOfGrid = flyad.PosOfGrid;
......@@ -527,7 +530,7 @@ namespace FLY.Thick.Base.Server
return GetSampleAdResult.OK;
}
GetSampleAdResult SetSampleAds(Misc.DIRECTION direction, int grid_start, int[] buf, int grid_offset)
GetSampleAdResult SetSampleAds(Misc.DIRECTION direction, int grid_start, int[] buf, int grid_offset)
{
for (int i = 0; i < Samples.Count(); i++)
{
......@@ -537,7 +540,7 @@ namespace FLY.Thick.Base.Server
{
//获取滤波后的AD值
var ret = GetSampleAd(sample, tempre, grid_start, buf, grid_offset, out int ad);
if(ret == GetSampleAdResult.OK)
if (ret == GetSampleAdResult.OK)
{
sample.AD = ad;
states[i] = SampleState.Ok;
......@@ -551,6 +554,13 @@ namespace FLY.Thick.Base.Server
}
return GetSampleAdResult.OK;
}
void UpdateSampleErrNo(ERRNO sampleErrNo)
{
this.warningSystem.Update(
sampleErrNo.Code,
sampleErrNo.Description
);
}
/// <summary>
/// 样品取样,推送给thickm, 参数一定合法,不用检测
/// </summary>
......@@ -562,60 +572,28 @@ namespace FLY.Thick.Base.Server
if (CheckParamIsValid() == false)
{
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:参数异常");
UpdateSampleErrNo(ERRNOs.Instance.ERRNO_SAMPLE_ParamErr);
return;
}
int grid_offset = 0;//经过相识性计算后的偏移量
//数据在 gsample -> gagedata[0]
SampleFeature psr = Features[(direction == Misc.DIRECTION.FORWARD) ? 0 : 1];
//这个方向的特征查找使能了,位置修正!!!!!!
if (psr.Enable)
{
//通过特征 计算样品偏移,
//当没有机架信息,会返回 true
//成功 计算出偏移 返回 true
//相关性太低,返回 false
if (!CalGridOffset(psr, direction, grid_start, buf, out grid_offset))
{
//有问题,全部复位
SetFailure(direction);
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:特征查找失败");
goto _end;
}
}
//获取这个方向全部样品AD
var ret = SetSampleAds(direction, grid_start, buf, grid_offset);
switch (ret)
{
case GetSampleAdResult.Zero:
{
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:AD值为0");
UpdateSampleErrNo(ERRNOs.Instance.ERRNO_SAMPLE_ADZero);
}
break;
case GetSampleAdResult.Invalid:
{
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:没有采集数据");
UpdateSampleErrNo(ERRNOs.Instance.ERRNO_SAMPLE_NoData);
}
break;
case GetSampleAdResult.FilterErr:
{
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:滤波数据与原始数据差异{ErrPercent:P0}");
UpdateSampleErrNo(ERRNOs.Instance.ERRNO_SAMPLE_FilterErr);
}
break;
}
......@@ -630,6 +608,8 @@ namespace FLY.Thick.Base.Server
//全部都采集完成
if (!IsErr())//没有异常
{
Remove_ERRNO_SAMPLE();
//备份
last_sampleData = new SampleData();
last_sampleData.Time = DateTime.Now;
......@@ -640,10 +620,18 @@ namespace FLY.Thick.Base.Server
}
}
}
_end:
_end:
SampleChangedEvent?.Invoke(this);
}
void Remove_ERRNO_SAMPLE()
{
this.warningSystem.Remove(ERRNOs.Instance.ERRNO_SAMPLE_ParamErr);
this.warningSystem.Remove(ERRNOs.Instance.ERRNO_SAMPLE_ADZero);
this.warningSystem.Remove(ERRNOs.Instance.ERRNO_SAMPLE_NoData);
this.warningSystem.Remove(ERRNOs.Instance.ERRNO_SAMPLE_FilterErr);
this.warningSystem.Remove(ERRNOs.Instance.ERRNO_SAMPLE_PercentErr);
this.warningSystem.Remove(ERRNOs.Instance.ERRNO_SAMPLE_CrossErr);
}
bool IsErr()
{
if (last_sampleData == null)
......@@ -652,9 +640,7 @@ namespace FLY.Thick.Base.Server
if (IsPercentErr())
{
//历史比较有问题
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:样品AD与上次大于{ErrPercent:P0}变化");
UpdateSampleErrNo(ERRNOs.Instance.ERRNO_SAMPLE_PercentErr);
//设置全部都是异常,重新测量
SetFailure();
......@@ -665,9 +651,7 @@ namespace FLY.Thick.Base.Server
if (IsCrossErr())
{
//交叉比较有问题
this.warningSystem.Update(
ERRNOs.Instance.SAMPLE_ERRNO_Failure.Code,
$"{ERRNOs.Instance.SAMPLE_ERRNO_Failure.Descrption}:样品比值与上次大于{CrossErrPercent:P0}变化");
UpdateSampleErrNo(ERRNOs.Instance.ERRNO_SAMPLE_CrossErr);
//设置全部都是异常,重新测量
SetFailure();
......@@ -691,7 +675,7 @@ namespace FLY.Thick.Base.Server
/// 刚才报警了,采样失败
/// </summary>
/// <returns></returns>
public bool IsFailure()
public bool IsFailure()
{
if (Enable)
{
......@@ -802,10 +786,11 @@ namespace FLY.Thick.Base.Server
/// </summary>
/// <param name="asyncCB"></param>
/// <param name="asyncContext"></param>
public void GetTempFilterDatas(AsyncCBHandler asyncDelegate, object asyncContext)
public void GetTempFilterDatas(AsyncCBHandler asyncDelegate, object asyncContext)
{
List<List<TempFilterData>> ret = new List<List<TempFilterData>>();
for (int i = 0; i < Samples.Count(); i++) {
for (int i = 0; i < Samples.Count(); i++)
{
SampleCell sample = Samples[i];
if (sample.Enable)
ret.Add(tempFilters[i].GetDatas());
......@@ -830,7 +815,7 @@ namespace FLY.Thick.Base.Server
public delegate void SampleChangedEventHandler(GSample gsample);
public class GSampleJsonDb
public class GSampleJsonDb
{
static Mapper Mapper { get; } = new AutoMapper.Mapper(new MapperConfiguration(c =>
{
......@@ -852,7 +837,8 @@ namespace FLY.Thick.Base.Server
opt.MapFrom(s => Map_SampleFeatureParam2SampleFeature(s.Features));
});
}));
static SampleCell[] Map_SampleCellParam2SampleCell(SampleCellParam[] sampleCellParams) {
static SampleCell[] Map_SampleCellParam2SampleCell(SampleCellParam[] sampleCellParams)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(sampleCellParams);
return Newtonsoft.Json.JsonConvert.DeserializeObject<SampleCell[]>(json);
}
......@@ -909,7 +895,7 @@ namespace FLY.Thick.Base.Server
}
public bool Enable { get; set; } = true;
public int Window { get; set; }
public int Window { get; set; }
public int SampleRange { get; set; } = 100;
public bool IsCheckByPercent { get; set; } = true;
public double ErrPercent { get; set; } = 2;
......
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