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
ecf66e6c
Commit
ecf66e6c
authored
Jun 14, 2022
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 测厚仪服务器,提供modbus Tcp 服务,供其它HMI读取
parent
9392ac86
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
279 additions
and
11 deletions
+279
-11
FLY.Thick.Blowing.csproj
....Thick.Blowing/FLY.Thick.Blowing/FLY.Thick.Blowing.csproj
+5
-0
ThickPlcModbusTcpServer.cs
...owing/FLY.Thick.Blowing/Server/ThickPlcModbusTcpServer.cs
+210
-0
FLY.Thick.BlowingScan.UI.Server.csproj
...wingScan.UI.Server/FLY.Thick.BlowingScan.UI.Server.csproj
+4
-0
MainWindow.xaml.cs
...ngScan/FLY.Thick.BlowingScan.UI.Server/MainWindow.xaml.cs
+6
-2
PgMain.xaml
...k.BlowingScan/FLY.Thick.BlowingScan.UI.Server/PgMain.xaml
+28
-0
PgMain.xaml.cs
...lowingScan/FLY.Thick.BlowingScan.UI.Server/PgMain.xaml.cs
+10
-4
WdSetup.xaml
....BlowingScan/FLY.Thick.BlowingScan.UI.Server/WdSetup.xaml
+4
-0
WdSetup.xaml.cs
...owingScan/FLY.Thick.BlowingScan.UI.Server/WdSetup.xaml.cs
+12
-5
No files found.
Project.FLY.Thick.Blowing/FLY.Thick.Blowing/FLY.Thick.Blowing.csproj
View file @
ecf66e6c
...
...
@@ -88,6 +88,7 @@
<Compile
Include=
"Server\Model\OrgDbModel.cs"
/>
<Compile
Include=
"Server\ScanWarning.cs"
/>
<Compile
Include=
"Server\TDGage.cs"
/>
<Compile
Include=
"Server\ThickPlcModbusTcpServer.cs"
/>
</ItemGroup>
<ItemGroup>
<Content
Include=
"FodyWeavers.xml"
>
...
...
@@ -111,6 +112,10 @@
<Project>
{5ee61ac6-5269-4f0f-b8fa-4334fe4a678f}
</Project>
<Name>
Misc
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\..\thick_public\Project.FLY.ModbusMapper\FLY.ModbusMapper\FLY.ModbusMapper.csproj"
>
<Project>
{6d4b9bda-2a66-4583-b244-758bc4213d9f}
</Project>
<Name>
FLY.ModbusMapper
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\..\thick_public\Project.FLY.OBJComponents\OBJComponents\FLY.OBJComponents.csproj"
>
<Project>
{a539505d-9ac0-426b-a9a0-197df50598b0}
</Project>
<Name>
FLY.OBJComponents
</Name>
...
...
Project.FLY.Thick.Blowing/FLY.Thick.Blowing/Server/ThickPlcModbusTcpServer.cs
0 → 100644
View file @
ecf66e6c
using
FLY.Thick.Blowing.IService
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Misc
;
using
System.IO
;
using
Newtonsoft.Json
;
namespace
FLY.Thick.Blowing.Server
{
public
class
ThickPlcModbusTcpServer
:
INotifyPropertyChanged
{
const
int
ADDR_ID
=
0
;
const
int
ADDR_DateTimeYear
=
1
;
const
int
ADDR_DateTimeMonth
=
2
;
const
int
ADDR_DateTimeDay
=
3
;
const
int
ADDR_DateTimeHour
=
4
;
const
int
ADDR_DateTimeMinute
=
5
;
const
int
ADDR_DateTimeSecond
=
6
;
const
int
ADDR_Average
=
7
;
const
int
ADDR_Sigma2
=
8
;
const
int
ADDR_Sigma2Percent
=
9
;
const
int
ADDR_Count
=
10
;
const
int
ADDR_Datas
=
11
;
const
int
DatasCap
=
199
-
11
+
1
;
FLY
.
Modbus
.
WithThread
.
ServerTCP
server
;
IBulkDbService
bulkDbService
;
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
string
ServerAddr
{
get
;
set
;
}
=
"0.0.0.0:1502"
;
public
FLY
.
Modbus
.
WithThread
.
ServerTCP
ModbusTcpServer
=>
server
;
UInt16
[]
regs
=
new
UInt16
[
200
];
UInt16
[]
regs2
=
new
UInt16
[
200
];
public
ThickPlcModbusTcpServer
()
{
if
(!
Load
())
{
Save
();
}
}
public
void
Init
(
IBulkDbService
bulkDbService
)
{
this
.
bulkDbService
=
bulkDbService
;
server
=
new
FLY
.
Modbus
.
WithThread
.
ServerTCP
(
Misc
.
StringConverter
.
ToIPEndPoint
(
ServerAddr
),
GetValue
,
SetValue
);
server
.
Start
();
this
.
bulkDbService
.
PropertyChanged
+=
BulkDbService_PropertyChanged
;
updateDatas
();
}
private
void
BulkDbService_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
e
.
PropertyName
==
nameof
(
bulkDbService
.
LastScanDataId
))
{
updateDatas
();
}
}
void
updateDatas
()
{
this
.
bulkDbService
.
GetFrame
(
new
Pack_GetFrameRequest
()
{
Id
=
0
,
Mix
=
1
},
(
object
asyncContext
,
object
retData
)
=>
{
var
reponse
=
retData
as
Pack_GetFrameReponse
;
if
(
reponse
.
scanData
==
null
)
{
//没有数据
return
;
}
var
scanData
=
reponse
.
scanData
;
regs2
[
ADDR_ID
]
=
(
UInt16
)
scanData
.
ID
;
regs2
[
ADDR_DateTimeYear
]
=
(
UInt16
)
scanData
.
Time
.
Year
;
regs2
[
ADDR_DateTimeMonth
]
=
(
UInt16
)
scanData
.
Time
.
Month
;
regs2
[
ADDR_DateTimeDay
]
=
(
UInt16
)
scanData
.
Time
.
Day
;
regs2
[
ADDR_DateTimeHour
]
=
(
UInt16
)
scanData
.
Time
.
Hour
;
regs2
[
ADDR_DateTimeMinute
]
=
(
UInt16
)
scanData
.
Time
.
Minute
;
regs2
[
ADDR_DateTimeSecond
]
=
(
UInt16
)
scanData
.
Time
.
Second
;
if
(
scanData
.
Thicks
!=
null
)
{
double
avg
=
scanData
.
Thicks
.
AverageNoNull
();
if
(!
double
.
IsNaN
(
avg
))
{
regs2
[
ADDR_Average
]
=
(
UInt16
)(
avg
*
10
);
double
sigma2
=
scanData
.
Thicks
.
Sigma
()
*
2
;
regs2
[
ADDR_Sigma2
]
=
(
UInt16
)(
sigma2
*
10
);
double
sigma2Percent
=
sigma2
/
avg
*
100
;
regs2
[
ADDR_Sigma2Percent
]
=
(
UInt16
)(
sigma2Percent
*
10
);
regs2
[
ADDR_Count
]
=
(
UInt16
)
scanData
.
Thicks
.
Count
();
for
(
int
i
=
0
;
i
<
scanData
.
Thicks
.
Count
()
&&
i
<
DatasCap
;
i
++)
{
var
d
=
scanData
.
Thicks
[
i
];
if
(!
double
.
IsNaN
(
avg
))
{
regs2
[
ADDR_Datas
+
i
]
=
(
UInt16
)(
d
*
10
);
}
else
{
regs2
[
ADDR_Datas
+
i
]
=
0
;
}
}
}
else
{
clearDatas
(
regs2
);
}
}
else
{
clearDatas
(
regs2
);
}
lock
(
regs
)
{
Array
.
Copy
(
regs2
,
regs
,
regs
.
Count
());
}
},
null
);
}
void
clearDatas
(
UInt16
[]
regs2
)
{
for
(
int
i
=
ADDR_Average
;
i
<
regs2
.
Count
();
i
++)
{
regs2
[
i
]
=
0
;
}
}
void
GetValue
(
int
addr
,
object
values
)
{
if
(
addr
<
0
)
return
;
if
(
values
is
UInt16
[])
{
var
uint16s
=
values
as
UInt16
[];
int
sourceIndex
=
addr
;
int
len
=
uint16s
.
Count
();
if
(
sourceIndex
>=
regs
.
Count
())
return
;
if
(
sourceIndex
+
len
>
regs
.
Count
())
{
len
=
regs
.
Count
()
-
sourceIndex
;
}
lock
(
regs
)
{
Array
.
Copy
(
regs
,
addr
,
uint16s
,
0
,
len
);
}
}
}
void
SetValue
(
int
addr
,
object
values
)
{
}
string
file_path
=
"thickplc.json"
;
bool
Load
()
{
try
{
if
(
File
.
Exists
(
file_path
))
{
string
json
=
File
.
ReadAllText
(
file_path
);
var
jsonDb
=
JsonConvert
.
DeserializeObject
<
ThickPlcModbusTcpServerJsonDb
>(
json
);
this
.
ServerAddr
=
jsonDb
.
ServerAddr
;
return
true
;
}
}
catch
{
//异常,没有json 解码失败
}
return
false
;
}
public
bool
Save
()
{
try
{
var
jsonDb
=
new
ThickPlcModbusTcpServerJsonDb
()
{
ServerAddr
=
ServerAddr
};
string
json
=
JsonConvert
.
SerializeObject
(
jsonDb
,
Formatting
.
Indented
);
File
.
WriteAllText
(
file_path
,
json
);
return
true
;
}
catch
{
//异常,没有json 编码失败
}
return
false
;
}
}
public
class
ThickPlcModbusTcpServerJsonDb
{
public
string
ServerAddr
=
"0.0.0.0:1502"
;
}
}
Project.FLY.Thick.BlowingScan/FLY.Thick.BlowingScan.UI.Server/FLY.Thick.BlowingScan.UI.Server.csproj
View file @
ecf66e6c
...
...
@@ -165,6 +165,10 @@
<Project>
{5ee61ac6-5269-4f0f-b8fa-4334fe4a678f}
</Project>
<Name>
Misc
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\..\thick_public\Project.FLY.ModbusMapper\FLY.ModbusMapper\FLY.ModbusMapper.csproj"
>
<Project>
{6d4b9bda-2a66-4583-b244-758bc4213d9f}
</Project>
<Name>
FLY.ModbusMapper
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\..\thick_public\Project.FLY.Thick.Base\FLY.Thick.Base\FLY.Thick.Base.csproj"
>
<Project>
{91a1aafe-a528-4c2e-a48a-9259e780255a}
</Project>
<Name>
FLY.Thick.Base
</Name>
...
...
Project.FLY.Thick.BlowingScan/FLY.Thick.BlowingScan.UI.Server/MainWindow.xaml.cs
View file @
ecf66e6c
...
...
@@ -10,7 +10,7 @@ using System.Text;
using
System.Threading.Tasks
;
using
System.Windows
;
using
System.Windows.Navigation
;
using
ThickPlcModbusTcpServer
=
FLY
.
Thick
.
Blowing
.
Server
.
ThickPlcModbusTcpServer
;
namespace
FLY.Thick.BlowingScan.UI.Server
{
/// <summary>
...
...
@@ -21,6 +21,7 @@ namespace FLY.Thick.BlowingScan.UI.Server
FLY
.
AppHelper
.
WindowNotifyIconHelper
notifyiconhelper
;
TDGage
mGage
;
OBJProxys
mOBJProxy
;
ThickPlcModbusTcpServer
thickPlcModbusTcpServer
;
public
MainWindow
()
{
InitializeComponent
();
...
...
@@ -40,12 +41,15 @@ namespace FLY.Thick.BlowingScan.UI.Server
mOBJProxy
=
new
OBJProxys
(
0
,
mGage
);
thickPlcModbusTcpServer
=
new
ThickPlcModbusTcpServer
();
thickPlcModbusTcpServer
.
Init
(
mGage
.
bulkDb
);
FObjBase
.
PollModule
.
Current
.
Start
();
this
.
Hide
();
PgMain
p
=
new
PgMain
();
p
.
Init
(
mGage
);
p
.
Init
(
mGage
,
thickPlcModbusTcpServer
);
this
.
Navigate
(
p
);
this
.
NavigationService
.
RemoveBackEntry
();
...
...
Project.FLY.Thick.BlowingScan/FLY.Thick.BlowingScan.UI.Server/PgMain.xaml
View file @
ecf66e6c
...
...
@@ -58,6 +58,34 @@
<TextBlock Style="{StaticResource Styles.Text.FieldContent}" Text="{Binding Position}"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}" DataContext="{Binding ModbusTcpServer}">
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="ModbusTcp服务地址"/>
<TextBlock Style="{StaticResource Styles.Text.FieldContent}" Text="{Binding LocalEP}"/>
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="状态"/>
<TextBlock>
<TextBlock.Style>
<Style TargetType="TextBlock" BasedOn="{StaticResource Styles.Text.FieldContent}">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Text" Value="停止"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsRunning}" Value="True">
<Setter Property="Foreground" Value="Green"/>
<Setter Property="Text" Value="工作中"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="当前连接数"/>
<TextBlock Style="{StaticResource Styles.Text.FieldContent}" Text="{Binding ConnectedCnt}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</Page>
Project.FLY.Thick.BlowingScan/FLY.Thick.BlowingScan.UI.Server/PgMain.xaml.cs
View file @
ecf66e6c
...
...
@@ -13,6 +13,7 @@ using System.Text;
using
System.Threading.Tasks
;
using
System.Windows.Controls
;
using
System.Windows.Data
;
using
ThickPlcModbusTcpServer
=
FLY
.
Thick
.
Blowing
.
Server
.
ThickPlcModbusTcpServer
;
namespace
FLY.Thick.BlowingScan.UI.Server
{
...
...
@@ -26,10 +27,10 @@ namespace FLY.Thick.BlowingScan.UI.Server
{
InitializeComponent
();
}
public
void
Init
(
TDGage
mGage
)
public
void
Init
(
TDGage
mGage
,
ThickPlcModbusTcpServer
thickPlcModbusTcpServer
)
{
viewModel
=
new
PgMainVm
();
viewModel
.
Init
(
mGage
);
viewModel
.
Init
(
mGage
,
thickPlcModbusTcpServer
);
this
.
DataContext
=
viewModel
;
}
...
...
@@ -46,7 +47,10 @@ namespace FLY.Thick.BlowingScan.UI.Server
public
RelayCommand
SaveDebugCmd
{
get
;
private
set
;
}
public
RelayCommand
DebugCmd
{
get
;
private
set
;
}
public
FLY
.
Modbus
.
WithThread
.
ServerTCP
ModbusTcpServer
{
get
;
set
;}
TDGage
mGage
;
ThickPlcModbusTcpServer
thickPlcModbusTcpServer
;
public
PgMainVm
()
{
SetupCmd
=
new
RelayCommand
(
Setup
);
...
...
@@ -56,11 +60,13 @@ namespace FLY.Thick.BlowingScan.UI.Server
public
void
Init
(
TDGage
mGage
)
public
void
Init
(
TDGage
mGage
,
ThickPlcModbusTcpServer
thickPlcModbusTcpServer
)
{
this
.
mGage
=
mGage
;
this
.
thickPlcModbusTcpServer
=
thickPlcModbusTcpServer
;
SysParam
=
mGage
.
sysParam
;
FlyAd
=
mGage
.
flyAd
;
ModbusTcpServer
=
thickPlcModbusTcpServer
.
ModbusTcpServer
;
}
private
void
OpenWdDebug
()
...
...
@@ -74,7 +80,7 @@ namespace FLY.Thick.BlowingScan.UI.Server
//打开设置页面
WdSetup
w
=
new
WdSetup
();
w
.
Init
(
SysParam
,
FlyAd
);
w
.
Init
(
SysParam
,
FlyAd
,
thickPlcModbusTcpServer
);
w
.
Owner
=
App
.
Current
.
MainWindow
;
w
.
ShowDialog
();
}
...
...
Project.FLY.Thick.BlowingScan/FLY.Thick.BlowingScan.UI.Server/WdSetup.xaml
View file @
ecf66e6c
...
...
@@ -24,6 +24,10 @@
<TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="AD盒地址"/>
<TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding FlyAdAddr}"/>
</StackPanel>
<StackPanel Margin="{StaticResource ControlMargin}">
<TextBlock Style="{StaticResource Styles.Text.FieldHeader}" Text="ModbusTcp地址"/>
<TextBox Style="{StaticResource Styles.Text.FieldContent.Input}" Text="{Binding PlcAddr}"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}">
<Button Style="{StaticResource Styles.Button.Square.Accent2}"
...
...
Project.FLY.Thick.BlowingScan/FLY.Thick.BlowingScan.UI.Server/WdSetup.xaml.cs
View file @
ecf66e6c
using
FLY.Thick.Base.Server
;
using
FLY.Thick.Blowing.Server
;
using
FlyADBase
;
using
GalaSoft.MvvmLight.Command
;
using
System
;
...
...
@@ -28,10 +29,10 @@ namespace FLY.Thick.BlowingScan.UI.Server
{
InitializeComponent
();
}
public
void
Init
(
SysParam
sysParam
,
FlyAD7
flyAd
)
public
void
Init
(
SysParam
sysParam
,
FlyAD7
flyAd
,
ThickPlcModbusTcpServer
thickPlcModbusTcpServer
)
{
viewModel
=
new
WdSetupVm
();
viewModel
.
Init
(
sysParam
,
flyAd
);
viewModel
.
Init
(
sysParam
,
flyAd
,
thickPlcModbusTcpServer
);
this
.
DataContext
=
viewModel
;
}
}
...
...
@@ -40,13 +41,13 @@ namespace FLY.Thick.BlowingScan.UI.Server
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
string
Addr
{
get
;
set
;
}
public
string
FlyAdAddr
{
get
;
set
;
}
public
string
PlcAddr
{
get
;
set
;
}
public
RelayCommand
OkCmd
{
get
;
private
set
;
}
SysParam
sysParam
;
FlyAD7
flyAd
;
InitParam
initParam
;
ThickPlcModbusTcpServer
thickPlcModbusTcpServer
;
public
WdSetupVm
()
{
OkCmd
=
new
RelayCommand
(
Ok
);
...
...
@@ -54,12 +55,15 @@ namespace FLY.Thick.BlowingScan.UI.Server
public
void
Init
(
SysParam
sysParam
,
FlyAD7
flyAd
)
public
void
Init
(
SysParam
sysParam
,
FlyAD7
flyAd
,
ThickPlcModbusTcpServer
thickPlcModbusTcpServer
)
{
this
.
sysParam
=
sysParam
;
this
.
flyAd
=
flyAd
;
this
.
thickPlcModbusTcpServer
=
thickPlcModbusTcpServer
;
Addr
=
sysParam
.
Addr
;
FlyAdAddr
=
flyAd
.
Addr
;
PlcAddr
=
thickPlcModbusTcpServer
.
ServerAddr
;
}
private
void
Ok
()
...
...
@@ -75,6 +79,9 @@ namespace FLY.Thick.BlowingScan.UI.Server
flyAd
.
Addr
=
FlyAdAddr
;
flyAd
.
Save
();
thickPlcModbusTcpServer
.
ServerAddr
=
PlcAddr
;
thickPlcModbusTcpServer
.
Save
();
System
.
Environment
.
CurrentDirectory
=
"../"
;
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