Commit 013060ee authored by 潘栩锋's avatar 潘栩锋 🚴

修复 中央收卷 X117 地址出错,8进制!!!!!

parent a9f0cc28
...@@ -73,56 +73,117 @@ namespace FLY.Winder.Server ...@@ -73,56 +73,117 @@ namespace FLY.Winder.Server
#region 报警 #region 报警
class ErrorAction class ErrorAction
{ {
public List<string> error_property; public List<ErrorInfo> error_property;
public object state; public object state;
public delegate void ErrorHandler(ref string msg, object state); public delegate void ErrorHandler(ref string msg, object state);
public ErrorHandler action; public ErrorHandler action;
} }
class ErrorInfo
{
public string property;
public byte code;
public string msg;
public bool offIsError;
}
Dictionary<INotifyPropertyChanged, ErrorAction> obj_error = new Dictionary<INotifyPropertyChanged, ErrorAction>(); Dictionary<INotifyPropertyChanged, ErrorAction> obj_error = new Dictionary<INotifyPropertyChanged, ErrorAction>();
void InitError() void InitError()
{ {
byte code = 0;
//反射找出全部是报警的property //反射找出全部是报警的property
List<string> error_accessory_property = new List<string>();
foreach (var propertyInfo in typeof(WinderAccessory).GetProperties())
{ {
if (propertyInfo.GetCustomAttributes(typeof(IsErrorAttribute), false).Count() > 0) List<ErrorInfo> error_accessory_property = new List<ErrorInfo>();
foreach (var propertyInfo in typeof(WinderAccessory).GetProperties())
{ {
error_accessory_property.Add(propertyInfo.Name); if (propertyInfo.GetCustomAttributes(typeof(IsErrorAttribute), false).Count() > 0)
{
string desp = (propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).First() as DescriptionAttribute).Description;
bool offIsError = (propertyInfo.GetCustomAttributes(typeof(IsErrorAttribute), false).First() as IsErrorAttribute).OffIsError;
ErrorInfo errorInfo = new ErrorInfo()
{
property = propertyInfo.Name,
msg = desp,
offIsError = offIsError,
code = code
};
error_accessory_property.Add(errorInfo);
code++;
}
} }
obj_error.Add(Accessory, new ErrorAction()
{
error_property = error_accessory_property
});
} }
List<string> error_winder_property = new List<string>();
foreach (var propertyInfo in typeof(WinderInsideOutside).GetProperties())
{ {
if (propertyInfo.GetCustomAttributes(typeof(IsErrorAttribute), false).Count() > 0) List<ErrorInfo> error_winder_property = new List<ErrorInfo>();
foreach (var propertyInfo in typeof(WinderInsideOutside).GetProperties())
{ {
error_winder_property.Add(propertyInfo.Name); if (propertyInfo.GetCustomAttributes(typeof(IsErrorAttribute), false).Count() > 0)
{
string desp = (propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).First() as DescriptionAttribute).Description;
bool offIsError = (propertyInfo.GetCustomAttributes(typeof(IsErrorAttribute), false).First() as IsErrorAttribute).OffIsError;
ErrorInfo errorInfo = new ErrorInfo()
{
property = propertyInfo.Name,
msg = desp,
offIsError = offIsError,
code = code
};
code++;
error_winder_property.Add(errorInfo);
}
} }
obj_error.Add(Items[0], new ErrorAction()
{
error_property = error_winder_property,
action = (ref string description, object state) =>
{
description = "内" + description;
}
});
} }
obj_error.Add(Accessory, new ErrorAction()
{ {
error_property = error_accessory_property List<ErrorInfo> error_winder_property = new List<ErrorInfo>();
}); foreach (var propertyInfo in typeof(WinderInsideOutside).GetProperties())
{
if (propertyInfo.GetCustomAttributes(typeof(IsErrorAttribute), false).Count() > 0)
{
string desp = (propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).First() as DescriptionAttribute).Description;
bool offIsError = (propertyInfo.GetCustomAttributes(typeof(IsErrorAttribute), false).First() as IsErrorAttribute).OffIsError;
obj_error.Add(Items[0], new ErrorAction()
{
error_property = error_winder_property,
action = (ref string description, object state) => {
description = "内" + description;
}
});
obj_error.Add(Items[1], new ErrorAction() ErrorInfo errorInfo = new ErrorInfo()
{ {
error_property = error_winder_property, property = propertyInfo.Name,
action = (ref string description, object state) => { msg = desp,
description = "外" + description; offIsError = offIsError,
code = code
};
code++;
error_winder_property.Add(errorInfo);
}
} }
});
obj_error.Add(Items[1], new ErrorAction()
{
error_property = error_winder_property,
action = (ref string description, object state) =>
{
description = "外" + description;
}
});
}
foreach (var obj in obj_error.Keys) foreach (var obj in obj_error.Keys)
{ {
...@@ -134,7 +195,7 @@ namespace FLY.Winder.Server ...@@ -134,7 +195,7 @@ namespace FLY.Winder.Server
foreach (var kv in obj_error) foreach (var kv in obj_error)
{ {
string objname = PLCos.ObjNames.First(_kv => _kv.Value == kv.Key).Key; string objname = PLCos.ObjNames.First(_kv => _kv.Value == kv.Key).Key;
PLCos.SetPlan(objname, kv.Value.error_property.ToArray(), 0); PLCos.SetPlan(objname, kv.Value.error_property.Select(ei=>ei.property).ToArray(), 0);
} }
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
...@@ -160,7 +221,7 @@ namespace FLY.Winder.Server ...@@ -160,7 +221,7 @@ namespace FLY.Winder.Server
foreach (var kv in obj_error) foreach (var kv in obj_error)
{ {
object sender = kv.Key; object sender = kv.Key;
foreach (string propertyname in kv.Value.error_property) foreach (string propertyname in kv.Value.error_property.Select(ei => ei.property))
{ {
Obj_PropertyChanged_ForError(sender, new PropertyChangedEventArgs(propertyname)); Obj_PropertyChanged_ForError(sender, new PropertyChangedEventArgs(propertyname));
} }
...@@ -174,16 +235,19 @@ namespace FLY.Winder.Server ...@@ -174,16 +235,19 @@ namespace FLY.Winder.Server
void Obj_PropertyChanged_ForError(object sender, PropertyChangedEventArgs e) void Obj_PropertyChanged_ForError(object sender, PropertyChangedEventArgs e)
{ {
ErrorAction errorAction = obj_error[sender as INotifyPropertyChanged]; ErrorAction errorAction = obj_error[sender as INotifyPropertyChanged];
if (errorAction.error_property.Contains(e.PropertyName)) var eis = from ei in errorAction.error_property where ei.property == e.PropertyName select ei;
if(eis.Count()>0)
{ {
var ei = eis.First();
//获取描述 //获取描述
var type = sender.GetType(); var type = sender.GetType();
var property = type.GetProperty(e.PropertyName); var property = type.GetProperty(ei.property);// e.PropertyName);
bool b = (bool)property.GetValue(sender,null); bool b = (bool)property.GetValue(sender,null);
//肯定有,没有就让它出错!!! //肯定有,没有就让它出错!!!
string desp = (property.GetCustomAttributes(typeof(DescriptionAttribute), false).First() as DescriptionAttribute).Description; string desp = ei.msg;// (property.GetCustomAttributes(typeof(DescriptionAttribute), false).First() as DescriptionAttribute).Description;
bool offIsError = (property.GetCustomAttributes(typeof(IsErrorAttribute), false).First() as IsErrorAttribute).OffIsError; bool offIsError = ei.offIsError;// (property.GetCustomAttributes(typeof(IsErrorAttribute), false).First() as IsErrorAttribute).OffIsError;
ERR_STATE state; ERR_STATE state;
if(offIsError) if(offIsError)
...@@ -191,7 +255,7 @@ namespace FLY.Winder.Server ...@@ -191,7 +255,7 @@ namespace FLY.Winder.Server
else else
state = b ? ERR_STATE.ON : ERR_STATE.OFF; state = b ? ERR_STATE.ON : ERR_STATE.OFF;
byte errcode = ERRNOs.ERRNO_PLC_REG.Code; byte errcode = ei.code;// ERRNOs.ERRNO_PLC_REG.Code;
string description = desp; string description = desp;
errorAction.action?.Invoke(ref description, errorAction.state); errorAction.action?.Invoke(ref description, errorAction.state);
......
...@@ -65,13 +65,13 @@ ...@@ -65,13 +65,13 @@
<PLCVariable DeviceIndex="0" Mode="1" Addr="63535" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_CustomerScram" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63535" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_CustomerScram" />
<PLCVariable DeviceIndex="0" Mode="1" Addr="63514" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryForwLimit" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63514" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryForwLimit" />
<PLCVariable DeviceIndex="0" Mode="1" Addr="63515" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryBackwLimit" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63515" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryBackwLimit" />
<PLCVariable DeviceIndex="0" Mode="1" Addr="63575" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_AirRoller1Power" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63559" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_AirRoller1Power" />
<PLCVariable DeviceIndex="0" Mode="1" Addr="63576" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_AirRoller2Power" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63560" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_AirRoller2Power" />
<PLCVariable DeviceIndex="0" Mode="0" Addr="142" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_T1CommErr" /> <PLCVariable DeviceIndex="0" Mode="0" Addr="142" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_T1CommErr" />
<PLCVariable DeviceIndex="0" Mode="0" Addr="143" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_T2CommErr" /> <PLCVariable DeviceIndex="0" Mode="0" Addr="143" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_T2CommErr" />
<PLCVariable DeviceIndex="0" Mode="0" Addr="146" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryCommErr" /> <PLCVariable DeviceIndex="0" Mode="0" Addr="146" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryCommErr" />
<PLCVariable DeviceIndex="0" Mode="1" Addr="63584" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_Splint1CommErr" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63568" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_Splint1CommErr" />
<PLCVariable DeviceIndex="0" Mode="1" Addr="63585" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_Splint2CommErr" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63569" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_Splint2CommErr" />
<PLCVariable DeviceIndex="0" Mode="0" Addr="1202" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryFlLock" /> <PLCVariable DeviceIndex="0" Mode="0" Addr="1202" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryFlLock" />
<PLCVariable DeviceIndex="0" Mode="0" Addr="1203" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryBlLock" /> <PLCVariable DeviceIndex="0" Mode="0" Addr="1203" Type="bool" Scale="1" OwnerName="Accessory" PropertyName="IsError_RotaryBlLock" />
<PLCVariable DeviceIndex="0" Mode="4" Addr="924" Type="uint32" Scale="1" OwnerName="Items[0]" PropertyName="MeasureLen" /> <PLCVariable DeviceIndex="0" Mode="4" Addr="924" Type="uint32" Scale="1" OwnerName="Items[0]" PropertyName="MeasureLen" />
...@@ -288,7 +288,7 @@ ...@@ -288,7 +288,7 @@
<PLCVariable DeviceIndex="0" Mode="0" Addr="703" Type="bool" Scale="1" OwnerName="Items[1]" PropertyName="IsError_MoveOut" /> <PLCVariable DeviceIndex="0" Mode="0" Addr="703" Type="bool" Scale="1" OwnerName="Items[1]" PropertyName="IsError_MoveOut" />
<PLCVariable DeviceIndex="0" Mode="0" Addr="704" Type="bool" Scale="1" OwnerName="Items[0]" PropertyName="IsError_UnloadUp" /> <PLCVariable DeviceIndex="0" Mode="0" Addr="704" Type="bool" Scale="1" OwnerName="Items[0]" PropertyName="IsError_UnloadUp" />
<PLCVariable DeviceIndex="0" Mode="0" Addr="705" Type="bool" Scale="1" OwnerName="Items[1]" PropertyName="IsError_UnloadUp" /> <PLCVariable DeviceIndex="0" Mode="0" Addr="705" Type="bool" Scale="1" OwnerName="Items[1]" PropertyName="IsError_UnloadUp" />
<PLCVariable DeviceIndex="0" Mode="1" Addr="63583" Type="bool" Scale="1" OwnerName="Items[0]" PropertyName="IsError_PumpPower" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63567" Type="bool" Scale="1" OwnerName="Items[0]" PropertyName="IsError_PumpPower" />
<PLCVariable DeviceIndex="0" Mode="1" Addr="63570" Type="bool" Scale="1" OwnerName="Items[1]" PropertyName="IsError_PumpPower" /> <PLCVariable DeviceIndex="0" Mode="1" Addr="63554" Type="bool" Scale="1" OwnerName="Items[1]" PropertyName="IsError_PumpPower" />
</Variables> </Variables>
</PLCGroup> </PLCGroup>
\ No newline at end of file
...@@ -100,7 +100,7 @@ namespace Autogen_WS ...@@ -100,7 +100,7 @@ namespace Autogen_WS
if (!m.Success) if (!m.Success)
return false; return false;
string plc_vt = m.Groups[1].Value; string plc_vt = m.Groups[1].Value;
int plc_a = int.Parse(m.Groups[2].Value); //int plc_a = int.Parse(m.Groups[2].Value);
//查表 //查表
var cells = from _cell in mDevMapperRuleTable.Tables where _cell.PLCVarType == plc_vt select _cell; var cells = from _cell in mDevMapperRuleTable.Tables where _cell.PLCVarType == plc_vt select _cell;
...@@ -109,12 +109,20 @@ namespace Autogen_WS ...@@ -109,12 +109,20 @@ namespace Autogen_WS
type = cells.First().VarType; type = cells.First().VarType;
//特别的, M0~... D0~.... 是连续的 //特别的, M0~... D0~.... 是10进制
//但 X0~X7 ,X10~X17, Y0~Y7 ,Y10~Y17, 不是连续的 //但 X0~X7 ,X10~X17,X70~X77,X100~X107, Y0~Y7 ,Y10~Y17, 是8进制
int plc_a;
if (plc_vt == "X" || plc_vt == "Y") if (plc_vt == "X" || plc_vt == "Y")
{ {
plc_a = ((int)(plc_a / 10)) * 8 + plc_a % 10; plc_a = Convert.ToInt32(m.Groups[2].Value, 8);// ((int)(plc_a / 10)) * 8 + plc_a % 10;
} }
else
{
plc_a = Convert.ToInt32(m.Groups[2].Value, 10);
}
addr = (plc_a - cells.First().PLCAddr1st) + cells.First().Addr1st; addr = (plc_a - cells.First().PLCAddr1st) + cells.First().Addr1st;
return true; return true;
......
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