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

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

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