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
58dba8c6
Commit
58dba8c6
authored
Jan 11, 2020
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://private.flyautomation.net:82/panruising/thick_public
parents
65e4bb49
698dda0b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
26 deletions
+42
-26
PLCProxySystem.cs
....FLY.OBJComponents/OBJComponents/Server/PLCProxySystem.cs
+42
-26
No files found.
Project.FLY.OBJComponents/OBJComponents/Server/PLCProxySystem.cs
View file @
58dba8c6
...
@@ -15,7 +15,10 @@ namespace FLY.OBJComponents.Server
...
@@ -15,7 +15,10 @@ namespace FLY.OBJComponents.Server
public
class
PLCProxySystem
:
IPLCProxySystemService
,
IPropertyOpt
public
class
PLCProxySystem
:
IPLCProxySystemService
,
IPropertyOpt
{
{
NLog
.
ILogger
logger
=
NLog
.
LogManager
.
GetCurrentClassLogger
();
NLog
.
ILogger
logger
=
NLog
.
LogManager
.
GetCurrentClassLogger
();
/// <summary>
/// 用于调试, 在这个表内的属性不输出调试
/// </summary>
public
List
<
SenderProperty
>
IgnoreLogProperties
=
new
List
<
SenderProperty
>();
class
Plan
class
Plan
{
{
/// <summary>
/// <summary>
...
@@ -78,21 +81,12 @@ namespace FLY.OBJComponents.Server
...
@@ -78,21 +81,12 @@ namespace FLY.OBJComponents.Server
//PLCs[0].Start();
//PLCs[0].Start();
}
}
private
void
Obj_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
isShield
)
return
;
List
<
DataToRegs
>
drs
=
DRMap
;
DataToRegs
dr
=
drs
.
Find
((
_dr
)
=>
{
return
(
_dr
.
propertyName
==
e
.
PropertyName
)
&&
(
_dr
.
owner
==
sender
);
});
if
(
dr
==
null
)
return
;
//不会刷新PLC
void
LogProperty
(
object
sender
,
string
propertyName
,
DataToRegs
dr
)
if
(
logger
.
IsInfoEnabled
)
{
{
//注解
//注解
var
property
=
sender
.
GetType
().
GetProperty
(
e
.
P
ropertyName
);
var
property
=
sender
.
GetType
().
GetProperty
(
p
ropertyName
);
var
attrs
=
property
.
GetCustomAttributes
(
typeof
(
DescriptionAttribute
),
false
);
var
attrs
=
property
.
GetCustomAttributes
(
typeof
(
DescriptionAttribute
),
false
);
string
desp
=
""
;
string
desp
=
""
;
if
(
attrs
.
Count
()
>
0
)
if
(
attrs
.
Count
()
>
0
)
...
@@ -104,25 +98,41 @@ namespace FLY.OBJComponents.Server
...
@@ -104,25 +98,41 @@ namespace FLY.OBJComponents.Server
var
new_value
=
property
.
GetValue
(
sender
,
null
);
var
new_value
=
property
.
GetValue
(
sender
,
null
);
//旧值
//旧值
var
old_value
=
dr
.
mapper
.
GetNameData
(
sender
,
e
.
P
ropertyName
);
var
old_value
=
dr
.
mapper
.
GetNameData
(
sender
,
p
ropertyName
);
//PLC地址
//PLC地址
string
plcAddr
=
$"
{(
dr
.
dataArea
==
PLCAddressArea
.
Coil
?
"M"
:
"D"
)}{
dr
.
addr
}
"
;
string
plcAddr
=
$"
{(
dr
.
dataArea
==
PLCAddressArea
.
Coil
?
"M"
:
"D"
)}{
dr
.
addr
}
"
;
//对象名称
//对象名称
string
objName
=
""
;
string
objName
=
""
;
var
names
=
from
kv
in
ObjNames
where
kv
.
Value
==
sender
select
kv
.
Key
;
var
names
=
from
kv
in
ObjNames
where
kv
.
Value
==
sender
select
kv
.
Key
;
if
(
names
.
Count
()>
0
)
if
(
names
.
Count
()
>
0
)
objName
=
names
.
First
();
objName
=
names
.
First
();
logger
.
Info
(
$"
{
objName
}
.
{
e
.
PropertyName
}
[
{
desp
}
] [
{
plcAddr
}
] (
{
old_value
}
)->(
{
new_value
}
)"
);
logger
.
Info
(
$"
{
objName
}
.
{
propertyName
}
[
{
desp
}
] [
{
plcAddr
}
] (
{
old_value
}
)->(
{
new_value
}
)"
);
}
private
void
Obj_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
isShield
)
return
;
List
<
DataToRegs
>
drs
=
DRMap
;
DataToRegs
dr
=
drs
.
Find
((
_dr
)
=>
{
return
(
_dr
.
propertyName
==
e
.
PropertyName
)
&&
(
_dr
.
owner
==
sender
);
});
if
(
dr
==
null
)
return
;
//不会刷新PLC
if
(
logger
.
IsInfoEnabled
)
{
if
(!
IgnoreLogProperties
.
Exists
(
sp
=>
sp
.
sender
==
sender
&&
sp
.
propertyName
==
e
.
PropertyName
))
{
LogProperty
(
sender
,
e
.
PropertyName
,
dr
);
}
}
}
//向PLC写入数据,mRegs每次只能写入一个,它有列表保存功能。
//向PLC写入数据,mRegs每次只能写入一个,它有列表保存功能。
//SetNameData可以执行很多次,不过它只能一个个发。
//SetNameData可以执行很多次,不过它只能一个个发。
dr
.
mapper
.
SetNameData
(
dr
,
Misc
.
PropertiesManager
.
GetValue
(
sender
,
e
.
PropertyName
));
dr
.
mapper
.
SetNameData
(
dr
,
Misc
.
PropertiesManager
.
GetValue
(
sender
,
e
.
PropertyName
));
}
}
/// <summary>
/// <summary>
...
@@ -303,4 +313,10 @@ namespace FLY.OBJComponents.Server
...
@@ -303,4 +313,10 @@ namespace FLY.OBJComponents.Server
return
null
;
return
null
;
}
}
}
}
public
class
SenderProperty
{
public
object
sender
;
public
string
propertyName
;
}
}
}
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