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
5f82430a
Commit
5f82430a
authored
Jul 10, 2021
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 ModbusMapper 添加注解
parent
76075ffe
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
20 deletions
+42
-20
ModbusMapper.cs
Project.FLY.ModbusMapper/FLY.ModbusMapper/ModbusMapper.cs
+10
-8
RegisterData.cs
Project.FLY.ModbusMapper/FLY.ModbusMapper/RegisterData.cs
+10
-4
ClientTCP.cs
...FLY.ModbusMapper/FLY.ModbusMapper/WithThread/ClientTCP.cs
+11
-3
PLCProxySystem.cs
....FLY.OBJComponents/OBJComponents/Server/PLCProxySystem.cs
+11
-5
No files found.
Project.FLY.ModbusMapper/FLY.ModbusMapper/ModbusMapper.cs
View file @
5f82430a
...
...
@@ -173,7 +173,7 @@ namespace FLY.Modbus
DataToRegs
dr
=
area_regs
.
regs
[
i
];
if
(
endAddr
<
dr
.
addr
)
{
//
在
前面
//
当前输入的全部PLC寄存器 在 dr的
前面
break
;
}
...
...
@@ -192,10 +192,10 @@ namespace FLY.Modbus
if
(
plc_value
[
idx1
]
!=
vals
.
ElementAt
(
idx2
))
{
plc_value
[
idx1
]
=
vals
.
ElementAt
(
idx2
);
area_regs
.
regs
[
i
].
isPlcValueChanged
=
true
;
dr
.
isPlcValueChanged
=
true
;
//其中 一个PLC寄存器 被改变了
}
}
if
(
endAddr_act
==
dr
.
endAddr
)
if
(
endAddr_act
==
dr
.
endAddr
)
//枚举到 dr 的最后一个寄存器了,触发动作
{
if
(
dr
.
isPlcValueChanged
)
{
...
...
@@ -366,6 +366,11 @@ namespace FLY.Modbus
/// 需要被更新的 寄存器数量
/// </summary>
public
int
DRNeedUpdateCnt
{
get
;
private
set
;
}
/// <summary>
/// 计划列表更新时间
/// </summary>
public
DateTime
PlanUpdateTime
{
get
;
private
set
;
}
/// <summary>
/// 总寄存器数量
/// </summary>
...
...
@@ -399,12 +404,9 @@ namespace FLY.Modbus
dr
.
isNeedUpdate
=
true
;
}
}
//foreach (DataToRegs dr in DRmap)
//{
// dr.isNeedUpdate = true;
//}
DRNeedUpdateCnt
=
DRmap
.
Count
((
dr
)
=>
dr
.
isNeedUpdate
);
DRNeedUpdateCnt
=
DRmap
.
Count
((
dr
)
=>
dr
.
isNeedUpdate
);
PlanUpdateTime
=
DateTime
.
Now
;
foreach
(
var
areaManager
in
mAreaManager
)
areaManager
.
MakePlan
();
}
...
...
Project.FLY.ModbusMapper/FLY.ModbusMapper/RegisterData.cs
View file @
5f82430a
...
...
@@ -41,7 +41,7 @@ namespace FLY.Modbus
if
(!
regs
[
i
].
isNeedUpdate
)
continue
;
if
(
addr
==
-
1
)
if
(
addr
==
-
1
)
//上次的计划已经结束,重新来
{
addr
=
regs
[
i
].
addr
;
UInt16
[]
plc_value
=
(
UInt16
[])
regs
[
i
].
plcValue
;
...
...
@@ -55,7 +55,7 @@ namespace FLY.Modbus
addr
+=
maxOfOneRead
;
num
-=
maxOfOneRead
;
}
if
(
num
>
0
)
if
(
num
>
0
)
//最后一些
plan
.
Add
(
new
Plan
(
area
,
addr
,
num
));
addr
=
-
1
;
}
...
...
@@ -63,23 +63,29 @@ namespace FLY.Modbus
else
{
UInt16
[]
plc_value
=
(
UInt16
[])
regs
[
i
].
plcValue
;
int
n
=
regs
[
i
].
addr
+
plc_value
.
Count
()
-
1
-
addr
+
1
;
//新的 最后一个寄存器地址
int
addr_end
=
regs
[
i
].
addr
+
plc_value
.
Count
()
-
1
;
//总数量
int
n
=
addr_end
-
addr
+
1
;
if
(
n
<=
maxOfOneRead
)
{
//还没长于单次最大数量,累计进去
num
=
n
;
}
else
{
//不行,太长,之前的截断,添加到 计划
plan_buffer
.
Add
(
new
Plan
(
area
,
addr
,
num
));
addr
=
-
1
;
//reg[i] 退回,下次再运算
i
--;
}
}
}
if
(
addr
!=
-
1
)
if
(
addr
!=
-
1
)
//上次还 添加到计划中
{
plan_buffer
.
Add
(
new
Plan
(
area
,
addr
,
num
));
addr
=
-
1
;
...
...
Project.FLY.ModbusMapper/FLY.ModbusMapper/WithThread/ClientTCP.cs
View file @
5f82430a
...
...
@@ -14,7 +14,7 @@ namespace FLY.Modbus.WithThread
/// <summary>
/// 基于线程,所有动作都会堵塞,必须确保只有一个Task操作
/// </summary>
public
class
ClientTCP
:
INotifyPropertyChanged
,
IModbusClient
public
class
ClientTCP
:
INotifyPropertyChanged
,
IModbusClient
{
/// <summary>
/// 通信超时, 默认是 1s
...
...
@@ -24,7 +24,7 @@ namespace FLY.Modbus.WithThread
/// socket 错误信息
/// </summary>
public
string
ErrMsg
{
get
;
set
;
}
/// <summary>
/// 连接成功
/// </summary>
...
...
@@ -34,7 +34,7 @@ namespace FLY.Modbus.WithThread
/// 标识,modbus tcp的参数
/// </summary>
public
byte
UnitID
=
1
;
UInt16
tranid
=
12
;
UInt16
GetFreeTranID
()
{
...
...
@@ -46,6 +46,14 @@ namespace FLY.Modbus.WithThread
/// 远端地址
/// </summary>
public
IPEndPoint
RemoteEP
{
get
;
set
;
}
public
string
RemoteAddr
{
get
{
if
(
RemoteEP
!=
null
)
{
return
RemoteEP
.
ToString
();
}
return
null
;
}
}
Socket
sock
;
public
event
PropertyChangedEventHandler
PropertyChanged
;
...
...
Project.FLY.OBJComponents/OBJComponents/Server/PLCProxySystem.cs
View file @
5f82430a
...
...
@@ -206,16 +206,22 @@ namespace FLY.OBJComponents.Server
//object value = plc.GetNameData(e.Owener, e.PropertyName);
//这是从PLC 更新过来的,不需要向PLC写入
FObjBase
.
PollModule
.
Current
.
Dispatcher
.
Invoke
(
new
SetValueHandler
((
owner
,
propertyname
,
value
)
=>
//FObjBase.PollModule.Current.Dispatcher.Invoke(new SetValueHandler((owner, propertyName, value) =>
//{
// isShield = true;
// Misc.PropertiesManager.SetValue(owner, propertyName, value);
// isShield = false;
//}), dr.owner, dr.propertyName, dr.value);
FObjBase
.
PollModule
.
Current
.
Dispatcher
.
Invoke
(()
=>
{
isShield
=
true
;
Misc
.
PropertiesManager
.
SetValue
(
dr
.
owner
,
dr
.
propertyName
,
dr
.
value
);
isShield
=
false
;
}),
dr
.
owner
,
dr
.
propertyName
,
dr
.
value
);
});
}
delegate
void
SetValueHandler
(
object
owner
,
string
propertyname
,
object
value
);
//
delegate void SetValueHandler(object owner, string propertyname, object value);
/// <summary>
/// 设置更新计划
/// </summary>
...
...
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