Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
PastureGateway
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
steven.sha
PastureGateway
Commits
4d5dd796
Commit
4d5dd796
authored
Jun 20, 2019
by
shaxuezheng
Browse files
Options
Browse Files
Download
Plain Diff
merge origin
parents
bfcd89ac
a6ed3828
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
171 additions
and
91 deletions
+171
-91
ModualControl.cs
ModbusDemo/MessageFormat/ModualControl.cs
+110
-71
AllPond.cs
ModbusDemo/application/AllPond.cs
+5
-13
AutoControl.cs
ModbusDemo/application/AutoControl.cs
+2
-2
InIHelper.cs
ModbusDemo/application/InIHelper.cs
+49
-0
ModualPool.cs
ModbusDemo/application/ModualPool.cs
+5
-5
No files found.
ModbusDemo/MessageFormat/ModualControl.cs
View file @
4d5dd796
...
@@ -14,35 +14,35 @@ using ModbusDemo.Common;
...
@@ -14,35 +14,35 @@ using ModbusDemo.Common;
using
System.Threading
;
using
System.Threading
;
using
ModbusDemo.application
;
using
ModbusDemo.application
;
using
System.Windows.Forms
;
using
System.Windows.Forms
;
using
System.IO
;
namespace
ModbusDemo.MessageFormat
namespace
ModbusDemo.MessageFormat
{
{
public
class
ModualControl
public
class
ModualControl
{
{
public
class
Op
public
class
Op
Item
{
{
public
ushort
duration
{
get
;
set
;
}
public
UInt64
startTime
{
get
;
set
;
}
public
int
d0
{
get
;
set
;
}
public
int
d0
{
get
;
set
;
}
public
int
d1
{
get
;
set
;
}
public
int
d2
{
get
;
set
;
}
public
int
d2
{
get
;
set
;
}
public
int
d3
{
get
;
set
;
}
public
int
d3
{
get
;
set
;
}
public
int
d4
{
get
;
set
;
}
public
int
d4
{
get
;
set
;
}
public
int
d5
{
get
;
set
;
}
public
int
d5
{
get
;
set
;
}
public
int
d6
{
get
;
set
;
}
public
int
d6
{
get
;
set
;
}
public
int
d7
{
get
;
set
;
}
public
int
d7
{
get
;
set
;
}
public
UInt64
ts
{
get
;
set
;
}
public
int
duration
{
get
;
set
;}
public
UInt64
startTime
{
get
;
set
;}
}
}
public
class
SsItem
public
class
SsItem
{
{
public
string
addr
{
get
;
set
;
}
public
string
addr
{
get
;
set
;
}
public
Op
op
{
get
;
set
;
}
}
public
List
<
OpItem
>
op
{
get
;
set
;
}
}
public
class
MqttRoot
public
class
MqttRoot
{
{
public
string
taskId
{
get
;
set
;
}
public
string
taskId
{
get
;
set
;
}
public
List
<
SsItem
>
ss
{
get
;
set
;
}
public
List
<
SsItem
>
ss
{
get
;
set
;
}
}
}
public
class
Cfg
public
class
Cfg
{
{
...
@@ -113,7 +113,8 @@ namespace ModbusDemo.MessageFormat
...
@@ -113,7 +113,8 @@ namespace ModbusDemo.MessageFormat
}
}
public
static
List
<
pcLiquidLevelConfig
>
cPoolLevelConfig
=
new
List
<
pcLiquidLevelConfig
>();
public
static
List
<
pcLiquidLevelConfig
>
cPoolLevelConfig
=
new
List
<
pcLiquidLevelConfig
>();
public
static
List
<
ModualCntrol
>
liModuualControl
=
new
List
<
ModualCntrol
>();
public
static
List
<
ModualCntrol
>
liModuualControl
=
new
List
<
ModualCntrol
>();
public
const
ushort
usDefineControlTimes
=
1
;
public
const
ushort
usDefineControlTimes
=
1
;
public
static
FileInfo
filConfigFiles
=
new
FileInfo
(
pcConfig
.
FileName
);
private
static
object
obLock
=
new
object
();
private
static
object
obLock
=
new
object
();
#if DEBUG_TEST
#if DEBUG_TEST
public
const
string
strMapCfg
=
"{chMap:["
+
public
const
string
strMapCfg
=
"{chMap:["
+
...
@@ -151,89 +152,92 @@ namespace ModbusDemo.MessageFormat
...
@@ -151,89 +152,92 @@ namespace ModbusDemo.MessageFormat
}
}
for
(
int
i
=
0
;
i
<
cControl
.
ss
.
Count
;
i
++)
for
(
int
i
=
0
;
i
<
cControl
.
ss
.
Count
;
i
++)
{
{
bool
[]
bOperationStatus
=
new
bool
[
8
]
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
};
for
(
int
m
=
0
;
m
<
cControl
.
ss
[
i
].
op
.
Count
();
m
++)
ModualCntrol
cModualCntrol
=
new
ModualCntrol
{
{
sbModbusID
=
byte
.
Parse
(
cControl
.
ss
[
i
].
addr
),
bool
[]
bOperationStatus
=
new
bool
[
8
]
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
};
usDurationTime
=
(
ushort
)(
cControl
.
ss
[
i
].
op
.
duration
*
60
),
ModualCntrol
cModualCntrol
=
new
ModualCntrol
ulStartTime
=
cControl
.
ss
[
i
].
op
.
startTime
{
};
sbModbusID
=
byte
.
Parse
(
cControl
.
ss
[
i
].
addr
),
cModualCntrol
.
bControlStatus
=
ModualPoll
.
bGet_channel_Value
<
bool
>(
cModualCntrol
.
sbModbusID
,
out
cModualCntrol
.
bControlData
,
"d0"
,
"d1"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
);
usDurationTime
=
(
ushort
)(
cControl
.
ss
[
i
].
op
[
m
].
duration
*
60
),
if
(
jsonObj
[
"ss"
][
i
][
"op"
]
!=
null
)
ulStartTime
=
cControl
.
ss
[
i
].
op
[
m
].
startTime
{
};
string
str
;
cModualCntrol
.
bControlStatus
=
ModualPoll
.
bGet_channel_Value
<
bool
>(
cModualCntrol
.
sbModbusID
,
out
cModualCntrol
.
bControlData
,
"d0"
,
"d1"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
)
;
for
(
int
j
=
0
;
j
<
8
;
j
++
)
if
(
jsonObj
[
"ss"
][
i
][
"op"
][
m
]
!=
null
)
{
{
str
=
"d"
+
j
.
ToString
()
;
str
ing
str
;
if
(
jsonObj
[
"ss"
][
i
][
"op"
][
str
]
!=
null
)
for
(
int
j
=
0
;
j
<
8
;
j
++
)
{
{
if
(
Convert
.
ToBoolean
(
jsonObj
[
"ss"
][
i
][
"op"
].
Value
<
int
>(
str
))
==
true
)
str
=
"d"
+
j
.
ToString
();
if
(
jsonObj
[
"ss"
][
i
][
"op"
][
m
][
str
]
!=
null
)
{
{
cModualCntrol
.
bControlData
[
j
]
=
true
;
if
(
Convert
.
ToBoolean
(
jsonObj
[
"ss"
][
i
][
"op"
][
m
].
Value
<
int
>(
str
))
==
true
)
cModualCntrol
.
bOpenMachine
=
true
;
{
cModualCntrol
.
bControlData
[
j
]
=
true
;
cModualCntrol
.
bOpenMachine
=
true
;
}
else
{
cModualCntrol
.
bControlData
[
j
]
=
false
;
cModualCntrol
.
bOpenMachine
=
false
;
}
cModualCntrol
.
bControlBit
[
j
]
=
true
;
strOperation
.
Add
(
str
);
}
}
}
if
(
jsonObj
[
"ss"
][
i
][
"op"
][
m
][
"ts"
]
!=
null
)
{
jsonObj
[
"ss"
][
i
][
"op"
][
m
][
"ts"
]
=
Form1
.
GetTimeStamp
();
}
cModualCntrol
.
strOperationChannelName
=
strOperation
.
ToArray
();
if
(
cModualCntrol
.
bControlStatus
==
true
&&
cModualCntrol
.
ulStartTime
<=
Form1
.
GetTimeStamp
())
{
//Form1.vSuspend_Poll_Control(true);
cModualCntrol
.
bStartControl
=
true
;
for
(
int
j
=
0
;
j
<
cModualCntrol
.
strOperationChannelName
.
Count
();
j
++)
{
if
(
ControlMap
.
bControl_Map
(
cModualCntrol
.
bOpenMachine
,
cModualCntrol
.
sbModbusID
,
cModualCntrol
.
bControlData
,
cModualCntrol
.
strOperationChannelName
[
j
]))
{
bOperationStatus
[
j
]
=
ControlMap
.
bDelege_Operation
(
cModualCntrol
.
bControlData
);
cModualCntrol
.
bControlStatus
=
bOperationStatus
[
j
];
}
}
else
else
{
{
cModualCntrol
.
bControl
Data
[
j
]
=
false
;
cModualCntrol
.
bControl
Status
=
false
;
cModualCntrol
.
bOpenMachine
=
false
;
bOperationStatus
[
j
]
=
false
;
}
}
cModualCntrol
.
bControlBit
[
j
]
=
true
;
strOperation
.
Add
(
str
);
}
}
//Form1.vSuspend_Poll_Control(false);
}
}
}
if
(
cModualCntrol
.
bControlStatus
==
true
&&
cModualCntrol
.
strOperationChannelName
.
Count
()
<=
1
)
if
(
jsonObj
[
"ss"
][
i
][
"op"
][
"ts"
]
!=
null
)
{
jsonObj
[
"ss"
][
i
][
"op"
][
"ts"
]
=
Form1
.
GetTimeStamp
();
}
cModualCntrol
.
strOperationChannelName
=
strOperation
.
ToArray
();
if
(
cModualCntrol
.
bControlStatus
==
true
&&
cModualCntrol
.
ulStartTime
<=
Form1
.
GetTimeStamp
())
{
//Form1.vSuspend_Poll_Control(true);
cModualCntrol
.
bStartControl
=
true
;
for
(
int
j
=
0
;
j
<
cModualCntrol
.
strOperationChannelName
.
Count
();
j
++)
{
{
if
(
ControlMap
.
bControl_Map
(
cModualCntrol
.
bOpenMachine
,
cModualCntrol
.
sbModbusID
,
cModualCntrol
.
bControlData
,
cModualCntrol
.
strOperationChannelName
[
j
]))
lock
(
obLock
)
{
bOperationStatus
[
j
]
=
ControlMap
.
bDelege_Operation
(
cModualCntrol
.
bControlData
);
cModualCntrol
.
bControlStatus
=
bOperationStatus
[
j
];
}
else
{
{
cModualCntrol
.
bControlStatus
=
false
;
vDelete_Same_Control
(
cModualCntrol
);
bOperationStatus
[
j
]
=
false
;
if
(
cModualCntrol
.
bStartControl
==
true
&&
cModualCntrol
.
ulStartTime
!=
0
&&
cModualCntrol
.
bControlStatus
==
true
)
{
liModuualControl
.
Add
(
cModualCntrol
);
}
else
if
(
cModualCntrol
.
bStartControl
==
false
&&
cModualCntrol
.
ulStartTime
!=
0
)
{
liModuualControl
.
Add
(
cModualCntrol
);
}
}
}
}
}
//Form1.vSuspend_Poll_Control(false);
for
(
int
k
=
0
;
k
<
8
;
k
++)
}
if
(
cModualCntrol
.
bControlStatus
==
true
&&
cModualCntrol
.
strOperationChannelName
.
Count
()
<=
1
)
{
lock
(
obLock
)
{
{
vDelete_Same_Control
(
cModualCntrol
);
if
(
cModualCntrol
.
bControlBit
[
k
]
==
true
&&
(
cModualCntrol
.
bControlStatus
==
true
||
bOperationStatus
[
k
]
==
true
))
if
(
cModualCntrol
.
bStartControl
==
true
&&
cModualCntrol
.
ulStartTime
!=
0
&&
cModualCntrol
.
bControlStatus
==
true
)
{
{
liModuualControl
.
Add
(
cModualCntrol
);
string
str
=
"d"
+
k
.
ToString
();
jsonObj
[
"ss"
][
i
][
"op"
][
m
][
str
]
=
1
;
}
}
else
if
(
cModualCntrol
.
b
StartControl
==
false
&&
cModualCntrol
.
ulStartTime
!=
0
)
else
if
(
cModualCntrol
.
b
ControlBit
[
k
]
==
true
)
{
{
liModuualControl
.
Add
(
cModualCntrol
);
string
str
=
"d"
+
k
.
ToString
();
jsonObj
[
"ss"
][
i
][
"op"
][
m
][
str
]
=
0
;
}
}
}
}
}
}
for
(
int
k
=
0
;
k
<
8
;
k
++)
{
if
(
cModualCntrol
.
bControlBit
[
k
]
==
true
&&
(
cModualCntrol
.
bControlStatus
==
true
||
bOperationStatus
[
k
]
==
true
))
{
string
str
=
"d"
+
k
.
ToString
();
jsonObj
[
"ss"
][
i
][
"op"
][
str
]
=
1
;
}
else
if
(
cModualCntrol
.
bControlBit
[
k
]
==
true
)
{
string
str
=
"d"
+
k
.
ToString
();
jsonObj
[
"ss"
][
i
][
"op"
][
str
]
=
0
;
}
}
}
}
stResponseData
=
jsonObj
.
ToString
();
stResponseData
=
jsonObj
.
ToString
();
}
}
...
@@ -290,6 +294,16 @@ namespace ModbusDemo.MessageFormat
...
@@ -290,6 +294,16 @@ namespace ModbusDemo.MessageFormat
}
}
public
static
Task
vControl_Res_Poll
()
public
static
Task
vControl_Res_Poll
()
{
{
if
(
filConfigFiles
.
Length
==
0
)
{
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最高液位"
,
"8"
);
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最低液位"
,
"1"
);
}
else
{
AllPond
.
cEastTransitPool
.
vSetMaxLevel
=
pcConfig
.
ReadConfig
<
double
>(
"匀浆池配置"
,
"报警最高液位"
);
AllPond
.
cEastTransitPool
.
vSetMinLevel
=
pcConfig
.
ReadConfig
<
double
>(
"匀浆池配置"
,
"报警最低液位"
);
}
while
(
true
)
while
(
true
)
{
{
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
...
@@ -467,6 +481,18 @@ namespace ModbusDemo.MessageFormat
...
@@ -467,6 +481,18 @@ namespace ModbusDemo.MessageFormat
}
}
}
}
double
EastTransitPoolLevel
;
EastTransitPoolLevel
=
AllPond
.
cEastTransitPool
.
cLevel
.
dCurrentlevel
;
if
(
EastTransitPoolLevel
>=
AllPond
.
cEastTransitPool
.
vSetMaxLevel
||
EastTransitPoolLevel
<=
AllPond
.
cEastTransitPool
.
vSetMinLevel
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
cEastTransitPool
.
cLevel
.
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelLevelError
,
true
,
1
,
AllPond
.
cEastTransitPool
.
cLevel
.
strChannelNumber
);
}
else
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
cEastTransitPool
.
cLevel
.
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelLevelError
,
false
,
1
,
AllPond
.
cEastTransitPool
.
cLevel
.
strChannelNumber
);
}
Thread
.
Sleep
(
1000
);
Thread
.
Sleep
(
1000
);
}
}
...
@@ -586,6 +612,7 @@ namespace ModbusDemo.MessageFormat
...
@@ -586,6 +612,7 @@ namespace ModbusDemo.MessageFormat
dUpLevel
=
double
.
Parse
(
cCfgRoot
.
ss
[
i
].
cfg
.
upper
),
dUpLevel
=
double
.
Parse
(
cCfgRoot
.
ss
[
i
].
cfg
.
upper
),
dDownLevel
=
double
.
Parse
(
cCfgRoot
.
ss
[
i
].
cfg
.
down
)
dDownLevel
=
double
.
Parse
(
cCfgRoot
.
ss
[
i
].
cfg
.
down
)
};
};
vSet_Pool_Alarm_Level
(
cLiquidLevelConfig
.
byModbusID
,
cLiquidLevelConfig
.
dUpLevel
,
cLiquidLevelConfig
.
dDownLevel
);
string
strChannelString
=
"d"
+
i
.
ToString
();
string
strChannelString
=
"d"
+
i
.
ToString
();
for
(
int
j
=
0
;
j
<
8
;
j
++)
for
(
int
j
=
0
;
j
<
8
;
j
++)
{
{
...
@@ -614,5 +641,17 @@ namespace ModbusDemo.MessageFormat
...
@@ -614,5 +641,17 @@ namespace ModbusDemo.MessageFormat
stResponseStrign
=
jsonObj
.
ToString
();
stResponseStrign
=
jsonObj
.
ToString
();
}
}
}
}
public
static
void
vSet_Pool_Alarm_Level
(
byte
byModbusID
,
double
dMaxLevel
,
double
dMinLevel
)
{
if
(
byModbusID
==
AllPond
.
cEastTransitPool
.
cLevel
.
byModbusID
)
{
AllPond
.
cEastTransitPool
.
vSetMaxLevel
=
dMaxLevel
;
AllPond
.
cEastTransitPool
.
vSetMinLevel
=
dMinLevel
;
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最高液位"
,
AllPond
.
cEastTransitPool
.
vSetMaxLevel
.
ToString
());
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最低液位"
,
AllPond
.
cEastTransitPool
.
vSetMaxLevel
.
ToString
());
}
}
}
}
}
}
\ No newline at end of file
ModbusDemo/application/AllPond.cs
View file @
4d5dd796
...
@@ -11,7 +11,7 @@ namespace ModbusDemo.application
...
@@ -11,7 +11,7 @@ namespace ModbusDemo.application
public
static
class
AllPond
public
static
class
AllPond
{
{
private
static
ModualPool
.
pcTemperature
cEastTransitPoolTemper
=
new
ModualPool
.
pcTemperature
(
"EastTransitPoolTemper"
,
27
,
"d0"
);
private
static
ModualPool
.
pcTemperature
cEastTransitPoolTemper
=
new
ModualPool
.
pcTemperature
(
"EastTransitPoolTemper"
,
27
,
"d0"
);
private
static
ModualPool
.
pcLiquidlevel
cEastTransitPoolLevel
=
new
ModualPool
.
pcLiquidlevel
(
"EastTransitPoolLevel"
,
13
,
"d
0
"
);
private
static
ModualPool
.
pcLiquidlevel
cEastTransitPoolLevel
=
new
ModualPool
.
pcLiquidlevel
(
"EastTransitPoolLevel"
,
13
,
"d
2
"
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolSouthWaterBase
=
new
ModualPool
.
pcOperation
private
static
ModualPool
.
pcOperation
cEastTransitPoolSouthWaterBase
=
new
ModualPool
.
pcOperation
{
{
byModbusID
=
31
,
byModbusID
=
31
,
...
@@ -19,9 +19,9 @@ namespace ModbusDemo.application
...
@@ -19,9 +19,9 @@ namespace ModbusDemo.application
strChannelNumber
=
new
string
[]
{
"d1"
,
"d2"
},
strChannelNumber
=
new
string
[]
{
"d1"
,
"d2"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
tru
e
,
bHadRefControl
=
fals
e
,
byResModbusID
=
13
,
byResModbusID
=
0
,
strResChannelNumber
=
"d0"
strResChannelNumber
=
null
};
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolSouthWater
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolSouthWater"
,
cEastTransitPoolSouthWaterBase
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolSouthWater
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolSouthWater"
,
cEastTransitPoolSouthWaterBase
);
...
@@ -131,7 +131,7 @@ namespace ModbusDemo.application
...
@@ -131,7 +131,7 @@ namespace ModbusDemo.application
public
static
class
cEastTransitPool
public
static
class
cEastTransitPool
{
{
public
static
double
vSetMaxLevel
;
public
static
double
vSetMaxLevel
;
public
static
double
vSetMinLevel
;
public
static
double
vSetMinLevel
;
public
static
ModualPool
.
pcTemperature
cTemper
{
get
=>
cEastTransitPoolTemper
;
set
=>
cEastTransitPoolTemper
=
value
;}
public
static
ModualPool
.
pcTemperature
cTemper
{
get
=>
cEastTransitPoolTemper
;
set
=>
cEastTransitPoolTemper
=
value
;}
public
static
ModualPool
.
pcLiquidlevel
cLevel
{
get
=>
cEastTransitPoolLevel
;
set
=>
cEastTransitPoolLevel
=
value
;}
public
static
ModualPool
.
pcLiquidlevel
cLevel
{
get
=>
cEastTransitPoolLevel
;
set
=>
cEastTransitPoolLevel
=
value
;}
...
@@ -144,15 +144,7 @@ namespace ModbusDemo.application
...
@@ -144,15 +144,7 @@ namespace ModbusDemo.application
public
static
ModualPool
.
pcMachine
cStirrer3
{
get
=>
cEastTransitPoolStirrer3
;
set
=>
cEastTransitPoolStirrer3
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer3
{
get
=>
cEastTransitPoolStirrer3
;
set
=>
cEastTransitPoolStirrer3
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer4
{
get
=>
cEastTransitPoolStirrer4
;
set
=>
cEastTransitPoolStirrer4
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer4
{
get
=>
cEastTransitPoolStirrer4
;
set
=>
cEastTransitPoolStirrer4
=
value
;
}
public
static
ModualPool
.
pcButton
cButton1
{
get
=>
cEastTransitPoolButton1
;
set
=>
cEastTransitPoolButton1
=
value
;
}
public
static
ModualPool
.
pcButton
cButton1
{
get
=>
cEastTransitPoolButton1
;
set
=>
cEastTransitPoolButton1
=
value
;
}
private
static
void
vSet_Poll_Max_Level
(
double
dData
)
{
vSetMaxLevel
=
dData
;
}
private
static
void
vSet_Poll_Min_Level
(
double
dData
)
{
vSetMinLevel
=
dData
;
}
}
}
...
...
ModbusDemo/application/AutoControl.cs
View file @
4d5dd796
...
@@ -38,7 +38,7 @@ namespace ModbusDemo.application
...
@@ -38,7 +38,7 @@ namespace ModbusDemo.application
public
int
modularx
;
public
int
modularx
;
public
byte
modbusID
;
public
byte
modbusID
;
}
}
public
static
byte
[]
EmodbusId
=
{
5
,
51
};
public
static
byte
[]
EmodbusId
=
{
16
,
51
};
public
static
byte
[]
WmodbusId
=
{
35
,
31
};
public
static
byte
[]
WmodbusId
=
{
35
,
31
};
public
static
byte
[]
LevelmodbusID
=
{
6
,
13
};
public
static
byte
[]
LevelmodbusID
=
{
6
,
13
};
public
static
bool
[]
state_ON
=
{
true
,
true
,
true
,
true
,
true
,
true
};
public
static
bool
[]
state_ON
=
{
true
,
true
,
true
,
true
,
true
,
true
};
...
@@ -47,7 +47,7 @@ namespace ModbusDemo.application
...
@@ -47,7 +47,7 @@ namespace ModbusDemo.application
public
static
bool
Wtimerun
=
false
;
public
static
bool
Wtimerun
=
false
;
static
System
.
Diagnostics
.
Stopwatch
ETime
=
new
System
.
Diagnostics
.
Stopwatch
();
static
System
.
Diagnostics
.
Stopwatch
ETime
=
new
System
.
Diagnostics
.
Stopwatch
();
static
System
.
Diagnostics
.
Stopwatch
WTime
=
new
System
.
Diagnostics
.
Stopwatch
();
static
System
.
Diagnostics
.
Stopwatch
WTime
=
new
System
.
Diagnostics
.
Stopwatch
();
private
static
readonly
int
Runtimeout
=
1
;
private
static
readonly
int
Runtimeout
=
1
0
;
public
static
void
CriticalValueMonitoring
(
ref
Control
usControl
,
bool
Enabl
,
string
Affiliation
,
out
Control
control
)
public
static
void
CriticalValueMonitoring
(
ref
Control
usControl
,
bool
Enabl
,
string
Affiliation
,
out
Control
control
)
{
{
...
...
ModbusDemo/application/InIHelper.cs
View file @
4d5dd796
...
@@ -58,4 +58,53 @@ namespace ModbusDemo.application
...
@@ -58,4 +58,53 @@ namespace ModbusDemo.application
f
.
WriteContentValue
(
section
,
key
,
value
);
f
.
WriteContentValue
(
section
,
key
,
value
);
}
}
}
}
public
class
pcConfig
{
public
static
string
FileName
=
Application
.
StartupPath
+
"\\PoolConfig.ini"
;
/// <summary>
/// 读取配置文件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="section"></param>
/// <param name="key"></param>
/// <returns></returns>
public
static
T
ReadConfig
<
T
>(
string
section
,
string
key
)
{
if
(
File
.
Exists
(
FileName
))
{
OperIni
f
=
new
OperIni
(
FileName
);
string
value
=
f
.
ReadContentValue
(
section
,
key
);
if
(
String
.
IsNullOrWhiteSpace
(
value
))
return
default
(
T
);
if
(
typeof
(
T
).
IsEnum
)
return
(
T
)
Enum
.
Parse
(
typeof
(
T
),
value
,
true
);
return
(
T
)
Convert
.
ChangeType
(
value
,
typeof
(
T
));
}
else
{
return
default
(
T
);
}
}
/// <summary>
/// 写配置文件
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="value"></param>
public
static
void
WriteConfig
(
string
section
,
string
key
,
string
value
)
{
//如果文件不存在,则创建
if
(!
File
.
Exists
(
FileName
))
{
using
(
FileStream
myFs
=
new
FileStream
(
FileName
,
FileMode
.
Create
))
{
}
}
OperIni
f
=
new
OperIni
(
FileName
);
f
.
WriteContentValue
(
section
,
key
,
value
);
}
}
}
}
ModbusDemo/application/ModualPool.cs
View file @
4d5dd796
...
@@ -15,8 +15,8 @@ namespace ModbusDemo.application
...
@@ -15,8 +15,8 @@ namespace ModbusDemo.application
{
{
private
string
strTemperName
;
private
string
strTemperName
;
public
double
dCurrentTemperate
{
get
=>
vGet_ResCurrent
();}
public
double
dCurrentTemperate
{
get
=>
vGet_ResCurrent
();}
p
rivate
byte
byModbusID
;
p
ublic
byte
byModbusID
;
p
rivate
string
[]
strChannelNumber
;
p
ublic
string
[]
strChannelNumber
;
public
pcTemperature
(
string
strName
,
byte
byModbusID
,
params
string
[]
strChannelNumber
)
public
pcTemperature
(
string
strName
,
byte
byModbusID
,
params
string
[]
strChannelNumber
)
{
{
this
.
strTemperName
=
strName
;
this
.
strTemperName
=
strName
;
...
@@ -50,8 +50,8 @@ namespace ModbusDemo.application
...
@@ -50,8 +50,8 @@ namespace ModbusDemo.application
{
{
private
string
strLevel
;
private
string
strLevel
;
public
double
dCurrentlevel
{
get
=>
vGet_ResCurrent
();}
public
double
dCurrentlevel
{
get
=>
vGet_ResCurrent
();}
p
rivate
byte
byModbusID
;
p
ublic
byte
byModbusID
;
p
rivate
string
[]
strChannelNumber
;
p
ublic
string
[]
strChannelNumber
;
public
pcLiquidlevel
(
string
strName
,
byte
byModbusID
,
params
string
[]
strChannelNumber
)
public
pcLiquidlevel
(
string
strName
,
byte
byModbusID
,
params
string
[]
strChannelNumber
)
{
{
this
.
strLevel
=
strName
;
this
.
strLevel
=
strName
;
...
@@ -67,7 +67,7 @@ namespace ModbusDemo.application
...
@@ -67,7 +67,7 @@ namespace ModbusDemo.application
List
<
double
>
ConvertData
=
new
List
<
double
>();
List
<
double
>
ConvertData
=
new
List
<
double
>();
for
(
int
i
=
0
;
i
<
dConvertData
.
Count
();
i
++)
for
(
int
i
=
0
;
i
<
dConvertData
.
Count
();
i
++)
{
{
if
(
dConvertData
[
i
]
>
0
&&
dConvertData
[
i
]
<
5
)
if
(
dConvertData
[
i
]
>
0
&&
dConvertData
[
i
]
<
20
)
{
{
ConvertData
.
Add
(
dConvertData
[
i
]);
ConvertData
.
Add
(
dConvertData
[
i
]);
}
}
...
...
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