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
e1da2583
Commit
e1da2583
authored
Feb 21, 2022
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 AD盒模拟器,添加流延的自动模头PLC模拟,这个模拟器只是modbusTCP通讯而已,无法调节厚度
parent
f445c84c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
434 additions
and
2 deletions
+434
-2
AutoDie.cs
Project.FLY.FlyADBase/FLY.Simulation.Casting/AutoDie.cs
+149
-0
FLY.Simulation.Casting.csproj
...Base/FLY.Simulation.Casting/FLY.Simulation.Casting.csproj
+6
-0
GageAD.cs
Project.FLY.FlyADBase/FLY.Simulation.Casting/GageAD.cs
+9
-2
PlcLink.cs
Project.FLY.FlyADBase/FLY.Simulation.Casting/PlcLink.cs
+256
-0
FlyADBase.sln
Project.FLY.FlyADBase/FlyADBase.sln
+14
-0
No files found.
Project.FLY.FlyADBase/FLY.Simulation.Casting/AutoDie.cs
0 → 100644
View file @
e1da2583
using
System
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
FLY.Simulation.Casting
{
public
class
AutoDie
{
/// <summary>
/// 加热通过
/// </summary>
public
int
ChannelCnt
;
/// <summary>
/// 加热量, 数据量为 ChannelCnt
/// </summary>
public
int
[]
Heats
;
/// <summary>
/// 第1个加热棒,对应的 数据序号, 数据量为 1000, BeforeData.Count
/// </summary>
public
int
Channel1stIndex
;
/// <summary>
/// 加热 对 厚度的影响
/// </summary>
public
double
Factor
;
//需要别人赋值
/// <summary>
/// 原始数据!! 数据量为1000
/// </summary>
public
ObservableCollection
<
int
>
BeforeDatas
;
/// <summary>
/// 加热后的数据!!!! 数据量为BeforeDatas.Count
/// </summary>
public
ObservableCollection
<
int
>
AfterDatas
;
double
[]
p
;
// 一个凸起来的数组 0 1 4 9 16 9 4 1 0
void
p_init
()
{
int
size
=
ChannelCnt
/
10
;
p
=
new
double
[
size
];
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
int
index1
=
i
;
int
index2
=
size
-
1
-
i
;
double
d
=
i
*
i
;
p
[
index1
]
=
d
;
p
[
index2
]
=
d
;
if
(
Math
.
Abs
(
index2
-
index1
)
<=
1
)
break
;
}
double
sum_p
=
p
.
Max
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
p
[
i
]
=
p
[
i
]
/
sum_p
;
}
}
public
AutoDie
(
int
channelcnt
)
{
SetChannelCnt
(
channelcnt
);
p_init
();
Factor
=
5
;
}
public
void
Init
(
ObservableCollection
<
int
>
before_datas
,
ObservableCollection
<
int
>
after_datas
,
int
channel1stIndex
)
{
BeforeDatas
=
before_datas
;
AfterDatas
=
after_datas
;
Channel1stIndex
=
channel1stIndex
;
}
public
void
SetChannelCnt
(
int
channelcnt
)
{
ChannelCnt
=
channelcnt
;
Heats
=
new
int
[
ChannelCnt
];
Array
.
Clear
(
Heats
,
0
,
ChannelCnt
);
}
public
event
Action
<
ObservableCollection
<
int
>>
AfterDatasUpdateEvent
;
public
void
HeatApply
()
{
int
boltcnt
=
BeforeDatas
.
Count
();
double
b_c
=
(
double
)(
boltcnt
)
/
ChannelCnt
;
int
b
=
Channel1stIndex
;
double
beforeavg
=
BeforeDatas
.
Average
();
int
[]
datas
=
new
int
[
boltcnt
];
for
(
int
i
=
0
;
i
<
ChannelCnt
;
i
++)
{
int
heat
=
Heats
[
i
];
int
e
=
(
int
)((
i
+
1
)
*
b_c
)
+
Channel1stIndex
;
if
(
e
>=
boltcnt
)
e
-=
boltcnt
;
else
if
(
e
<
0
)
e
+=
boltcnt
;
int
j
=
b
;
while
(
j
!=
e
)
{
datas
[
j
]
=
(
int
)(
BeforeDatas
[
j
]
-
beforeavg
*
heat
/
Factor
/
100
);
j
++;
if
(
j
>=
boltcnt
)
j
-=
boltcnt
;
}
b
=
e
;
}
double
afteravg
=
datas
.
Average
();
for
(
int
j
=
0
;
j
<
boltcnt
;
j
++)
{
AfterDatas
[
j
]
=
(
int
)(
beforeavg
*
datas
[
j
]
/
afteravg
);
}
if
(
AfterDatasUpdateEvent
!=
null
)
{
AfterDatasUpdateEvent
(
AfterDatas
);
}
}
public
void
Test
(
int
idx
,
int
offset
)
{
idx
-=
p
.
Count
()
/
2
;
if
(
idx
<
0
)
idx
+=
ChannelCnt
;
else
if
(
idx
>=
ChannelCnt
)
idx
-=
ChannelCnt
;
for
(
int
i
=
0
;
i
<
p
.
Count
();
i
++)
{
int
index
=
idx
+
i
;
if
(
index
<
0
)
index
+=
ChannelCnt
;
else
if
(
index
>=
ChannelCnt
)
index
-=
ChannelCnt
;
int
heat
=
Heats
[
index
]
+
(
int
)(
offset
*
p
[
i
]);
if
(
heat
>
100
)
heat
=
100
;
else
if
(
heat
<
0
)
heat
=
0
;
Heats
[
index
]
=
heat
;
}
HeatApply
();
}
}
}
Project.FLY.FlyADBase/FLY.Simulation.Casting/FLY.Simulation.Casting.csproj
View file @
e1da2583
...
...
@@ -43,7 +43,9 @@
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"AutoDie.cs"
/>
<Compile
Include=
"GageAD.cs"
/>
<Compile
Include=
"PlcLink.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
...
...
@@ -51,6 +53,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=
"..\FLY.Simulation\FLY.Simulation.csproj"
>
<Project>
{150F2411-FE62-4042-A968-33E416DC56A1}
</Project>
<Name>
FLY.Simulation
</Name>
...
...
Project.FLY.FlyADBase/FLY.Simulation.Casting/GageAD.cs
View file @
e1da2583
...
...
@@ -47,11 +47,17 @@ namespace FLY.Simulation.Casting
/// 机架总长 mm
/// </summary>
public
int
TotalLength
{
get
;
set
;
}
=
3000
;
PlcLink
plcLink
;
Random
random
;
public
GageAD
()
{
curve
=
new
CurveCollection
();
plcLink
=
new
PlcLink
();
plcLink
.
Init
();
Load
();
random
=
new
Random
();
}
public
int
GetAD
(
int
mm
)
...
...
@@ -61,6 +67,7 @@ namespace FLY.Simulation.Casting
else
if
(
mm
>=
datas_horizontal
.
Count
())
mm
=
datas_horizontal
.
Count
()
-
1
;
int
ad
=
datas_horizontal
[
mm
];
ad
+=
(
int
)(
ad
*
(
random
.
NextDouble
()
*
0.01
-
0.005
));
return
ad
;
}
...
...
Project.FLY.FlyADBase/FLY.Simulation.Casting/PlcLink.cs
0 → 100644
View file @
e1da2583
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.ComponentModel
;
using
System.Net
;
using
System.IO
;
namespace
FLY.Simulation.Casting
{
public
class
PlcLink
:
INotifyPropertyChanged
{
//D200 4x201 通道数量
//D201 4x202 设置值 更新
//D202 4x203 当前值 更新 //不用
//D400 4x401 设置值 160个
//D600 4x601 当前值 160个 //不用
//M3 0x4 风环开关
//M4 0x5 检测电流
const
int
ADDR_M_HasElectricity
=
3
;
//检测电流
const
int
ADDR_M_HasFan
=
4
;
//风环开关
const
int
ADDR_D_ChannelCnt
=
200
;
const
int
ADDR_D_HeatUpdate
=
201
;
const
int
ADDR_D_CurrentUpdate
=
202
;
const
UInt16
ADDR_D_Heats
=
400
;
const
UInt16
ADDR_D_Currents
=
600
;
/// <summary>
/// 加热通道数
/// </summary>
public
UInt16
ChannelCnt
{
get
;
set
;
}
/// <summary>
/// 加热量更新
/// </summary>
public
UInt16
HeatUpdate
{
get
;
set
;
}
/// <summary>
/// 当前量更新
/// </summary>
public
UInt16
CurrentUpdate
{
get
;
set
;
}
/// <summary>
/// 当前电流 有没?
/// </summary>
public
bool
HasElectricity
{
get
;
set
;
}
/// <summary>
/// 风机是否启动?
/// </summary>
public
bool
HasFan
{
get
;
set
;
}
=
true
;
UInt16
heatupdate_last
=
1
;
UInt16
[]
heats
;
bool
[]
Bads
;
AutoDie
mAutoDie
;
FLY
.
Modbus
.
WithThread
.
ServerTCP
mbServer
;
public
PlcLink
()
{
heats
=
new
UInt16
[
160
];
Bads
=
new
bool
[
160
];
Bads
[
2
]
=
true
;
Bads
[
30
]
=
true
;
HeatUpdate
=
1
;
heatupdate_last
=
1
;
CurrentUpdate
=
1
;
}
public
void
Init
()
{
//this.mAutoDie = autoDie;
PlcLinkJsonDb
plcLink
=
new
PlcLinkJsonDb
();
ChannelCnt
=
100
;
// (UInt16)mAutoDie.ChannelCnt;
mbServer
=
new
Modbus
.
WithThread
.
ServerTCP
(
Misc
.
StringConverter
.
ToIPEndPoint
(
plcLink
.
Addr
),
GetValue
,
SetValue
);
mbServer
.
Start
();
this
.
PropertyChanged
+=
PlcLink_PropertyChanged
;
}
private
void
PlcLink_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
e
.
PropertyName
==
nameof
(
ChannelCnt
))
{
//mAutoDie.SetChannelCnt(ChannelCnt);
}
}
void
GetValue
(
int
addr
,
object
values
)
{
if
(
values
is
bool
[])
GetValue_M
(
addr
,
(
bool
[])
values
);
else
GetValue_D
(
addr
,
(
UInt16
[])
values
);
}
void
SetValue
(
int
addr
,
object
values
)
{
if
(
values
is
bool
[])
SetValue_M
(
addr
,
(
bool
[])
values
);
else
SetValue_D
(
addr
,
(
UInt16
[])
values
);
}
void
GetValue_M
(
int
addr
,
bool
[]
values
)
{
for
(
int
i
=
0
;
i
<
values
.
Count
();
i
++)
{
int
single_addr
=
addr
+
i
;
switch
(
single_addr
)
{
case
ADDR_M_HasElectricity
:
{
values
[
i
]
=
HasElectricity
;
}
break
;
case
ADDR_M_HasFan
:
{
values
[
i
]
=
HasFan
;
}
break
;
}
}
}
void
GetValue_D
(
int
addr
,
UInt16
[]
values
)
{
for
(
int
i
=
0
;
i
<
values
.
Count
();
i
++)
{
int
single_addr
=
addr
+
i
;
if
(
single_addr
==
ADDR_D_ChannelCnt
)
{
values
[
i
]
=
ChannelCnt
;
}
else
if
(
single_addr
==
ADDR_D_HeatUpdate
)
{
values
[
i
]
=
HeatUpdate
;
}
else
if
(
single_addr
==
ADDR_D_CurrentUpdate
)
{
values
[
i
]
=
CurrentUpdate
;
}
else
if
(
single_addr
>=
ADDR_D_Heats
&&
single_addr
<
ADDR_D_Heats
+
160
)
{
int
index
=
single_addr
-
ADDR_D_Heats
;
values
[
i
]
=
heats
[
index
];
}
else
if
(
single_addr
>=
ADDR_D_Currents
&&
single_addr
<
ADDR_D_Currents
+
160
)
{
int
index
=
single_addr
-
ADDR_D_Currents
;
values
[
i
]
=
heats
[
index
];
//if (index < mAutoDie.Heats.Count())
//{
// values[i] = (UInt16)mAutoDie.Heats[index];
//}
}
}
}
void
SetValue_M
(
int
addr
,
bool
[]
values
)
{
}
void
SetValue_D
(
int
addr
,
UInt16
[]
values
)
{
for
(
int
i
=
0
;
i
<
values
.
Count
();
i
++)
{
int
single_addr
=
addr
+
i
;
if
(
single_addr
==
ADDR_D_ChannelCnt
)
{
ChannelCnt
=
values
[
i
];
}
else
if
(
single_addr
==
ADDR_D_HeatUpdate
)
{
HeatUpdate
=
values
[
i
];
if
(
HeatUpdate
!=
heatupdate_last
)
{
heatupdate_last
=
HeatUpdate
;
//for (int j = 0; j < ChannelCnt; j++) {
// mAutoDie.Heats[j] = heats[j];
//}
//mAutoDie.HeatApply();
if
(
heats
.
Take
(
ChannelCnt
).
Any
(
h
=>
h
>
0
))
HasElectricity
=
true
;
else
HasElectricity
=
false
;
}
CurrentUpdate
++;
}
else
if
(
single_addr
==
ADDR_D_CurrentUpdate
)
{
CurrentUpdate
=
values
[
i
];
}
else
if
(
single_addr
>=
ADDR_D_Heats
&&
single_addr
<
ADDR_D_Heats
+
160
)
{
int
index
=
single_addr
-
ADDR_D_Heats
;
heats
[
index
]
=
values
[
i
];
}
}
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
}
public
class
PlcLinkJsonDb
{
public
string
Addr
=
"0.0.0.0:502"
;
private
string
filePath
=
"plclink.json"
;
public
bool
Save
()
{
try
{
string
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
this
);
File
.
WriteAllText
(
filePath
,
json
);
return
true
;
}
catch
{
return
false
;
}
}
public
bool
Load
()
{
if
(!
File
.
Exists
(
filePath
))
{
return
false
;
}
try
{
string
json
=
File
.
ReadAllText
(
filePath
);
Newtonsoft
.
Json
.
JsonConvert
.
PopulateObject
(
json
,
this
);
return
true
;
}
catch
{
return
false
;
}
}
}
}
Project.FLY.FlyADBase/FlyADBase.sln
View file @
e1da2583
...
...
@@ -44,6 +44,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FLY.Simulation.Calender.GuR
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FLY.Simulation.Calender.GuRuiShiYe.UI", "FLY.Simulation.Calender.GuRuiShiYe.UI\FLY.Simulation.Calender.GuRuiShiYe.UI.csproj", "{517847E4-5708-4ACE-BDF0-BB2C4495136D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FLY.ModbusMapper", "..\Project.FLY.ModbusMapper\FLY.ModbusMapper\FLY.ModbusMapper.csproj", "{6D4B9BDA-2A66-4583-B244-758BC4213D9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -242,6 +244,18 @@ Global
{517847E4-5708-4ACE-BDF0-BB2C4495136D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{517847E4-5708-4ACE-BDF0-BB2C4495136D}.Release|x86.ActiveCfg = Release|Any CPU
{517847E4-5708-4ACE-BDF0-BB2C4495136D}.Release|x86.Build.0 = Release|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Debug|x86.ActiveCfg = Debug|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Debug|x86.Build.0 = Debug|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Release|Any CPU.Build.0 = Release|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Release|x86.ActiveCfg = Release|Any CPU
{6D4B9BDA-2A66-4583-B244-758BC4213D9F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
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