Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
3fc76b07
Commit
3fc76b07
authored
May 20, 2022
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 ErrorConf 添加PLC 断开 报警编号
parent
a20a0d42
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
54 deletions
+54
-54
ErrorConf.cs
Project.FLY.OBJComponents/OBJComponents/Server/ErrorConf.cs
+54
-54
No files found.
Project.FLY.OBJComponents/OBJComponents/Server/ErrorConf.cs
View file @
3fc76b07
...
...
@@ -17,7 +17,6 @@ namespace FLY.OBJComponents.Server
const
int
MARKNO_DELAY_ISCONNECTED
=
4
;
#
endregion
List
<
string
>
plcNames
;
/// <summary>
/// 需要设置
/// </summary>
...
...
@@ -26,21 +25,49 @@ namespace FLY.OBJComponents.Server
/// 报警系统
/// </summary>
WarningSystem2
mWarning
;
public
byte
ErrCode
=
0
;
public
ErrorConf
(
PLCProxySystem
PLCos
,
WarningSystem2
mWarning
,
string
plcName
)
/// <summary>
/// 报警码自动排号,再枚举IsError 属性,对应的异常会被设置为ErrCode, 然后ErrCode++
/// </summary>
public
int
ErrCode
=
0
;
class
PlcDisconnectedErrMsg
{
this
.
PLCos
=
PLCos
;
this
.
mWarning
=
mWarning
;
plcNames
=
new
List
<
string
>();
plcNames
.
Add
(
plcName
);
public
int
ErrCode
;
public
string
Description
;
}
List
<
PlcDisconnectedErrMsg
>
plcDisconnectedErrMsgs
=
new
List
<
PlcDisconnectedErrMsg
>();
public
ErrorConf
(
PLCProxySystem
PLCos
,
WarningSystem2
mWarning
,
string
plcName
)
:
this
(
PLCos
,
mWarning
,
new
string
[]
{
plcName
})
{
}
public
ErrorConf
(
PLCProxySystem
PLCos
,
WarningSystem2
mWarning
,
string
[]
plcNames
)
{
initialize
(
PLCos
,
mWarning
,
plcNames
,
PlcErrNos
.
Instance
.
ERRNO_PLC_DISCONNECTED
.
Code
-
(
PLCos
.
PLCs
.
Count
()
-
1
));
}
public
ErrorConf
(
PLCProxySystem
PLCos
,
WarningSystem2
mWarning
,
string
[]
plcNames
,
int
plcErrCodeBegin
)
{
initialize
(
PLCos
,
mWarning
,
plcNames
,
plcErrCodeBegin
);
}
void
initialize
(
PLCProxySystem
PLCos
,
WarningSystem2
mWarning
,
string
[]
plcNames
,
int
plcErrCodeBegin
)
{
this
.
PLCos
=
PLCos
;
this
.
mWarning
=
mWarning
;
this
.
plcNames
=
new
List
<
string
>();
if
(
plcNames
.
All
(
s
=>
!
string
.
IsNullOrEmpty
(
s
)))
this
.
plcNames
.
AddRange
(
plcNames
);
//初始化 PLC连接断开的描述列表
int
plcCnt
=
PLCos
.
PLCs
.
Count
();
int
errCode
=
plcErrCodeBegin
;
string
descrption
=
PlcErrNos
.
Instance
.
ERRNO_PLC_DISCONNECTED
.
Descrption
;
for
(
int
i
=
0
;
i
<
plcCnt
;
i
++)
{
plcDisconnectedErrMsgs
.
Add
(
new
PlcDisconnectedErrMsg
()
{
ErrCode
=
errCode
+
i
,
Description
=
$"
{
GetPlcName
(
plcCnt
,
i
,
plcNames
)}
"
+
descrption
});
}
}
#
region
报警
public
class
ErrorAction
...
...
@@ -53,7 +80,7 @@ namespace FLY.OBJComponents.Server
public
class
ErrorInfo
{
public
string
property
;
public
byte
code
;
public
int
code
;
public
string
msg
;
}
Dictionary
<
INotifyPropertyChanged
,
ErrorAction
>
obj_error
=
new
Dictionary
<
INotifyPropertyChanged
,
ErrorAction
>();
...
...
@@ -113,62 +140,35 @@ namespace FLY.OBJComponents.Server
{
for
(
int
i
=
0
;
i
<
PLCos
.
PLCs
.
Count
();
i
++)
{
bool
b
=
!
PLCos
.
PLCs
[
i
].
Client
.
IsConnected
;
ERR_STATE
state
=
b
?
ERR_STATE
.
ON
:
ERR_STATE
.
OFF
;
ERRNO
errno
=
PlcErrNos
.
Instance
.
ERRNO_PLC_DISCONNECTED
;
UInt16
errcode
=
(
UInt16
)(
errno
.
Code
-
i
);
string
description
=
$"
{
GetPlcName
(
i
)}
"
+
errno
.
Descrption
;
mWarning
.
Add
(
errcode
,
description
,
state
);
int
errcode
=
plcDisconnectedErrMsgs
[
i
].
ErrCode
;
string
description
=
plcDisconnectedErrMsgs
[
i
].
Description
;
if
(!
PLCos
.
PLCs
[
i
].
Client
.
IsConnected
)
{
mWarning
.
Add
(
errcode
,
description
,
canReset
:
false
);
}
else
{
mWarning
.
Remove
(
errcode
);
}
}
},
TimeSpan
.
FromSeconds
(
3
),
true
,
false
,
this
,
MARKNO_DELAY_ISCONNECTED
,
false
);
//--------------------------------------------------------------------------------
//启动定时器,每1秒查报警,防止 以为报警复位了,但其实还在报警
//FObjBase.PollModule.Current.Poll_Config(PollModule.POLL_CONFIG.ADD,
// () =>
// {
// foreach (var objError in obj_error)
// {
// object sender = objError.Key;
// ErrorAction errorAction = objError.Value;
// foreach (var ei in errorAction.error_property)
// {
// //获取描述
// var type = sender.GetType();
// var property = type.GetProperty(ei.property);
// bool b = (bool)property.GetValue(sender, null);
// string desp = ei.msg;
// ERR_STATE state = b ? ERR_STATE.ON : ERR_STATE.OFF;
// byte errcode = ei.code;//每个报警必须不一样!!
// string description = desp;
// errorAction.action?.Invoke(ref description, errorAction.state);
// mWarning.Add(errcode, description, state);
// }
// }
// }, TimeSpan.FromSeconds(3));
}
string
GetPlcName
(
int
index
)
string
GetPlcName
(
int
plcCnt
,
int
index
,
string
[]
plcNames
)
{
if
(
PLCos
.
PLCs
.
Count
()
==
1
)
if
(
plcCnt
==
1
)
{
return
plcNames
[
0
];
}
//多个PLC
if
(
PLCos
.
PLCs
.
Count
()
!=
plcNames
.
Count
())
if
(
plcCnt
!=
plcNames
.
Count
())
{
//没有定义全部名字
return
$"
{
plcNames
[
0
]}
No.
{
index
+
1
}
"
;
}
return
plcNames
[
index
];
}
public
void
ResetError
(
INotifyPropertyChanged
sender
)
...
...
@@ -200,7 +200,7 @@ namespace FLY.OBJComponents.Server
var
property
=
type
.
GetProperty
(
ei
.
property
);
bool
b
=
(
bool
)
property
.
GetValue
(
sender
,
null
);
string
description
=
ei
.
msg
;
byte
errcode
=
ei
.
code
;
//每个报警必须不一样!!
int
errcode
=
ei
.
code
;
//每个报警必须不一样!!
if
(
b
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment