Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hemei
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
潘栩锋
hemei
Commits
064c0c51
Commit
064c0c51
authored
Jan 18, 2019
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 实际测试PLC,上料全部寄存读取,只需要0.07s
parent
52095453
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
323 additions
and
156 deletions
+323
-156
FeedbackHeatServiceClient.cs
.../FLY.FeedbackRenZiJia/Client/FeedbackHeatServiceClient.cs
+6
-1
IFeedbackHeat.cs
...ckRenZiJia/FLY.FeedbackRenZiJia/IService/IFeedbackHeat.cs
+7
-1
FeedbackHeat.cs
...dbackRenZiJia/FLY.FeedbackRenZiJia/Server/FeedbackHeat.cs
+52
-47
PLCLink.cs
...Y.FeedbackRenZiJia/FLY.FeedbackRenZiJia/Server/PLCLink.cs
+16
-5
AreaManager.cs
Project.FLY.ModbusMapper/FLY.ModbusMapper/AreaManager.cs
+2
-2
ClientTCP.cs
Project.FLY.ModbusMapper/FLY.ModbusMapper/ClientTCP.cs
+1
-1
ModbusMapper.cs
Project.FLY.ModbusMapper/FLY.ModbusMapper/ModbusMapper.cs
+1
-1
Pack_Proto.cs
Project.FLY.ModbusMapper/FLY.ModbusMapper/Pack_Proto.cs
+3
-3
ClientTCP.cs
...FLY.ModbusMapper/FLY.ModbusMapper/WithThread/ClientTCP.cs
+84
-58
ModbusMapper_Client.cs
...Mapper/FLY.ModbusMapper/WithThread/ModbusMapper_Client.cs
+76
-27
PLCProxySystem.cs
....FLY.OBJComponents/OBJComponents/Server/PLCProxySystem.cs
+4
-0
MainWindow.xaml
Project.FLY.Weight/FLY.Weight.UI.Server/MainWindow.xaml
+37
-5
MainWindow.xaml.cs
Project.FLY.Weight/FLY.Weight.UI.Server/MainWindow.xaml.cs
+5
-4
WeightSystem.cs
Project.FLY.Weight/FLY.Weight/Server/WeightSystem.cs
+12
-1
WinderSystem.cs
Project.FLY.Winder/FLY.Winder/Server/WinderSystem.cs
+1
-0
WS_local_test.xml
Resource/称重/设备连接变量表_341/Generated/WS_local_test.xml
+0
-0
cp_ws_local_test.ps1
Resource/称重/设备连接变量表_341/Generated/cp_ws_local_test.ps1
+16
-0
地址表.xlsx
风环PLC/PLC/PLC_V3_20190108/地址表.xlsx
+0
-0
No files found.
Project.FLY.FeedbackRenZiJia/FLY.FeedbackRenZiJia/Client/FeedbackHeatServiceClient.cs
View file @
064c0c51
...
...
@@ -9,7 +9,7 @@ using System.Collections.ObjectModel;
using
FLY.FeedbackRenZiJia.Common
;
using
FLY.Thick.Base.IService
;
using
FLY.FeedbackRenZiJia.IService
;
using
System.Net
;
namespace
FLY.FeedbackRenZiJia.Client
{
...
...
@@ -24,6 +24,11 @@ namespace FLY.FeedbackRenZiJia.Client
#
region
IFeedbackHeat
成员
#
region
参数
/// <summary>
/// 作为客户端模式
/// </summary>
public
bool
IsClient
{
get
;
set
;
}
public
IPEndPoint
PLCep
{
get
;
set
;
}
/// <summary>
/// 自动控制使能
...
...
Project.FLY.FeedbackRenZiJia/FLY.FeedbackRenZiJia/IService/IFeedbackHeat.cs
View file @
064c0c51
...
...
@@ -9,13 +9,19 @@ using FLY.Thick.Base.IService;
using
FObjBase
;
using
FLY.Thick.RemoteHistory
;
using
System.Text.RegularExpressions
;
using
System.Net
;
namespace
FLY.FeedbackRenZiJia.IService
{
public
interface
IFeedbackHeat
:
INotifyPropertyChanged
{
#
region
参数
/// <summary>
/// 作为客户端模式
/// </summary>
bool
IsClient
{
get
;
set
;
}
IPEndPoint
PLCep
{
get
;
set
;
}
/// <summary>
/// 自控使能, 不保存!!!
/// </summary>
...
...
Project.FLY.FeedbackRenZiJia/FLY.FeedbackRenZiJia/Server/FeedbackHeat.cs
View file @
064c0c51
...
...
@@ -14,6 +14,7 @@ using FLY.Thick.Base.IService;
using
FLY.FeedbackRenZiJia.IService
;
using
FLY.OBJComponents.Server
;
using
FLY.OBJComponents.Common
;
using
System.Net
;
namespace
FLY.FeedbackRenZiJia.Server
{
...
...
@@ -29,7 +30,11 @@ namespace FLY.FeedbackRenZiJia.Server
#
region
IFeedbackHeat
成员
#
region
参数
/// <summary>
/// 作为客户端模式
/// </summary>
public
bool
IsClient
{
get
;
set
;
}
public
IPEndPoint
PLCep
{
get
;
set
;
}
/// <summary>
/// 自动控制使能
/// </summary>
...
...
@@ -79,7 +84,7 @@ namespace FLY.FeedbackRenZiJia.Server
/// <summary>
/// 当前
/// </summary>
public
int
[]
Currs
{
get
;
set
;
}
//
public int[] Currs { get; set; }
#
endregion
...
...
@@ -130,9 +135,9 @@ namespace FLY.FeedbackRenZiJia.Server
#
endregion
#
endregion
private
IPLCLink
hmi
;
private
IPLCLink
plc
;
private
FLY
.
Thick
.
Blowing
.
IService
.
IBlowing
renzijia
;
private
FLY
.
Thick
.
Blowing
.
IService
.
IBlowingDetect
mBDetect
;
private
UInt16
CurrsUpdate
=
0
;
...
...
@@ -156,14 +161,17 @@ namespace FLY.FeedbackRenZiJia.Server
public
FeedbackHeat
()
{
hmi
=
new
HMI
();
hmi
.
PropertyChanged
+=
new
PropertyChangedEventHandler
(
hmi_PropertyChanged
);
Misc
.
BindingOperations
.
SetBinding
(
hmi
,
"HasElectricity"
,
this
,
"HasElectricity"
);
Misc
.
BindingOperations
.
SetBinding
(
hmi
,
"HasFan"
,
this
,
"HasFan"
);
PLCep
=
Misc
.
StringConverter
.
ToIPEndPoint
(
"192.168.251.9:502"
);
Load
();
if
(
IsClient
)
plc
=
new
PLCLink
(
PLCep
);
else
plc
=
new
HMI
();
plc
.
PropertyChanged
+=
new
PropertyChangedEventHandler
(
hmi_PropertyChanged
);
Misc
.
BindingOperations
.
SetBinding
(
plc
,
"HasElectricity"
,
this
,
"HasElectricity"
);
Misc
.
BindingOperations
.
SetBinding
(
plc
,
"HasFan"
,
this
,
"HasFan"
);
InitBuf
();
...
...
@@ -230,7 +238,7 @@ namespace FLY.FeedbackRenZiJia.Server
mHeatCheck
.
Init
(
mHeatCell
);
mHeatCheck
.
PropertyChanged
+=
new
PropertyChangedEventHandler
(
mHeatCheck_PropertyChanged
);
Misc
.
BindingOperations
.
SetBinding
(
hmi
,
"HasElectricity"
,
mHeatCheck
,
"HasElectricity"
);
Misc
.
BindingOperations
.
SetBinding
(
plc
,
"HasElectricity"
,
mHeatCheck
,
"HasElectricity"
);
Misc
.
BindingOperations
.
SetBinding
(
this
,
"HasCheck"
,
mHeatCheck
,
"Has"
);
Misc
.
BindingOperations
.
SetBinding
(
mHeatCheck
,
"Enable"
,
this
,
"CheckEnable"
,
Misc
.
BindingOperations
.
BindingMode
.
TwoWay
);
Misc
.
BindingOperations
.
SetBinding
(
mHeatCheck
,
"CheckNo"
,
this
,
"CheckNo"
);
...
...
@@ -374,8 +382,8 @@ namespace FLY.FeedbackRenZiJia.Server
void
InitBuf
()
{
hmi
.
ChannelCnt
=
(
UInt16
)
ChannelCnt
;
Currs
=
new
int
[
ChannelCnt
];
plc
.
ChannelCnt
=
(
UInt16
)
ChannelCnt
;
//
Currs = new int[ChannelCnt];
mHeatChanged
.
Init
(
ChannelCnt
);
mHeatBuf
.
Init
(
NBolts
,
ChannelCnt
);
mHeatCell
.
Init2
(
NBolts
,
ChannelCnt
);
...
...
@@ -386,44 +394,20 @@ namespace FLY.FeedbackRenZiJia.Server
}
void
hmi_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
e
.
PropertyName
==
"
CurrUpdate
"
)
if
(
e
.
PropertyName
==
"
Errno
"
)
{
if
(
hmi
.
CurrUpdate
!=
CurrsUpdate
)
if
(
plc
.
Errno
==
-
1
)
{
CurrsUpdate
=
hmi
.
CurrUpdate
;
bool
isupdate
=
false
;
IEnumerable
<
UInt16
>
list
=
hmi
.
GetCurr
();
//更新了
for
(
int
i
=
0
;
i
<
ChannelCnt
&&
i
<
list
.
Count
();
i
++)
{
if
(
Currs
[
i
]
!=
list
.
ElementAt
(
i
))
{
Currs
[
i
]
=
list
.
ElementAt
(
i
);
isupdate
=
true
;
}
}
if
(
isupdate
)
{
NotifyPropertyChanged
(
"Currs"
);
//把Currs 复制到 HeatCell.Heats
mHeatCell
.
ModifyHeats
(
Currs
);
}
}
}
else
if
(
e
.
PropertyName
==
"Errno"
)
{
if
(
hmi
.
Errno
==
-
1
)
IsConnectedWithPLC
=
false
;
}
else
{
IsConnectedWithPLC
=
true
;
//刚成功连接上
,
//
把Currs 复制到 HeatCell.Heats
//mHeatCell.ModifyHeats(Currs
);
//刚成功连接上
//
重新复制数据到 PLC
RecoverPLC
(
);
}
}
}
...
...
@@ -643,10 +627,11 @@ namespace FLY.FeedbackRenZiJia.Server
}
UInt16
[]
last_heat
;
UInt16
last_heatupdate
;
void
Output
(
int
[]
heats
)
{
List
<
UInt16
>
list
=
new
List
<
UInt16
>();
for
(
int
i
=
0
;
i
<
ChannelCnt
;
i
++)
{
UInt16
heat
=
(
UInt16
)
heats
[
i
];
...
...
@@ -656,13 +641,33 @@ namespace FLY.FeedbackRenZiJia.Server
heat
=
100
;
list
.
Add
(
heat
);
}
hmi
.
SetHeat
(
list
);
UInt16
heatupdate
=
(
UInt16
)(
hmi
.
HeatUpdate
+
1
);
plc
.
SetHeat
(
list
);
last_heat
=
list
.
ToArray
();
UInt16
heatupdate
=
(
UInt16
)(
plc
.
HeatUpdate
+
1
);
if
(
heatupdate
==
0
)
heatupdate
=
1
;
hmi
.
HeatUpdate
=
heatupdate
;
plc
.
HeatUpdate
=
heatupdate
;
last_heatupdate
=
heatupdate
;
}
void
RecoverPLC
()
{
plc
.
ChannelCnt
=
(
UInt16
)
ChannelCnt
;
if
(
last_heat
!=
null
)
{
plc
.
SetHeat
(
last_heat
);
plc
.
HeatUpdate
=
last_heatupdate
;
}
else
{
//设置全部0进去
plc
.
SetHeat
(
new
UInt16
[
ChannelCnt
]);
plc
.
HeatUpdate
=
plc
.
HeatUpdate
;
}
}
void
Add
(
DateTime
time
,
DateTime
endtime
,
Misc
.
DIRECTION
direction
,
TimeSpan
period
,
int
rotateCnt
,
int
orgboltno
,
double
rAngle
,
double
filmLength
,
int
[]
frame
)
...
...
Project.FLY.FeedbackRenZiJia/FLY.FeedbackRenZiJia/Server/PLCLink.cs
View file @
064c0c51
...
...
@@ -79,10 +79,11 @@ namespace FLY.FeedbackRenZiJia.Server
#
endregion
#
region
状态
public
int
Errno
{
get
;
set
;
}
public
int
Errno
{
get
;
set
;
}
=
-
1
;
#
endregion
bool
IsRunning
;
public
PLCLink
(
IPEndPoint
ep
)
{
mclient
=
new
Modbus
.
WithThread
.
ClientTCP
(
ep
);
...
...
@@ -106,6 +107,8 @@ namespace FLY.FeedbackRenZiJia.Server
List
<
RegWrite
>
rws
=
new
List
<
RegWrite
>();
private
ushort
_channelCnt
;
private
ushort
_heatUpdate
;
private
UInt16
[]
heats
=
null
;
private
void
PLCLink_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
...
...
@@ -163,13 +166,16 @@ namespace FLY.FeedbackRenZiJia.Server
stopwatch
.
Restart
();
if
(!
UpdateReadData
())
return
;
//连接断开,终止更新线程
break
;
//连接断开,终止更新线程
Errno
=
0
;
}
//输出写入数据
if
(!
UpdateWriteData
())
return
;
//连接断开,终止更新线程
break
;
//连接断开,终止更新线程
Thread
.
Sleep
(
100
);
}
Errno
=
-
1
;
IsRunning
=
false
;
}
...
...
@@ -220,7 +226,7 @@ namespace FLY.FeedbackRenZiJia.Server
{
rws
.
Add
(
regWrite
);
}
heats
=
buf
;
}
/// <summary>
...
...
@@ -229,7 +235,12 @@ namespace FLY.FeedbackRenZiJia.Server
/// <returns></returns>
public
IEnumerable
<
UInt16
>
GetCurr
()
{
return
null
;
UInt16
[]
curr
=
new
UInt16
[
ChannelCnt
];
if
(
ChannelCnt
!=
0
&&
heats
!=
null
)
{
Array
.
Copy
(
heats
,
curr
,
Math
.
Min
(
ChannelCnt
,
heats
.
Count
()));
}
return
curr
;
}
}
}
Project.FLY.ModbusMapper/FLY.ModbusMapper/AreaManager.cs
View file @
064c0c51
...
...
@@ -10,8 +10,8 @@ namespace FLY.Modbus
/// <summary>
/// 现在工作中的读取计划任务
/// </summary>
p
rotected
List
<
Plan
>
plan
=
new
List
<
Plan
>();
p
ublic
List
<
Plan
>
plan
=
new
List
<
Plan
>();
/// <summary>
/// 当true, plan_buffer -> plan
/// </summary>
...
...
Project.FLY.ModbusMapper/FLY.ModbusMapper/ClientTCP.cs
View file @
064c0c51
...
...
@@ -118,7 +118,7 @@ namespace FLY.Modbus
{
Pack_Proto
p
=
new
Pack_Proto
();
int
rlen
;
if
(!
p
.
TryParse
(
inBuf
,
startIndex
,
out
rlen
))
if
(!
p
.
TryParse
(
inBuf
,
startIndex
,
inBuf
.
Length
,
out
rlen
))
{
//处理失败
return
startIndex
;
...
...
Project.FLY.ModbusMapper/FLY.ModbusMapper/ModbusMapper.cs
View file @
064c0c51
...
...
@@ -15,7 +15,7 @@ namespace FLY.Modbus
/// 一次读取的数据量
/// </summary>
const
int
MaxRegsOfOneRead
=
100
;
const
int
MaxCoilsOfOneRead
=
900
0
;
const
int
MaxCoilsOfOneRead
=
900
;
#
region
数据变化通知
/// <summary>
...
...
Project.FLY.ModbusMapper/FLY.ModbusMapper/Pack_Proto.cs
View file @
064c0c51
...
...
@@ -65,7 +65,7 @@ namespace FLY.Modbus
return
buf
.
ToArray
();
}
public
bool
TryParse
(
byte
[]
value
,
int
startIndex
,
out
int
rlen
)
public
bool
TryParse
(
byte
[]
value
,
int
startIndex
,
int
value_len
,
out
int
rlen
)
{
//格式——————————————
//MBAP
...
...
@@ -82,7 +82,7 @@ namespace FLY.Modbus
rlen
=
0
;
int
cnt
=
7
+
1
;
if
(
value
.
Count
()
<
cnt
)
if
(
value
_len
<
cnt
)
return
false
;
int
index
=
startIndex
;
tranid
=
COMMON
.
ToUInt16_Big_endian
(
value
,
index
);
...
...
@@ -94,7 +94,7 @@ namespace FLY.Modbus
index
+=
2
;
cnt
+=
len
-
2
;
if
(
value
.
Count
()
<
cnt
)
if
(
value
_len
<
cnt
)
return
false
;
unitid
=
value
[
index
];
...
...
Project.FLY.ModbusMapper/FLY.ModbusMapper/WithThread/ClientTCP.cs
View file @
064c0c51
...
...
@@ -19,7 +19,7 @@ namespace FLY.Modbus.WithThread
/// <summary>
/// 通信超时, 默认是 1s
/// </summary>
public
TimeSpan
Timeout
{
get
;
set
;
}
=
TimeSpan
.
FromSeconds
(
1
);
public
TimeSpan
Timeout
{
get
;
set
;
}
=
TimeSpan
.
FromSeconds
(
2
);
/// <summary>
/// socket 错误信息,带时间
/// </summary>
...
...
@@ -61,47 +61,60 @@ namespace FLY.Modbus.WithThread
public
ClientTCP
(
IPEndPoint
ep
)
{
RemoteEP
=
ep
;
sock
=
new
Socket
(
AddressFamily
.
InterNetwork
,
SocketType
.
Stream
,
ProtocolType
.
Tcp
);
Connect
(
true
);
}
bool
isconnecting
=
false
;
void
Connect
(
bool
isImmediately
)
/// <summary>
/// 工作中
/// </summary>
public
bool
IsRunning
{
get
;
private
set
;
}
/// <summary>
/// 用于停止Task
/// </summary>
CancellationTokenSource
cts
;
/// <summary>
/// 建立连接
/// </summary>
public
void
Connect
()
{
if
(
isconnect
ing
)
if
(
IsRunn
ing
)
return
;
isconnecting
=
true
;
Task
task
=
new
Task
((
state
)
=>
IsRunning
=
true
;
IsConnected
=
false
;
sock
=
new
Socket
(
AddressFamily
.
InterNetwork
,
SocketType
.
Stream
,
ProtocolType
.
Tcp
);
cts
=
new
CancellationTokenSource
();
Task
.
Factory
.
StartNew
(()
=>
{
bool
isImme
=
(
bool
)
state
;
if
(!
isImme
)
//不需要立刻连接,等待3秒后重试
Thread
.
Sleep
(
3000
);
while
(!
IsConnected
)
while
(
true
)
{
lock
(
this
)
if
(
cts
.
IsCancellationRequested
)
//被主动申请断开
break
;
try
{
try
{
sock
.
Connect
(
RemoteEP
);
IsConnected
=
true
;
}
catch
(
Exception
e
)
{
ErrMsg
=
e
.
Message
;
}
sock
.
Connect
(
RemoteEP
);
IsConnected
=
true
;
break
;
}
if
(!
IsConnected
)
Thread
.
Sleep
(
3000
);
catch
(
Exception
e
)
{
ErrMsg
=
e
.
Message
;
}
//连接失败,等待再尝试
Thread
.
Sleep
(
1000
);
}
isconnecting
=
false
;
},
isImmediately
);
task
.
Start
();
});
}
/// <summary>
/// 停止
/// </summary>
public
void
Stop
()
{
if
(!
IsRunning
)
return
;
IsRunning
=
false
;
sock
.
Close
();
IsConnected
=
false
;
cts
.
Cancel
();
}
bool
TranExecute
(
Pack_Proto
request
,
out
Pack_Proto
reponse
)
{
...
...
@@ -126,36 +139,27 @@ namespace FLY.Modbus.WithThread
goto
_end
;
}
byte
[]
recvBytes
=
new
byte
[
sock
.
ReceiveBufferSize
];
//回复的指令不可能大于2K
sock
.
ReceiveTimeout
=
(
int
)
Timeout
.
TotalMilliseconds
;
int
offset
=
0
;
//读取数据
while
(
true
)
{
byte
[]
recvBytes
=
new
byte
[
2048
];
//回复的指令不可能大于2K
sock
.
ReceiveTimeout
=
(
int
)
Timeout
.
TotalMilliseconds
;
int
offset
=
0
;
int
size
=
recvBytes
.
Length
-
offset
;
if
(
size
<=
0
)
{
//异常
ErrMsg
=
"TimeOut"
;
IsConnected
=
false
;
goto
_end
;
}
int
bytes
=
0
;
try
{
int
size
=
recvBytes
.
Length
-
offset
;
if
(
size
<=
0
)
{
//异常
ErrMsg
=
"TimeOut"
;
IsConnected
=
false
;
goto
_end
;
}
int
bytes
=
sock
.
Receive
(
recvBytes
,
offset
,
recvBytes
.
Length
,
0
);
//从客户端接受信息
//可能会分了多次接收
if
(!
reponse
.
TryParse
(
recvBytes
,
0
,
out
int
rlen
))
{
//处理失败,数据不够,继续接收
offset
=
bytes
;
}
else
{
break
;
}
bytes
=
sock
.
Receive
(
recvBytes
,
offset
,
size
,
SocketFlags
.
None
);
//从客户端接受信息,可能会分了多次接收
}
catch
(
SocketException
e
)
{
...
...
@@ -164,12 +168,34 @@ namespace FLY.Modbus.WithThread
IsConnected
=
false
;
goto
_end
;
}
if
(
bytes
==
0
)
{
//超时,或已经断开连接
ErrMsg
=
"TimeOut"
;
IsConnected
=
false
;
goto
_end
;
}
if
(!
reponse
.
TryParse
(
recvBytes
,
0
,
bytes
,
out
int
rlen
))
{
//处理失败,数据不够,继续接收
offset
=
bytes
;
}
else
{
break
;
}
}
}
_end
:
if
(!
IsConnected
)
{
Connect
(
false
);
sock
.
Close
();
if
(
IsRunning
)
{
IsRunning
=
false
;
Connect
();
}
return
false
;
}
else
...
...
Project.FLY.ModbusMapper/FLY.ModbusMapper/WithThread/ModbusMapper_Client.cs
View file @
064c0c51
...
...
@@ -28,8 +28,11 @@ namespace FLY.Modbus.WithThread
/// 工作中
/// </summary>
public
bool
IsRunning
{
get
;
private
set
;
}
/// <summary>
/// 异常次数
/// </summary>
public
int
ErrorCnt
{
get
;
private
set
;
}
class
RegWrite
{
public
PLCAddressArea
dataArea
;
...
...
@@ -58,8 +61,6 @@ namespace FLY.Modbus.WithThread
{
mclient
=
clienttcp
;
mclient
.
PropertyChanged
+=
Mclient_PropertyChanged
;
Start
();
}
...
...
@@ -90,35 +91,55 @@ namespace FLY.Modbus.WithThread
}
}
}
void
Start
()
public
void
Start
()
{
if
(!
mclient
.
IsRunning
)
{
mclient
.
Connect
();
}
else
{
if
(
IsRunning
)
return
;
IsRunning
=
true
;
Task
.
Factory
.
StartNew
(
OnPoll_update
);
}
}
/// <summary>
/// 停止
/// </summary>
public
void
Stop
()
{
if
(
IsRunning
)
if
(
!
IsRunning
)
return
;
Task
.
Factory
.
StartNew
(
OnPoll_update
);
mclient
.
Stop
(
);
}
void
OnPoll_update
()
{
IsRunning
=
true
;
Stopwatch
stopwatch
=
new
Stopwatch
();
stopwatch
.
Start
();
while
(
mclient
.
IsConnected
)
{
if
(
stopwatch
.
ElapsedMilliseconds
>=
UpdateInterval
)
{
//检查上次更新周期是否完成
ActUpdateInterval
=
stopwatch
.
Elapsed
;
TimeSpan
elapsed
=
stopwatch
.
Elapsed
;
ActUpdateInterval
=
elapsed
;
stopwatch
.
Restart
();
if
(!
UpdateReadData
())
return
;
//连接断开,终止更新线程
break
;
//连接断开,终止更新线程
}
//输出写入数据
if
(!
UpdateWriteData
())
return
;
//连接断开,终止更新线程
Thread
.
Sleep
(
0
);
break
;
//连接断开,终止更新线程
Thread
.
Sleep
(
1
0
);
}
IsRunning
=
false
;
ErrorCnt
++;
}
/// <summary>
...
...
@@ -132,11 +153,10 @@ namespace FLY.Modbus.WithThread
areaManager
.
MakePlanReal
();
}
int
curr_area_idx
=
0
;
while
(
true
)
//
int curr_area_idx = 0;
foreach
(
var
areaManager
in
mAreaManager
)
{
Plan
p_doing
=
mAreaManager
[
curr_area_idx
].
GetNextPlan
();
if
(
p_doing
!=
null
)
foreach
(
Plan
p_doing
in
areaManager
.
plan
)
{
switch
(
p_doing
.
area
)
{
...
...
@@ -156,17 +176,42 @@ namespace FLY.Modbus.WithThread
break
;
}
}
else
{
//读完
curr_area_idx
++;
if
(
curr_area_idx
>=
mAreaManager
.
Count
())
{
//读完一轮了
return
true
;
}
}
}
return
true
;
// while (true)
//{
// Plan p_doing = mAreaManager[curr_area_idx].GetNextPlan();
// if (p_doing != null)
// {
// switch (p_doing.area)
// {
// case PLCAddressArea.Coil:
// {
// if (!mclient.Do_01(p_doing.addr, p_doing.num, out IEnumerable<bool> values))
// return false;
// SetModbusData(PLCAddressArea.Coil, p_doing.addr, values);
// }
// break;
// case PLCAddressArea.Register:
// {
// if (!mclient.Do_03(p_doing.addr, p_doing.num, out IEnumerable<UInt16> values))
// return false;
// SetModbusData(PLCAddressArea.Register, p_doing.addr, values);
// }
// break;
// }
// }
// else
// {
// //读完
// curr_area_idx++;
// if (curr_area_idx >= mAreaManager.Count())
// {
// //读完一轮了
// return true;
// }
// }
//}
}
/// <summary>
...
...
@@ -404,6 +449,10 @@ namespace FLY.Modbus.WithThread
dr
.
isNeedUpdate
=
true
;
}
}
//foreach (DataToRegs dr in DRmap)
//{
// dr.isNeedUpdate = true;
//}
DRNeedUpdateCnt
=
DRmap
.
Count
((
dr
)
=>
dr
.
isNeedUpdate
);
foreach
(
var
areaManager
in
mAreaManager
)
...
...
Project.FLY.OBJComponents/OBJComponents/Server/PLCProxySystem.cs
View file @
064c0c51
...
...
@@ -69,6 +69,10 @@ namespace FLY.OBJComponents.Server
FObjBase
.
PollModule
.
Current
.
Poll_Config
(
FObjBase
.
PollModule
.
POLL_CONFIG
.
ADD
,
OnPoll_plans
,
TimeSpan
.
FromSeconds
(
1
));
//启动!!!!
foreach
(
var
plc
in
PLCs
)
plc
.
Start
();
}
private
void
Obj_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
...
...
Project.FLY.Weight/FLY.Weight.UI.Server/MainWindow.xaml
View file @
064c0c51
<Window x:Class="FLY.Weight.UI.Server.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" ResizeMode="NoResize" SizeToContent="WidthAndHeight" >
Title="MainWindow" ResizeMode="NoResize" SizeToContent="WidthAndHeight"
MinHeight="80" MinWidth="200"
>
<Grid>
<Grid x:Name="grid_plc"/>
<Grid x:Name="grid_plcos"/>
<Grid x:Name="grid_WeightSystem"/>
<StackPanel Orientation="Vertical" Margin="5">
<StackPanel Orientation="Horizontal" >
<ItemsControl x:Name="itemcontrol">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal" >
<StackPanel Orientation="Vertical" Margin="4" >
<TextBlock Text="更新速度" />
<TextBlock FontSize="20">
<Run Text="{Binding ActUpdateInterval,StringFormat=\{0:sfff\}, Mode=OneWay}" />
<Run Text="ms" FontSize="15"/>
</TextBlock>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" >
<TextBlock Text="PLC连接状态" />
<TextBlock Text="{Binding IsRunning}" FontSize="20"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" >
<TextBlock Text="异常次数" />
<TextBlock Text="{Binding ErrorCnt}" FontSize="20"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" >
<TextBlock Text="寄存器更新数" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DRNeedUpdateCnt}" FontSize="20"/>
<TextBlock Text="/"/>
<TextBlock Text="{Binding DRCnt}" FontSize="20"/>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!--<StackPanel Orientation="Horizontal" >
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}">
<TextBlock Text="更新速度" />
<TextBlock Text="{Binding ActUpdateInterval}" FontSize="20"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plcos}">
<TextBlock Text="PLC连接状态" />
<TextBlock Text="{Binding Is
ConnectedWithPLC
}" FontSize="20"/>
<TextBlock Text="{Binding Is
Running
}" FontSize="20"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="4" DataContext="{Binding DataContext,ElementName=grid_plc}">
<TextBlock Text="寄存器更新数" />
...
...
@@ -26,7 +58,7 @@
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
-->
</StackPanel>
</Grid>
...
...
Project.FLY.Weight/FLY.Weight.UI.Server/MainWindow.xaml.cs
View file @
064c0c51
...
...
@@ -40,12 +40,13 @@ namespace FLY.Weight.UI.Server
mTDGage
=
new
TDGage
(
"Gage1"
);
this
.
DataContext
=
mTDGage
.
mData
.
Items
[
0
];
//
this.DataContext = mTDGage.mData.Items[0];
FLY
.
OBJComponents
.
Server
.
PLCProxySystem
plsos
=
mTDGage
.
mData
.
PLCos
as
FLY
.
OBJComponents
.
Server
.
PLCProxySystem
;
grid_plcos
.
DataContext
=
plsos
;
grid_plc
.
DataContext
=
plsos
.
PLCs
[
0
];
grid_WeightSystem
.
DataContext
=
mTDGage
.
mData
;
//grid_plcos.DataContext = plsos;
//grid_plc.DataContext = plsos.PLCs[0];
//grid_WeightSystem.DataContext = mTDGage.mData;
this
.
itemcontrol
.
ItemsSource
=
plsos
.
PLCs
;
}
}
}
Project.FLY.Weight/FLY.Weight/Server/WeightSystem.cs
View file @
064c0c51
...
...
@@ -184,6 +184,7 @@ namespace FLY.Weight.Server
this
.
PropertyChanged
+=
WeightSystem_PropertyChanged
;
FObjBase
.
PollModule
.
Current
.
Poll_Config
(
PollModule
.
POLL_CONFIG
.
ADD
,
OnPoll_SaveMix
,
TimeSpan
.
FromSeconds
(
1
));
}
void
OnPoll_SaveMix
()
{
...
...
@@ -566,7 +567,14 @@ namespace FLY.Weight.Server
var
plc
=
new
Modbus
.
WithThread
.
ModbusMapper_Client
(
new
Modbus
.
WithThread
.
ClientTCP
(
device
.
EP
));
plcos
.
PLCs
.
Add
(
plc
);
}
//测试---
//只加载第1个
{
//var plc = new Modbus.WithThread.ModbusMapper_Client(new Modbus.WithThread.ClientTCP(plcgroup.Devices[1].EP));
//plcos.PLCs.Add(plc);
//plc = new Modbus.WithThread.ModbusMapper_Client(new Modbus.WithThread.ClientTCP(plcgroup.Devices[1].EP));
//plcos.PLCs.Add(plc);
}
List
<
int
>
bincnts
=
new
List
<
int
>();
Regex
r
=
new
Regex
(
@"Items\[([0-9])\]"
);
Regex
r2
=
new
Regex
(
"MixPSet_([1-9])"
);
...
...
@@ -631,6 +639,9 @@ namespace FLY.Weight.Server
foreach
(
var
plc
in
plcos
.
PLCs
)
plc
.
Build
();
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
...
...
Project.FLY.Winder/FLY.Winder/Server/WinderSystem.cs
View file @
064c0c51
...
...
@@ -65,6 +65,7 @@ namespace FLY.Winder.Server
InitError
();
plcos
.
Init
();
}
#
region
报警
class
ErrorAction
...
...
Resource/称重/设备连接变量表_341/Generated/WS_local_test.xml
0 → 100644
View file @
064c0c51
This diff is collapsed.
Click to expand it.
Resource/称重/设备连接变量表_341/Generated/cp_ws_local_test.ps1
0 → 100644
View file @
064c0c51
$root_path
=
$PSScriptRoot
$src_path
=
$root_path
+
"\WS_local_test.xml"
$dest_dir
=
$root_path
+
"\..\..\..\..\Project.FLY.Weight\FLY.Weight.UI.Server\bin\Debug\Gage1"
$dest_path
=
$dest_dir
+
"\WS.xml"
if
(
-not
(
Test-Path
$dest_dir
))
{
echo
$dest_dir
mkdir
$dest_dir
}
echo
WS.xml
cp
$src_path
$dest_path
echo
Ƴɹ
pause
\ No newline at end of file
风环PLC/PLC/PLC_V3_20190108/地址表.xlsx
View file @
064c0c51
No preview for this file type
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