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
26d99f02
Commit
26d99f02
authored
Aug 01, 2022
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化 AD盒模拟器,吹膜的PLC模拟器 使用 V3接口
parent
87d5e93d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
372 additions
and
31 deletions
+372
-31
Blowing.cs
Project.FLY.FlyADBase/FLY.Simulation.Blowing/Blowing.cs
+30
-5
FLY.Simulation.Blowing.csproj
...Base/FLY.Simulation.Blowing/FLY.Simulation.Blowing.csproj
+6
-0
HMI.cs
Project.FLY.FlyADBase/FLY.Simulation.Blowing/HMI.cs
+68
-21
IPlcLink.cs
Project.FLY.FlyADBase/FLY.Simulation.Blowing/IPlcLink.cs
+30
-0
PlcLink.cs
Project.FLY.FlyADBase/FLY.Simulation.Blowing/PlcLink.cs
+210
-0
MainWindow.xaml.cs
...ct.FLY.FlyADBase/FLYAD7_Simulation_Wpf/MainWindow.xaml.cs
+7
-2
WindowBlowing.xaml
...ct.FLY.FlyADBase/FLYAD7_Simulation_Wpf/WindowBlowing.xaml
+6
-0
WindowBlowing.xaml.cs
...FLY.FlyADBase/FLYAD7_Simulation_Wpf/WindowBlowing.xaml.cs
+15
-3
No files found.
Project.FLY.FlyADBase/FLY.Simulation.Blowing/Blowing.cs
View file @
26d99f02
...
...
@@ -162,7 +162,8 @@ namespace FLY.Simulation.Blowing
/// </summary>
public
double
CurrFilmVelocity
{
get
;
private
set
;
}
#
endregion
public
HMI
mHMI
;
public
IPlcLink
plcLink
;
public
int
Avg
{
get
;
set
;
}
public
double
[]
mFilmLength3D
;
...
...
@@ -267,16 +268,21 @@ namespace FLY.Simulation.Blowing
mAirRing2
.
AfterDatasUpdateEvent
+=
new
Action
<
ObservableCollection
<
int
>>(
mAirRing2_AfterDatasUpdateEvent
);
Avg
=
(
int
)(
BeforeDatas
.
Average
());
//原始平均值
mAirRing2
.
Bads
[
2
]
=
true
;
mAirRing2
.
Bads
[
30
]
=
true
;
mAirRing2
.
Bads
[
31
]
=
true
;
TestPos
=
500
;
UpdateTestHeat
();
//AfterDatas.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(AfterDatas_CollectionChanged);
PropertyChanged
+=
new
PropertyChangedEventHandler
(
Blowing_PropertyChanged
);
mHMI
=
new
HMI
();
mHMI
.
mAirRing
=
mAirRing2
;
//plcLink = new HMI();
//plcLink.Init(mAirRing2);
var
plc
=
new
PlcLink
();
plc
.
Init
(
mAirRing2
);
plcLink
=
plc
;
Is360
=
false
;
...
...
@@ -317,6 +323,12 @@ namespace FLY.Simulation.Blowing
/// 加热量, 数据量为 ChannelCnt
/// </summary>
public
int
[]
Heats
;
/// <summary>
/// 坏的加热棒
/// </summary>
public
bool
[]
Bads
;
public
bool
HasElectricCurrent
;
/// <summary>
/// 第1个加热棒,对应的 数据序号, 数据量为 1000, BeforeData.Count
/// </summary>
...
...
@@ -375,11 +387,24 @@ namespace FLY.Simulation.Blowing
{
ChannelCnt
=
channelcnt
;
Heats
=
new
int
[
ChannelCnt
];
Bads
=
new
bool
[
ChannelCnt
];
Array
.
Clear
(
Heats
,
0
,
ChannelCnt
);
}
public
event
Action
<
ObservableCollection
<
int
>>
AfterDatasUpdateEvent
;
public
void
HeatApply
()
{
bool
current
=
false
;
for
(
int
i
=
0
;
i
<
ChannelCnt
;
i
++)
{
if
((
Bads
[
i
]
==
false
)
&&
(
Heats
[
i
]
>
0
))
{
current
=
true
;
break
;
}
}
HasElectricCurrent
=
current
;
int
boltcnt
=
BeforeDatas
.
Count
();
double
b_c
=
(
double
)(
boltcnt
)/
ChannelCnt
;
int
b
=
Channel1stIndex
;
...
...
Project.FLY.FlyADBase/FLY.Simulation.Blowing/FLY.Simulation.Blowing.csproj
View file @
26d99f02
...
...
@@ -47,7 +47,9 @@
<Compile
Include=
"FilmLength3D.cs"
/>
<Compile
Include=
"GageAD.cs"
/>
<Compile
Include=
"HMI.cs"
/>
<Compile
Include=
"IPlcLink.cs"
/>
<Compile
Include=
"OrgData.cs"
/>
<Compile
Include=
"PlcLink.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
...
...
@@ -59,6 +61,10 @@
<Project>
{5EE61AC6-5269-4F0F-B8FA-4334FE4A678F}
</Project>
<Name>
Misc
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\..\Project.FLY.ModbusMapper\FLY.ModbusMapper\FLY.ModbusMapper.csproj"
>
<Project>
{6d4b9bda-2a66-4583-b244-758bc4213d9f}
</Project>
<Name>
FLY.ModbusMapper
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\..\Project.FLY.ModbusModule\FLY.ModbusModule\FLY.ModbusModule.csproj"
>
<Project>
{8e19c40f-ce7f-4982-bd90-4eb4e9e04e34}
</Project>
<Name>
FLY.ModbusModule
</Name>
...
...
Project.FLY.FlyADBase/FLY.Simulation.Blowing/HMI.cs
View file @
26d99f02
...
...
@@ -4,10 +4,11 @@ using System.Linq;
using
System.Text
;
using
System.ComponentModel
;
using
System.Net
;
using
System.IO
;
namespace
FLY.Simulation.Blowing
{
public
class
HMI
:
INotifyPropertyChanged
public
class
HMI
:
IPlcLink
{
const
int
ADDR_M_HasElectricCurrent
=
0
;
//bit 三相电 电流
const
int
ADDR_M_HasFan
=
1
;
//bit 风机启动
...
...
@@ -33,12 +34,12 @@ namespace FLY.Simulation.Blowing
/// 风机是否启动?
/// </summary>
public
bool
HasFan
{
get
;
set
;
}
=
true
;
public
string
PlcAddr
{
get
;
set
;
}
=
"127.0.0.1"
;
UInt16
heatupdate
=
1
;
UInt16
currupdate
=
1
;
UInt16
heatupdate_last
=
1
;
UInt16
[]
heats
;
bool
[]
Bads
;
public
Blowing
.
AirRing
mAirRing
;
FLY
.
ModbusModule
.
ClientTCP
mbclient
;
...
...
@@ -46,26 +47,34 @@ namespace FLY.Simulation.Blowing
public
HMI
()
{
mbclient
=
new
FLY
.
ModbusModule
.
ClientTCP
(
IPAddress
.
Parse
(
"127.0.0.1"
));
if
(!
Load
())
Save
();
heats
=
new
UInt16
[
100
];
Bads
=
new
bool
[
100
];
Array
.
Clear
(
heats
,
0
,
100
);
Array
.
Clear
(
Bads
,
0
,
100
);
Bads
[
2
]
=
true
;
Bads
[
30
]
=
true
;
heatupdate
=
1
;
heatupdate_last
=
1
;
currupdate
=
1
;
mbclient
.
PropertyChanged
+=
new
PropertyChangedEventHandler
(
mbclient_PropertyChanged
);
//每1秒读取一次
FObjBase
.
PollModule
.
Current
.
Poll_Config
(
FObjBase
.
PollModule
.
POLL_CONFIG
.
ADD
,
new
FObjBase
.
PollModule
.
PollHandler
(
OnPoll
),
TimeSpan
.
FromMilliseconds
(
200
)
);
}
public
void
Init
(
Blowing
.
AirRing
mAirRing
)
{
this
.
mAirRing
=
mAirRing
;
mbclient
=
new
FLY
.
ModbusModule
.
ClientTCP
(
IPAddress
.
Parse
(
PlcAddr
));
mbclient
.
PropertyChanged
+=
new
PropertyChangedEventHandler
(
mbclient_PropertyChanged
);
//每1秒读取一次
FObjBase
.
PollModule
.
Current
.
Poll_Config
(
FObjBase
.
PollModule
.
POLL_CONFIG
.
ADD
,
new
FObjBase
.
PollModule
.
PollHandler
(
OnPoll
),
TimeSpan
.
FromMilliseconds
(
200
));
}
void
mbclient_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
e
.
PropertyName
==
"IsConnected"
)
...
...
@@ -134,23 +143,61 @@ namespace FLY.Simulation.Blowing
mAirRing
.
HeatApply
();
SendHeats
();
bool
current
=
false
;
for
(
int
i
=
0
;
i
<
mAirRing
.
ChannelCnt
;
i
++)
{
if
(
(
Bads
[
i
]==
false
)
&&
(
mAirRing
.
Heats
[
i
]>
0
))
{
current
=
true
;
break
;
}
}
HasElectricCurrent
=
current
;
HasElectricCurrent
=
mAirRing
.
HasElectricCurrent
;
CurrUpdate
++;
SendUpdate
();
}
SendStatue
();
}
string
filePath
=
"airRingPlc.json"
;
bool
Load
()
{
return
HmiJsonDb
.
Load
(
filePath
,
this
);
}
public
bool
Save
()
{
return
HmiJsonDb
.
Save
(
filePath
,
this
);
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
}
public
class
HmiJsonDb
{
public
string
PlcAddr
=
"127.0.0.1"
;
public
static
bool
Save
(
string
filePath
,
HMI
plcLink
)
{
try
{
HmiJsonDb
jsondb
=
new
HmiJsonDb
()
{
PlcAddr
=
plcLink
.
PlcAddr
};
string
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
jsondb
,
Newtonsoft
.
Json
.
Formatting
.
Indented
);
File
.
WriteAllText
(
filePath
,
json
);
return
true
;
}
catch
{
return
false
;
}
}
public
static
bool
Load
(
string
filePath
,
HMI
plcLink
)
{
try
{
if
(!
File
.
Exists
(
filePath
))
return
false
;
string
json
=
File
.
ReadAllText
(
filePath
);
var
jsonDb
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
HmiJsonDb
>(
json
);
plcLink
.
PlcAddr
=
jsonDb
.
PlcAddr
;
return
true
;
}
catch
{
return
false
;
}
}
}
}
Project.FLY.FlyADBase/FLY.Simulation.Blowing/IPlcLink.cs
0 → 100644
View file @
26d99f02
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
FLY.Simulation.Blowing
{
public
interface
IPlcLink
:
INotifyPropertyChanged
{
string
PlcAddr
{
get
;
set
;
}
/// <summary>
/// 当前电流 有没?
/// </summary>
bool
HasElectricCurrent
{
get
;
set
;
}
/// <summary>
/// 风机是否启动?
/// </summary>
bool
HasFan
{
get
;
set
;
}
UInt16
HeatUpdate
{
get
;
set
;
}
bool
Save
();
}
}
Project.FLY.FlyADBase/FLY.Simulation.Blowing/PlcLink.cs
0 → 100644
View file @
26d99f02
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
FLY.Simulation.Blowing
{
public
class
PlcLink
:
IPlcLink
{
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
string
PlcAddr
{
get
;
set
;
}
=
"127.168.50.60:502"
;
//D200 4x201 通道数量
//D201 4x202 设置值 更新
//D202 4x203 当前值 更新 //不用
//D400 4x401 设置值 160个
//D600 4x601 当前值 160个 //不用
//M3 0x4 风环开关
//M4 0x5 检测电流
public
FLY
.
Modbus
.
WithThread
.
ServerTCP
mserver
;
public
Blowing
.
AirRing
mAirRing
;
public
UInt16
HeatUpdate
{
get
;
set
;
}
/// <summary>
/// 当前电流 有没?
/// </summary>
public
bool
HasElectricCurrent
{
get
;
set
;
}
/// <summary>
/// 风机是否启动?
/// </summary>
public
bool
HasFan
{
get
;
set
;
}
=
true
;
public
PlcLink
()
{
if
(!
Load
())
Save
();
}
public
void
Init
(
Blowing
.
AirRing
mAirRing
)
{
this
.
mAirRing
=
mAirRing
;
mserver
=
new
Modbus
.
WithThread
.
ServerTCP
(
Misc
.
StringConverter
.
ToIPEndPoint
(
PlcAddr
),
GetValue
,
SetValue
);
mserver
.
Start
();
}
void
GetValue
(
int
addr
,
object
values
)
{
if
(
values
is
UInt16
[])
{
var
uint16s
=
values
as
UInt16
[];
for
(
int
i
=
0
;
i
<
uint16s
.
Count
();
i
++)
{
uint16s
[
i
]
=
GetValue_reg
(
i
+
addr
);
}
}
else
if
(
values
is
bool
[])
{
var
bools
=
values
as
bool
[];
for
(
int
i
=
0
;
i
<
bools
.
Count
();
i
++)
{
bools
[
i
]
=
GetValue_coil
(
i
+
addr
);
}
}
}
UInt16
GetValue_reg
(
int
addr
)
{
if
(
addr
==
200
)
{
return
(
UInt16
)
mAirRing
.
ChannelCnt
;
}
else
if
(
addr
==
201
)
{
return
HeatUpdate
;
}
else
if
(
addr
>=
400
&&
addr
<
400
+
160
)
{
int
idx
=
addr
-
400
;
if
(
idx
>=
0
&&
idx
<
mAirRing
.
Heats
.
Count
())
return
(
UInt16
)
mAirRing
.
Heats
[
idx
];
else
return
0
;
}
else
{
return
0
;
}
}
bool
GetValue_coil
(
int
addr
)
{
if
(
addr
==
3
)
{
return
HasFan
;
}
else
if
(
addr
==
4
)
{
return
HasElectricCurrent
;
}
else
{
return
false
;
}
}
void
SetValue
(
int
addr
,
object
values
)
{
if
(
values
is
UInt16
[])
{
var
uint16s
=
values
as
UInt16
[];
for
(
int
i
=
0
;
i
<
uint16s
.
Count
();
i
++)
{
SetValue_reg
(
i
+
addr
,
uint16s
[
i
]);
}
}
else
if
(
values
is
bool
[])
{
var
bools
=
values
as
bool
[];
for
(
int
i
=
0
;
i
<
bools
.
Count
();
i
++)
{
SetValue_coil
(
i
+
addr
,
bools
[
i
]);
}
}
}
void
SetValue_reg
(
int
addr
,
UInt16
reg
)
{
if
(
addr
==
200
)
{
mAirRing
.
SetChannelCnt
(
reg
);
}
else
if
(
addr
==
201
)
{
if
(
HeatUpdate
!=
reg
)
{
HeatUpdate
=
reg
;
mAirRing
.
HeatApply
();
HasElectricCurrent
=
mAirRing
.
HasElectricCurrent
;
}
}
else
if
(
addr
>=
400
&&
addr
<
400
+
160
)
{
int
idx
=
addr
-
400
;
if
(
idx
>=
0
&&
idx
<
mAirRing
.
Heats
.
Count
())
{
mAirRing
.
Heats
[
idx
]
=
reg
;
}
}
else
{
}
}
void
SetValue_coil
(
int
addr
,
bool
coil
)
{
}
string
filePath
=
"airRingPlc.json"
;
bool
Load
()
{
return
PlcLinkJsonDb
.
Load
(
filePath
,
this
);
}
public
bool
Save
()
{
return
PlcLinkJsonDb
.
Save
(
filePath
,
this
);
}
}
public
class
PlcLinkJsonDb
{
public
string
PlcAddr
=
"127.168.50.60:502"
;
public
static
bool
Save
(
string
filePath
,
PlcLink
plcLink
)
{
try
{
PlcLinkJsonDb
jsondb
=
new
PlcLinkJsonDb
()
{
PlcAddr
=
plcLink
.
PlcAddr
};
string
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
jsondb
,
Newtonsoft
.
Json
.
Formatting
.
Indented
);
File
.
WriteAllText
(
filePath
,
json
);
return
true
;
}
catch
{
return
false
;
}
}
public
static
bool
Load
(
string
filePath
,
PlcLink
plcLink
)
{
try
{
if
(!
File
.
Exists
(
filePath
))
return
false
;
string
json
=
File
.
ReadAllText
(
filePath
);
var
jsonDb
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
PlcLinkJsonDb
>(
json
);
plcLink
.
PlcAddr
=
jsonDb
.
PlcAddr
;
return
true
;
}
catch
{
return
false
;
}
}
}
}
Project.FLY.FlyADBase/FLYAD7_Simulation_Wpf/MainWindow.xaml.cs
View file @
26d99f02
...
...
@@ -151,8 +151,13 @@ namespace FLYAD7_Simulation_Wpf
private
void
button2_Click
(
object
sender
,
RoutedEventArgs
e
)
{
flyad7
.
Save
();
MessageBox
.
Show
(
"保存成功,请重启"
);
if
(
MessageBox
.
Show
(
"需要重启,才能生效"
,
"提示"
,
MessageBoxButton
.
OKCancel
)
==
MessageBoxResult
.
OK
)
{
flyad7
.
Save
();
FLY
.
AppHelper
.
AppJustOne
.
Restart
();
}
}
private
void
button3_Click
(
object
sender
,
RoutedEventArgs
e
)
...
...
Project.FLY.FlyADBase/FLYAD7_Simulation_Wpf/WindowBlowing.xaml
View file @
26d99f02
...
...
@@ -86,10 +86,16 @@
<GroupBox Header="电柜" Margin="2" >
<StackPanel >
<StackPanel x:Name="spPlc">
<StackPanel>
<TextBlock Text="PLC地址"/>
<TextBox Text="{Binding PlcAddr}"/>
</StackPanel>
<CheckBox Content="电流计" Height="16" Margin="5" IsChecked="{Binding HasElectricCurrent}" IsEnabled="False"/>
<CheckBox Content="风机开" Height="16" Margin="5" IsChecked="{Binding HasFan}" />
<Button Content="保存PLC设置" Padding="5,2" Click="btnPlcSaveClick"/>
</StackPanel>
<CheckBox Content="屏蔽I9" Height="16" Margin="5" IsChecked="{Binding IsShieldI9}" />
</StackPanel>
</GroupBox>
</StackPanel>
...
...
Project.FLY.FlyADBase/FLYAD7_Simulation_Wpf/WindowBlowing.xaml.cs
View file @
26d99f02
...
...
@@ -147,7 +147,7 @@ namespace FLYAD7_Simulation_Wpf
private
void
Window_Loaded
(
object
sender
,
RoutedEventArgs
e
)
{
this
.
DataContext
=
mBlowing
;
this
.
spPlc
.
DataContext
=
mBlowing
.
mHMI
;
this
.
spPlc
.
DataContext
=
mBlowing
.
plcLink
;
mBlowing
.
PropertyChanged
+=
new
System
.
ComponentModel
.
PropertyChangedEventHandler
(
mBlowing_PropertyChanged
);
DataBindAll
();
chart1
.
ChartAreas
[
"Default"
].
CursorX
.
Position
=
mBlowing
.
TestPos
;
...
...
@@ -222,8 +222,20 @@ namespace FLYAD7_Simulation_Wpf
private
void
btnSaveClick
(
object
sender
,
RoutedEventArgs
e
)
{
mBlowing
.
Save
();
MessageBox
.
Show
(
"已经保存数据,请重启"
);
if
(
MessageBox
.
Show
(
"需要重启,才能生效"
,
"提示"
,
MessageBoxButton
.
OKCancel
)
==
MessageBoxResult
.
OK
)
{
mBlowing
.
Save
();
FLY
.
AppHelper
.
AppJustOne
.
Restart
();
}
}
private
void
btnPlcSaveClick
(
object
sender
,
RoutedEventArgs
e
)
{
if
(
MessageBox
.
Show
(
"需要重启,才能生效"
,
"提示"
,
MessageBoxButton
.
OKCancel
)
==
MessageBoxResult
.
OK
)
{
mBlowing
.
plcLink
.
Save
();
FLY
.
AppHelper
.
AppJustOne
.
Restart
();
}
}
}
}
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