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
5e2f988a
Commit
5e2f988a
authored
Jun 21, 2019
by
leon.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add data in time updata
parent
a6ed3828
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
384 additions
and
207 deletions
+384
-207
ModualControl.cs
ModbusDemo/MessageFormat/ModualControl.cs
+8
-4
ModualPoll.cs
ModbusDemo/Modular/ModualPoll.cs
+77
-11
AllPond.cs
ModbusDemo/application/AllPond.cs
+219
-93
AutoControl.cs
ModbusDemo/application/AutoControl.cs
+30
-29
Form1.cs
ModbusDemo/windows/Form1.cs
+50
-70
No files found.
ModbusDemo/MessageFormat/ModualControl.cs
View file @
5e2f988a
...
...
@@ -138,7 +138,6 @@ namespace ModbusDemo.MessageFormat
#endif
public
static
void
vGetaWay_Receive_Control
(
string
sDataString
,
out
string
stResponseData
)
{
List
<
string
>
strOperation
=
new
List
<
string
>();
MqttRoot
cControl
=
new
MqttRoot
();
var
jsonObj
=
new
JObject
();
try
...
...
@@ -154,6 +153,7 @@ namespace ModbusDemo.MessageFormat
{
for
(
int
m
=
0
;
m
<
cControl
.
ss
[
i
].
op
.
Count
();
m
++)
{
List
<
string
>
strOperation
=
new
List
<
string
>();
bool
[]
bOperationStatus
=
new
bool
[
8
]
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
};
ModualCntrol
cModualCntrol
=
new
ModualCntrol
{
...
...
@@ -207,6 +207,7 @@ namespace ModbusDemo.MessageFormat
bOperationStatus
[
j
]
=
false
;
}
}
//Form1.vSuspend_Poll_Control(false);
}
if
(
cModualCntrol
.
bControlStatus
==
true
&&
cModualCntrol
.
strOperationChannelName
.
Count
()
<=
1
)
...
...
@@ -290,7 +291,6 @@ namespace ModbusDemo.MessageFormat
}
Thread
.
Sleep
(
100
);
}
}
public
static
Task
vControl_Res_Poll
()
{
...
...
@@ -298,6 +298,9 @@ namespace ModbusDemo.MessageFormat
{
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最高液位"
,
"8"
);
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最低液位"
,
"1"
);
AllPond
.
cEastTransitPool
.
vSetMaxLevel
=
pcConfig
.
ReadConfig
<
double
>(
"匀浆池配置"
,
"报警最高液位"
);
AllPond
.
cEastTransitPool
.
vSetMinLevel
=
pcConfig
.
ReadConfig
<
double
>(
"匀浆池配置"
,
"报警最低液位"
);
}
else
{
...
...
@@ -581,6 +584,7 @@ namespace ModbusDemo.MessageFormat
ModualAlarm
.
vSet_Modual_Alarm
(
sbModbusID
,(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
str
);
}
}
ModualPoll
.
vSend_Actual_Data
(
sbModbusID
);
return
bControlStatus
;
}
public
static
void
vDelete_Same_Control
(
ModualCntrol
cModualCntrol
)
...
...
@@ -613,9 +617,9 @@ namespace ModbusDemo.MessageFormat
dDownLevel
=
double
.
Parse
(
cCfgRoot
.
ss
[
i
].
cfg
.
down
)
};
vSet_Pool_Alarm_Level
(
cLiquidLevelConfig
.
byModbusID
,
cLiquidLevelConfig
.
dUpLevel
,
cLiquidLevelConfig
.
dDownLevel
);
string
strChannelString
=
"d"
+
i
.
ToString
();
for
(
int
j
=
0
;
j
<
8
;
j
++)
{
string
strChannelString
=
"d"
+
j
.
ToString
();
if
(
jsonObj
[
"ss"
][
i
][
"cfg"
].
Value
<
string
>(
"name"
)
==
strChannelString
)
{
cLiquidLevelConfig
.
stChannelNumber
=
strChannelString
;
...
...
@@ -649,7 +653,7 @@ namespace ModbusDemo.MessageFormat
AllPond
.
cEastTransitPool
.
vSetMaxLevel
=
dMaxLevel
;
AllPond
.
cEastTransitPool
.
vSetMinLevel
=
dMinLevel
;
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最高液位"
,
AllPond
.
cEastTransitPool
.
vSetMaxLevel
.
ToString
());
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最低液位"
,
AllPond
.
cEastTransitPool
.
vSetM
ax
Level
.
ToString
());
pcConfig
.
WriteConfig
(
"匀浆池配置"
,
"报警最低液位"
,
AllPond
.
cEastTransitPool
.
vSetM
in
Level
.
ToString
());
}
}
...
...
ModbusDemo/Modular/ModualPoll.cs
View file @
5e2f988a
...
...
@@ -442,7 +442,66 @@ namespace ModbusDemo.Modular
await
ModualAlarm
.
vPublishAlarmPackageJson
(
mqttClient
);
}
}
public
static
void
vSend_Actual_Data
(
byte
byModbusID
)
{
string
strRes
=
null
;
for
(
int
i
=
0
;
i
<
ModualPoll
.
byX18xNumber
;
i
++)
{
if
(
byModbusID
==
ModualPoll
.
cx18x
.
byModbusID
[
i
])
{
double
[]
dGetData
;
bGet_channel_Value
<
double
>
(
byModbusID
,
out
dGetData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
string
stIdString
=
byModbusID
.
ToString
();
WTDR18X
OneNodeJsonPackage
=
new
WTDR18X
(
stIdString
,
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
0
],
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
1
],
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
2
],
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
3
],
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
4
],
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
5
],
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
6
],
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
7
],
Form1
.
GetTimeStamp
());
strRes
=
JsonConvert
.
SerializeObject
(
OneNodeJsonPackage
);
break
;
}
}
for
(
int
i
=
0
;
i
<
ModualPoll
.
byX14pNumber
;
i
++)
{
if
(
byModbusID
==
ModualPoll
.
cx14P
.
byModbusID
[
i
])
{
string
stIdString
=
byModbusID
.
ToString
();
double
[]
dGetData
;
bGet_channel_Value
<
double
>
(
byModbusID
,
out
dGetData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
);
WTDR14P
OneNodeJsonPackage
=
new
WTDR14P
(
stIdString
,
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
0
],
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
1
],
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
2
],
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
3
],
Form1
.
GetTimeStamp
());
strRes
=
JsonConvert
.
SerializeObject
(
OneNodeJsonPackage
);
break
;
}
}
for
(
int
i
=
0
;
i
<
ModualPoll
.
byX78cNumber
;
i
++)
{
if
(
byModbusID
==
ModualPoll
.
cx78c
.
byModbusID
[
i
])
{
string
stIdString
=
byModbusID
.
ToString
();
bool
[]
dGetData
;
bGet_channel_Value
<
bool
>
(
byModbusID
,
out
dGetData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
,
"d8"
,
"d9"
,
"d10"
,
"d11"
,
"d12"
,
"d13"
,
"d14"
,
"d15"
);
_478C
cBoolConvertInt
=
new
_478C
();
int
[]
InputConvert
,
OutPutConver
;
InputConvert
=
cBoolConvertInt
.
IO
(
cx78c
.
sX78cRegStatusStruct
[
i
].
bInputRegStatus
);
OutPutConver
=
cBoolConvertInt
.
IO
(
cx78c
.
sX78cRegStatusStruct
[
i
].
bOutPutRegStatus
);
WTDR78C
OneNodeJsonPackage
=
new
WTDR78C
(
stIdString
,
InputConvert
[
0
],
InputConvert
[
1
],
InputConvert
[
2
],
InputConvert
[
3
],
InputConvert
[
4
],
InputConvert
[
5
],
InputConvert
[
6
],
InputConvert
[
7
],
OutPutConver
[
0
],
OutPutConver
[
1
],
OutPutConver
[
2
],
OutPutConver
[
3
],
OutPutConver
[
4
],
OutPutConver
[
5
],
OutPutConver
[
6
],
OutPutConver
[
7
],
Form1
.
GetTimeStamp
());
strRes
=
JsonConvert
.
SerializeObject
(
OneNodeJsonPackage
);
break
;
}
}
for
(
int
i
=
0
;
i
<
ModualPoll
.
byX66cNumber
;
i
++)
{
if
(
byModbusID
==
ModualPoll
.
cx66c
.
byModbusID
[
i
])
{
string
stIdString
=
byModbusID
.
ToString
();
bool
[]
dGetData
;
bGet_channel_Value
<
bool
>
(
byModbusID
,
out
dGetData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
);
_478C
cBoolConvertInt
=
new
_478C
();
int
[]
sRelayConvert
;
sRelayConvert
=
cBoolConvertInt
.
IO
(
cx66c
.
sX66cRegStatusStruct
[
i
].
bRegRelayStatus
);
WTDR66C
OneNodeJsonPackage
=
new
WTDR66C
(
stIdString
,
sRelayConvert
[
0
],
sRelayConvert
[
1
],
sRelayConvert
[
2
],
sRelayConvert
[
3
],
sRelayConvert
[
4
],
sRelayConvert
[
5
],
Form1
.
GetTimeStamp
());
strRes
=
JsonConvert
.
SerializeObject
(
OneNodeJsonPackage
);
break
;
}
}
Form1
.
vControlResponseBack
(
Form1
.
mqttTopic
,
strRes
);
}
public
static
bool
bGet_channel_Value
<
T
>
(
byte
byModbusID
,
out
T
[]
ChannnelData
,
params
string
[]
strChannelList
)
{
ModbusComm
.
eModbusErrorCode
ModbusErrorCode
=
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
;
...
...
@@ -485,26 +544,27 @@ namespace ModbusDemo.Modular
switch
(
cx18x
.
beChannelType
[
i
,
k
])
{
case
modual
.
eX18xSensorChannelType
.
Weiertai
:
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
8
-
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
8
),
typeof
(
T
))
);
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
8
-
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
8
);
break
;
case
modual
.
eX18xSensorChannelType
.
Mike_5
:
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
5
-
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
5
),
typeof
(
T
))
);
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
5
-
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
5
);
break
;
case
modual
.
eX18xSensorChannelType
.
Mike_6
:
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
6
-
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
6
),
typeof
(
T
)));
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
6
-
((
double
.
Parse
(
strCalculData
[
k
])
-
6
)
/
16
*
6
);
break
;
case
modual
.
eX18xSensorChannelType
.
Mike_7
:
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
7
-
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
7
),
typeof
(
T
))
);
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
7
-
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
7
);
break
;
case
modual
.
eX18xSensorChannelType
.
NormalCurrent
:
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
double
.
Parse
(
strCalculData
[
k
]),
typeof
(
T
))
);
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
double
.
Parse
(
strCalculData
[
k
]
);
break
;
case
modual
.
eX18xSensorChannelType
.
Null
:
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
0
,
typeof
(
T
)))
;
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
0
;
break
;
default
:
break
;
}
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
],
typeof
(
T
)));
}
}
...
...
@@ -536,14 +596,16 @@ namespace ModbusDemo.Modular
bGetStatus
=
false
;
}
strCalculData
=
c14formulasormual
.
RtdValue
(
usRegValue
,
usRegType
);
for
(
int
j
=
0
;
j
<
strChannelList
.
Count
();
j
++)
{
for
(
int
k
=
0
;
k
<
byX14pReadTypeNumber
;
k
++)
{
ModualPoll
.
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
]
=
double
.
Parse
(
strCalculData
[
k
]);
string
str
=
"d"
+
k
.
ToString
();
if
(
str
==
strChannelList
[
j
])
{
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
strCalculData
,
typeof
(
T
)));
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
ModualPoll
.
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
]
,
typeof
(
T
)));
}
}
}
...
...
@@ -573,6 +635,8 @@ namespace ModbusDemo.Modular
ModualAlarm
.
vSet_Modual_Alarm
(
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
bGetStatus
=
false
;
}
ModualPoll
.
cx78c
.
sX78cRegStatusStruct
[
i
].
bInputRegStatus
=
bInputData
;
ModualPoll
.
cx78c
.
sX78cRegStatusStruct
[
i
].
bOutPutRegStatus
=
bOutPutData
;
for
(
int
j
=
0
;
j
<
strChannelList
.
Count
();
j
++)
{
for
(
int
k
=
0
;
k
<
byX78cInputRegNumber
;
k
++)
...
...
@@ -580,7 +644,7 @@ namespace ModbusDemo.Modular
string
str
=
"d"
+
k
.
ToString
();
if
(
str
==
strChannelList
[
j
])
{
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
bInputData
[
j
],
typeof
(
T
)));
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
bInputData
[
k
],
typeof
(
T
)));
}
}
for
(
int
k
=
byX78cInputRegNumber
;
k
<
byX78cOutputRegNumber
+
byX78cInputRegNumber
;
k
++)
...
...
@@ -588,7 +652,7 @@ namespace ModbusDemo.Modular
string
str
=
"d"
+
k
.
ToString
();
if
(
str
==
strChannelList
[
j
])
{
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
bOutPutData
[
j
],
typeof
(
T
)));
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
bOutPutData
[
k
],
typeof
(
T
)));
}
}
}
...
...
@@ -609,6 +673,8 @@ namespace ModbusDemo.Modular
ModualAlarm
.
vSet_Modual_Alarm
(
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
bGetStatus
=
false
;
}
ModualPoll
.
cx66c
.
sX66cRegStatusStruct
[
i
].
bRegRelayStatus
=
bRelayValue
;
for
(
int
j
=
0
;
j
<
strChannelList
.
Count
()
&&
j
<
byX66cRelayRegNumber
;
j
++)
{
for
(
int
k
=
0
;
k
<
byX66cRelayRegNumber
;
k
++)
...
...
@@ -616,7 +682,7 @@ namespace ModbusDemo.Modular
string
str
=
"d"
+
k
.
ToString
();
if
(
str
==
strChannelList
[
j
])
{
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
bRelayValue
[
j
],
typeof
(
T
)));
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
bRelayValue
[
k
],
typeof
(
T
)));
}
}
}
...
...
ModbusDemo/application/AllPond.cs
View file @
5e2f988a
...
...
@@ -10,143 +10,269 @@ namespace ModbusDemo.application
{
public
static
class
AllPond
{
private
static
ModualPool
.
pcTemperature
cEastTransitPoolTemper
=
new
ModualPool
.
pcTemperature
(
"EastTransitPoolTemper"
,
27
,
"d0"
);
private
static
ModualPool
.
pcLiquidlevel
cEastTransitPoolLevel
=
new
ModualPool
.
pcLiquidlevel
(
"EastTransitPoolLevel"
,
13
,
"d2
"
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolSouthWaterBase
=
new
ModualPool
.
pcOperation
{
byModbusID
=
31
,
strOperationNumber
=
"d1
"
,
strChannelNumber
=
new
string
[]
{
"d1"
,
"d2
"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
private
static
ModualPool
.
pcTemperature
cEastTransitPoolTemper
=
new
ModualPool
.
pcTemperature
(
"EastTransitPoolTemper"
,
27
,
"d0"
);
private
static
ModualPool
.
pcLiquidlevel
cEastTransitPoolLevel
=
new
ModualPool
.
pcLiquidlevel
(
"EastTransitPoolLevel"
,
13
,
"d0
"
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolSouthWaterBase
=
new
ModualPool
.
pcOperation
{
byModbusID
=
16
,
strOperationNumber
=
"d0
"
,
strChannelNumber
=
new
string
[]
{
"d0"
,
"d1
"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolSouthWater
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolSouthWater"
,
cEastTransitPoolSouthWaterBase
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolSouthWater
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolSouthWater"
,
cEastTransitPoolSouthWaterBase
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolNorthWaterBase
=
new
ModualPool
.
pcOperation
private
static
ModualPool
.
pcOperation
cEastTransitPoolNorthWaterBase
=
new
ModualPool
.
pcOperation
{
byModbusID
=
16
,
strOperationNumber
=
"d0
"
,
strChannelNumber
=
new
string
[]
{
"d0"
,
"d1
"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
byModbusID
=
16
,
strOperationNumber
=
"d2
"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3
"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolNorthWater
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolNorthWater"
,
cEastTransitPoolNorthWaterBase
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolNorthWater
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolNorthWater"
,
cEastTransitPoolNorthWaterBase
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolPumb1Base
=
new
ModualPool
.
pcOperation
private
static
ModualPool
.
pcOperation
cEastTransitPoolPumb1Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
16
,
strOperationNumber
=
"d2
"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
byModbusID
=
39
,
strOperationNumber
=
"d0
"
,
strChannelNumber
=
new
string
[]
{
"d0"
,
"d1"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolPumb1
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolPumb_1"
,
cEastTransitPoolPumb1Base
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolPumb1
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolPumb_1"
,
cEastTransitPoolPumb1Base
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolPumb2Base
=
new
ModualPool
.
pcOperation
private
static
ModualPool
.
pcOperation
cEastTransitPoolPumb2Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
35
,
strOperationNumber
=
"d0
"
,
strChannelNumber
=
new
string
[]
{
"d0"
,
"d1"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
true
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
byModbusID
=
39
,
strOperationNumber
=
"d2
"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
true
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolPumb2
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolPumb_2"
,
cEastTransitPoolPumb2Base
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolPumb2
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolPumb_2"
,
cEastTransitPoolPumb2Base
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer1Base
=
new
ModualPool
.
pcOperation
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer1Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
35
,
strOperationNumber
=
"d2
"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3
"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
fals
e
,
byResModbusID
=
0
,
strResChannelNumber
=
null
byModbusID
=
90
,
strOperationNumber
=
"d0
"
,
strChannelNumber
=
new
string
[]
{
"d0
"
},
bOpenOperation
=
new
bool
[]
{
true
},
bCloseOperation
=
new
bool
[]
{
false
},
bHadRefControl
=
tru
e
,
byResModbusID
=
13
,
strResChannelNumber
=
"d0"
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer1
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_1"
,
cEastTransitPoolStirrer1Base
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer1
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_1"
,
cEastTransitPoolStirrer1Base
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer2Base
=
new
ModualPool
.
pcOperation
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer2Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
39
,
strOperationNumber
=
"d0
"
,
strChannelNumber
=
new
string
[]
{
"d0"
,
"d1"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
tru
e
,
byResModbusID
=
13
,
byModbusID
=
90
,
strOperationNumber
=
"d1
"
,
strChannelNumber
=
new
string
[]
{
"d1"
},
bOpenOperation
=
new
bool
[]
{
true
},
bCloseOperation
=
new
bool
[]
{
false
},
bHadRefControl
=
fals
e
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
"d0"
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer2
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_2"
,
cEastTransitPoolStirrer2Base
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer2
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_2"
,
cEastTransitPoolStirrer2Base
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer3Base
=
new
ModualPool
.
pcOperation
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer3Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
39
,
strOperationNumber
=
"d2"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3
"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
byModbusID
=
90
,
strOperationNumber
=
"d2"
,
strChannelNumber
=
new
string
[]
{
"d2
"
},
bOpenOperation
=
new
bool
[]
{
true
},
bCloseOperation
=
new
bool
[]
{
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer3
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_3"
,
cEastTransitPoolStirrer3Base
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer3
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_3"
,
cEastTransitPoolStirrer3Base
);
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer4Base
=
new
ModualPool
.
pcOperation
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer4Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
16
,
strOperationNumber
=
"d
4
"
,
strChannelNumber
=
new
string
[]
{
"d
4
"
},
byModbusID
=
90
,
strOperationNumber
=
"d
3
"
,
strChannelNumber
=
new
string
[]
{
"d
3
"
},
bOpenOperation
=
new
bool
[]
{
true
},
bCloseOperation
=
new
bool
[]
{
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer4
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_4"
,
cEastTransitPoolStirrer4Base
);
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer4
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_4"
,
cEastTransitPoolStirrer4Base
);
private
static
ModualPool
.
pcButtonOperation
cEastTransitPoolButton1Base
=
new
ModualPool
.
pcButtonOperation
private
static
ModualPool
.
pcButtonOperation
cEastTransitPoolButton1Base
=
new
ModualPool
.
pcButtonOperation
{
byModbusID
=
16
,
strOperationNumber
=
"d0"
,
strChannelNumber
=
new
string
[]{
"d0"
,
"d1"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
}
strOperationNumber
=
"d0"
,
strChannelNumber
=
new
string
[]
{
"d0"
,
"d1"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
}
};
private
static
ModualPool
.
pcButton
cEastTransitPoolButton1
=
new
ModualPool
.
pcButton
(
"EastTransitPoolButton1"
,
cEastTransitPoolButton1Base
);
private
static
ModualPool
.
pcButton
cEastTransitPoolButton1
=
new
ModualPool
.
pcButton
(
"EastTransitPoolButton1"
,
cEastTransitPoolButton1Base
);
public
static
List
<
ModualPool
.
pcMachine
>
EastTransitPoolList
=
new
List
<
ModualPool
.
pcMachine
>(
new
ModualPool
.
pcMachine
[]
{
cEastTransitPoolSouthWater
,
cEastTransitPoolNorthWater
,
cEastTransitPoolPumb1
,
cEastTransitPoolPumb2
,
cEastTransitPoolStirrer1
,
cEastTransitPoolStirrer2
,
cEastTransitPoolStirrer3
,
cEastTransitPoolStirrer4
});
public
static
List
<
ModualPool
.
pcMachine
>
EastTransitPoolList
=
new
List
<
ModualPool
.
pcMachine
>(
new
ModualPool
.
pcMachine
[]
{
cEastTransitPoolSouthWater
,
cEastTransitPoolNorthWater
,
cEastTransitPoolPumb1
,
cEastTransitPoolPumb2
,
cEastTransitPoolStirrer1
,
cEastTransitPoolStirrer2
,
cEastTransitPoolStirrer3
,
cEastTransitPoolStirrer4
});
public
static
class
cEastTransitPool
public
static
class
cEastTransitPool
{
public
static
double
vSetMaxLevel
;
public
static
double
vSetMaxLevel
;
public
static
double
vSetMinLevel
;
public
static
ModualPool
.
pcTemperature
cTemper
{
get
=>
cEastTransitPoolTemper
;
set
=>
cEastTransitPoolTemper
=
value
;}
public
static
ModualPool
.
pcLiquidlevel
cLevel
{
get
=>
cEastTransitPoolLevel
;
set
=>
cEastTransitPoolLevel
=
value
;}
public
static
ModualPool
.
pcMachine
cSouthWater
{
get
=>
cEastTransitPoolSouthWater
;
set
=>
cEastTransitPoolSouthWater
=
value
;
}
public
static
ModualPool
.
pcMachine
cNorthWater
{
get
=>
cEastTransitPoolNorthWater
;
set
=>
cEastTransitPoolNorthWater
=
value
;
}
public
static
ModualPool
.
pcMachine
cPumb1
{
get
=>
cEastTransitPoolPumb1
;
set
=>
cEastTransitPoolPumb1
=
value
;
}
public
static
ModualPool
.
pcMachine
cPumb2
{
get
=>
cEastTransitPoolPumb2
;
set
=>
cEastTransitPoolPumb2
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer1
{
get
=>
cEastTransitPoolStirrer1
;
set
=>
cEastTransitPoolStirrer1
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer2
{
get
=>
cEastTransitPoolStirrer2
;
set
=>
cEastTransitPoolStirrer2
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer3
{
get
=>
cEastTransitPoolStirrer3
;
set
=>
cEastTransitPoolStirrer3
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer4
{
get
=>
cEastTransitPoolStirrer4
;
set
=>
cEastTransitPoolStirrer4
=
value
;
}
public
static
ModualPool
.
pcButton
cButton1
{
get
=>
cEastTransitPoolButton1
;
set
=>
cEastTransitPoolButton1
=
value
;
}
public
static
ModualPool
.
pcTemperature
cTemper
{
get
=>
cEastTransitPoolTemper
;
set
=>
cEastTransitPoolTemper
=
value
;
}
public
static
ModualPool
.
pcLiquidlevel
cLevel
{
get
=>
cEastTransitPoolLevel
;
set
=>
cEastTransitPoolLevel
=
value
;
}
public
static
ModualPool
.
pcMachine
cSouthWater
{
get
=>
cEastTransitPoolSouthWater
;
set
=>
cEastTransitPoolSouthWater
=
value
;
}
public
static
ModualPool
.
pcMachine
cNorthWater
{
get
=>
cEastTransitPoolNorthWater
;
set
=>
cEastTransitPoolNorthWater
=
value
;
}
public
static
ModualPool
.
pcMachine
cPumb1
{
get
=>
cEastTransitPoolPumb1
;
set
=>
cEastTransitPoolPumb1
=
value
;
}
public
static
ModualPool
.
pcMachine
cPumb2
{
get
=>
cEastTransitPoolPumb2
;
set
=>
cEastTransitPoolPumb2
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer1
{
get
=>
cEastTransitPoolStirrer1
;
set
=>
cEastTransitPoolStirrer1
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer2
{
get
=>
cEastTransitPoolStirrer2
;
set
=>
cEastTransitPoolStirrer2
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer3
{
get
=>
cEastTransitPoolStirrer3
;
set
=>
cEastTransitPoolStirrer3
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer4
{
get
=>
cEastTransitPoolStirrer4
;
set
=>
cEastTransitPoolStirrer4
=
value
;
}
public
static
ModualPool
.
pcButton
cButton1
{
get
=>
cEastTransitPoolButton1
;
set
=>
cEastTransitPoolButton1
=
value
;
}
}
private
static
ModualPool
.
pcTemperature
cWestTransitPoolTemper
=
new
ModualPool
.
pcTemperature
(
"WestTransitPoolTemper"
,
27
,
"d0"
);
private
static
ModualPool
.
pcLiquidlevel
cWestTransitPoolLevel
=
new
ModualPool
.
pcLiquidlevel
(
"WestTransitPoolLevel"
,
13
,
"d0"
);
private
static
ModualPool
.
pcOperation
cWestTransitPoolSouthWaterBase
=
new
ModualPool
.
pcOperation
{
byModbusID
=
35
,
strOperationNumber
=
"d0"
,
strChannelNumber
=
new
string
[]
{
"d0"
,
"d1"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cWestTransitPoolSouthWater
=
new
ModualPool
.
pcMachine
(
"WestTransitPoolSouthWater"
,
cWestTransitPoolSouthWaterBase
);
private
static
ModualPool
.
pcOperation
cWestTransitPoolNorthWaterBase
=
new
ModualPool
.
pcOperation
{
byModbusID
=
35
,
strOperationNumber
=
"d2"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cWestTransitPoolNorthWater
=
new
ModualPool
.
pcMachine
(
"WestTransitPoolNorthWater"
,
cWestTransitPoolNorthWaterBase
);
private
static
ModualPool
.
pcOperation
cWestTransitPoolPumb1Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
31
,
strOperationNumber
=
"d2"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cWestTransitPoolPumb1
=
new
ModualPool
.
pcMachine
(
"WestTransitPoolPumb_1"
,
cWestTransitPoolPumb1Base
);
private
static
ModualPool
.
pcOperation
cWestTransitPoolPumb2Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
39
,
strOperationNumber
=
"d2"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
true
},
bHadRefControl
=
false
,
byResModbusID
=
0
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cWestTransitPoolPumb2
=
new
ModualPool
.
pcMachine
(
"WestTransitPoolPumb_2"
,
cWestTransitPoolPumb2Base
);
private
static
ModualPool
.
pcOperation
cWestTransitPoolStirrer1Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
31
,
strOperationNumber
=
"d4"
,
strChannelNumber
=
new
string
[]
{
"d4"
,
"d5"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cWestTransitPoolStirrer1
=
new
ModualPool
.
pcMachine
(
"WestTransitPoolStirrer_1"
,
cWestTransitPoolStirrer1Base
);
private
static
ModualPool
.
pcOperation
cWestTransitPoolStirrer2Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
90
,
strOperationNumber
=
"d1"
,
strChannelNumber
=
new
string
[]
{
"d1"
},
bOpenOperation
=
new
bool
[]
{
true
},
bCloseOperation
=
new
bool
[]
{
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
"d0"
};
private
static
ModualPool
.
pcMachine
cWestTransitPoolStirrer2
=
new
ModualPool
.
pcMachine
(
"WestTransitPoolStirrer_2"
,
cWestTransitPoolStirrer2Base
);
private
static
ModualPool
.
pcOperation
cWestTransitPoolStirrer3Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
90
,
strOperationNumber
=
"d2"
,
strChannelNumber
=
new
string
[]
{
"d2"
},
bOpenOperation
=
new
bool
[]
{
true
},
bCloseOperation
=
new
bool
[]
{
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cWestTransitPoolStirrer3
=
new
ModualPool
.
pcMachine
(
"WestTransitPoolStirrer_3"
,
cWestTransitPoolStirrer3Base
);
private
static
ModualPool
.
pcOperation
cWestTransitPoolStirrer4Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
90
,
strOperationNumber
=
"d3"
,
strChannelNumber
=
new
string
[]
{
"d3"
},
bOpenOperation
=
new
bool
[]
{
true
},
bCloseOperation
=
new
bool
[]
{
false
},
bHadRefControl
=
false
,
byResModbusID
=
0xFF
,
strResChannelNumber
=
null
};
private
static
ModualPool
.
pcMachine
cWestTransitPoolStirrer4
=
new
ModualPool
.
pcMachine
(
"WestTransitPoolStirrer_4"
,
cWestTransitPoolStirrer4Base
);
public
static
class
pcWestTransitPool
{
public
static
double
vSetMaxLevel
;
public
static
double
vSetMinLevel
;
public
static
ModualPool
.
pcTemperature
cTemper
{
get
=>
cWestTransitPoolTemper
;
set
=>
cWestTransitPoolTemper
=
value
;
}
public
static
ModualPool
.
pcLiquidlevel
cLevel
{
get
=>
cWestTransitPoolLevel
;
set
=>
cWestTransitPoolLevel
=
value
;
}
public
static
ModualPool
.
pcMachine
cSouthWater
{
get
=>
cWestTransitPoolSouthWater
;
set
=>
cWestTransitPoolSouthWater
=
value
;
}
public
static
ModualPool
.
pcMachine
cNorthWater
{
get
=>
cWestTransitPoolNorthWater
;
set
=>
cWestTransitPoolNorthWater
=
value
;
}
public
static
ModualPool
.
pcMachine
cPumb1
{
get
=>
cWestTransitPoolPumb1
;
set
=>
cWestTransitPoolPumb1
=
value
;
}
public
static
ModualPool
.
pcMachine
cPumb2
{
get
=>
cWestTransitPoolPumb2
;
set
=>
cWestTransitPoolPumb2
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer1
{
get
=>
cWestTransitPoolStirrer1
;
set
=>
cWestTransitPoolStirrer1
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer2
{
get
=>
cWestTransitPoolStirrer2
;
set
=>
cWestTransitPoolStirrer2
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer3
{
get
=>
cWestTransitPoolStirrer3
;
set
=>
cWestTransitPoolStirrer3
=
value
;
}
public
static
ModualPool
.
pcMachine
cStirrer4
{
get
=>
cWestTransitPoolStirrer4
;
set
=>
cWestTransitPoolStirrer4
=
value
;
}
}
}
}
ModbusDemo/application/AutoControl.cs
View file @
5e2f988a
...
...
@@ -9,7 +9,8 @@ using ModbusDemo.Modular;
using
ModbusDemo.MessageFormat
;
using
ModbusDemo.Common
;
using
System.IO
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
ModbusDemo.application
{
public
class
AutoControl
...
...
@@ -104,7 +105,6 @@ namespace ModbusDemo.application
TimeSpan
timespan
=
ETime
.
Elapsed
;
// 获取当前实例测量得出的总时间
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
if
(
Eenabl
==
true
)
{
if
(
timerun
==
false
)
...
...
@@ -310,9 +310,35 @@ namespace ModbusDemo.application
Control
usEcontrolB
=
new
Control
();
Control
usWcontrol
=
new
Control
();
Control
usWcontrolB
=
new
Control
();
FileInfo
file
=
new
FileInfo
(
InIHelper
.
FileName
);
if
(
file
.
Length
!=
0
)
{
usEcontrol
.
modularx
=
InIHelper
.
ReadConfig
<
int
>(
"Channel number"
,
"东液位通道"
);
usWcontrol
.
modularx
=
InIHelper
.
ReadConfig
<
int
>(
"Channel number"
,
"西液位通道"
);
usWcontrol
.
maxLevel
=
InIHelper
.
ReadConfig
<
float
>(
"MaxLevel"
,
"西·中转池"
);
usWcontrol
.
minLevel
=
InIHelper
.
ReadConfig
<
float
>(
"MinLevel"
,
"西·中转池"
);
usEcontrol
.
maxLevel
=
InIHelper
.
ReadConfig
<
float
>(
"MaxLevel"
,
"东·中转池"
);
usEcontrol
.
minLevel
=
InIHelper
.
ReadConfig
<
float
>(
"MinLevel"
,
"东·中转池"
);
usEcontrol
.
realTimeLevel
=
ModualPoll
.
cx18x
.
sX18xDataStruct
[
usEcontrol
.
modularx
].
dNowConvertData
[
0
];
usWcontrol
.
realTimeLevel
=
ModualPoll
.
cx18x
.
sX18xDataStruct
[
usWcontrol
.
modularx
].
dNowConvertData
[
0
];
CriticalValueMonitoring
(
ref
usEcontrol
,
true
,
"东·中转池"
,
out
usEcontrolB
);
CriticalValueMonitoring
(
ref
usWcontrol
,
true
,
"西·中转池"
,
out
usWcontrolB
);
Automatic_control
(
usWcontrolB
.
status
,
usEcontrolB
.
status
);
}
while
(
true
)
{
FileInfo
file
=
new
FileInfo
(
InIHelper
.
FileName
);
if
(
ModualControl
.
cPoolLevelConfig
.
Count
!=
0
)
{
for
(
int
i
=
0
;
i
<
ModualControl
.
cPoolLevelConfig
.
Count
;
i
++)
...
...
@@ -369,38 +395,13 @@ namespace ModbusDemo.application
Automatic_control
(
usWcontrolB
.
status
,
usEcontrolB
.
status
);
}
else
if
(
file
.
Length
!=
0
)
{
usEcontrol
.
modularx
=
InIHelper
.
ReadConfig
<
int
>(
"Channel number"
,
"东液位通道"
);
usWcontrol
.
modularx
=
InIHelper
.
ReadConfig
<
int
>(
"Channel number"
,
"西液位通道"
);
usWcontrol
.
maxLevel
=
InIHelper
.
ReadConfig
<
float
>(
"MaxLevel"
,
"西·中转池"
);
usWcontrol
.
minLevel
=
InIHelper
.
ReadConfig
<
float
>(
"MinLevel"
,
"西·中转池"
);
usEcontrol
.
maxLevel
=
InIHelper
.
ReadConfig
<
float
>(
"MaxLevel"
,
"东·中转池"
);
usEcontrol
.
minLevel
=
InIHelper
.
ReadConfig
<
float
>(
"MinLevel"
,
"东·中转池"
);
usEcontrol
.
realTimeLevel
=
ModualPoll
.
cx18x
.
sX18xDataStruct
[
usEcontrol
.
modularx
].
dNowConvertData
[
0
];
usWcontrol
.
realTimeLevel
=
ModualPoll
.
cx18x
.
sX18xDataStruct
[
usWcontrol
.
modularx
].
dNowConvertData
[
0
];
CriticalValueMonitoring
(
ref
usEcontrol
,
true
,
"东·中转池"
,
out
usEcontrolB
);
CriticalValueMonitoring
(
ref
usWcontrol
,
true
,
"西·中转池"
,
out
usWcontrolB
);
Automatic_control
(
usWcontrolB
.
status
,
usEcontrolB
.
status
);
}
else
{
usWcontrol
.
status
=
false
;
usEcontrol
.
status
=
false
;
Automatic_control
(
usWcontrol
.
status
,
usEcontrol
.
status
);
}
Thread
.
Sleep
(
100
);
}
}
}
...
...
ModbusDemo/windows/Form1.cs
View file @
5e2f988a
...
...
@@ -37,7 +37,7 @@ namespace ModbusDemo
System
.
Timers
.
Timer
MQTTTimer
=
new
System
.
Timers
.
Timer
();
BackgroundWorker
m_bgw0
=
new
BackgroundWorker
();
bool
m_Isbgw0_CanContinueRun
=
true
;
bool
bCre
ta
Thead
=
false
;
bool
bCre
at
Thead
=
false
;
public
static
ModbusDemo
.
windows
.
Totxt
totxt
=
new
windows
.
Totxt
(
AppDomain
.
CurrentDomain
.
BaseDirectory
+
@"/log/Log.txt"
);
public
Form1
()
...
...
@@ -84,12 +84,12 @@ namespace ModbusDemo
public
const
string
mqttSubscribeControlTopic
=
"Witium/WTDS78X/"
+
mqttSn
+
"/Ctrl"
;
public
const
string
mqttBackTopic
=
"Witium/WTDS78X/"
+
mqttSn
+
"/Back"
;
public
const
string
mqttCfgTopic
=
"Witium/WTDS78X/"
+
mqttSn
+
"/Config"
;
public
const
string
mqttCfgResTopic
=
"Witium/WTDS78X/"
+
mqttSn
+
"/
CfgRes
"
;
public
const
string
mqttCfgResTopic
=
"Witium/WTDS78X/"
+
mqttSn
+
"/
Back
"
;
public
const
string
mqttTopic
=
"Witium/WTDS78X/"
+
mqttSn
+
"/Data"
;
public
const
string
sAlarmTopic
=
"Witium/WTDS78X/"
+
mqttSn
+
"/Alarm"
;
string
mqttData
;
//数据
string
mqttData_Back
;
//数据
private
IMqttClient
mqttClient
=
null
;
private
static
IMqttClient
mqttClient
=
null
;
private
bool
isReconnect
=
true
;
private
void
SetMqtt
()
{
...
...
@@ -141,29 +141,30 @@ namespace ModbusDemo
private
Thread
ModbusControlThread
;
private
Thread
MqttReceiveThread
;
public
List
<
string
>
ListHandle
=
new
List
<
string
>();
private
async
Task
Publish
()
private
static
object
SenPackage
=
new
object
();
public
static
async
Task
Publish
(
string
strTopic
,
string
strJsonPackage
)
{
if
(
mqttClient
.
IsConnected
==
true
)
{
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
mqtt
Topic
)
.
WithPayload
(
mqttData
)
.
WithTopic
(
str
Topic
)
.
WithPayload
(
strJsonPackage
)
.
WithAtMostOnceQoS
()
.
WithRetainFlag
(
false
)
.
Build
();
if
(
mqttData
!=
null
)
if
(
strJsonPackage
!=
null
)
{
await
mqttClient
.
PublishAsync
(
message
);
await
mqttClient
.
PublishAsync
(
message
);
}
}
}
p
rivate
void
vControlResponseBack
(
)
p
ublic
static
void
vControlResponseBack
(
string
strTopic
,
string
strJsonPackage
)
{
if
(
mqttClient
.
IsConnected
==
true
)
{
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
mqttBack
Topic
)
.
WithPayload
(
mqttData_Back
)
.
WithTopic
(
str
Topic
)
.
WithPayload
(
strJsonPackage
)
.
WithAtLeastOnceQoS
()
.
WithRetainFlag
(
false
)
.
Build
();
...
...
@@ -171,19 +172,6 @@ namespace ModbusDemo
}
}
private
async
Task
vCfgResponseBack
(
string
data
)
{
if
(
mqttClient
.
IsConnected
==
true
)
{
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
mqttCfgResTopic
)
.
WithPayload
(
data
)
.
WithAtMostOnceQoS
()
.
WithRetainFlag
(
false
)
.
Build
();
await
mqttClient
.
PublishAsync
(
message
);
}
}
private
async
Task
Subscribe
()
{
if
(!
mqttClient
.
IsConnected
)
...
...
@@ -263,12 +251,9 @@ namespace ModbusDemo
}
private
void
MqttClient_Connected
(
object
sender
,
EventArgs
e
)
{
Invoke
(
(
new
Action
(
()
=>
Invoke
(
(
new
Action
(
async
()
=>
{
//txtReceiveMessage.Clear();
txtReceiveMessage
.
AppendText
(
"已连接到MQTT服务器!"
+
Environment
.
NewLine
);
//totxt.Log("已连接到MQTT服务器!" + Environment.NewLine);
//Console.WriteLine("已连接到MQTT服务器!" + Environment.NewLine);
txtReceiveMessage
.
AppendText
(
"已连接到MQTT服务器!"
+
Environment
.
NewLine
);
})));
}
private
void
MqttClient_Disconnected
(
object
sender
,
EventArgs
e
)
...
...
@@ -279,11 +264,7 @@ namespace ModbusDemo
DateTime
curTime
=
new
DateTime
();
curTime
=
DateTime
.
UtcNow
;
txtReceiveMessage
.
AppendText
(
$">> [
{
curTime
.
ToLongTimeString
()}
]"
);
//totxt.Log($">> [{curTime.ToLongTimeString()}]");
txtReceiveMessage
.
AppendText
(
"已断开MQTT连接!"
+
Environment
.
NewLine
);
//totxt.Log("已断开MQTT连接!" + Environment.NewLine);
//Console.WriteLine("已断开MQTT连接!" + Environment.NewLine);
})));
//Reconnecting
...
...
@@ -293,8 +274,6 @@ namespace ModbusDemo
{
txtReceiveMessage
.
AppendText
(
"正在尝试重新连接"
+
Environment
.
NewLine
);
totxt
.
Log
(
"正在尝试重新连接"
+
Environment
.
NewLine
);
await
Subscribe
();
//Console.WriteLine("正在尝试重新连接" + Environment.NewLine);
})));
...
...
@@ -311,12 +290,11 @@ namespace ModbusDemo
try
{
await
mqttClient
.
ConnectAsync
(
options
);
await
Subscribe
();
}
catch
{
txtReceiveMessage
.
AppendText
(
"### RECONNECTING FAILED ###"
+
Environment
.
NewLine
);
//totxt.Log("### RECONNECTING FAILED ###" + Environment.NewLine);
//Console.WriteLine("### RECONNECTING FAILED ###" + Environment.NewLine);
}
})));
}
...
...
@@ -326,7 +304,6 @@ namespace ModbusDemo
{
txtReceiveMessage
.
AppendText
(
"已下线!"
+
Environment
.
NewLine
);
totxt
.
Log
(
"已下线!"
+
Environment
.
NewLine
);
//Console.WriteLine("已下线!" + Environment.NewLine);
})));
}
}
...
...
@@ -358,7 +335,7 @@ namespace ModbusDemo
else
if
(
e
.
ApplicationMessage
.
Topic
==
mqttCfgTopic
)
{
ModualControl
.
vPoolLevelParse
(
stConvertString
,
out
mqttData_Back
);
await
vCfgResponseBack
(
mqttData_Back
);
await
Publish
(
mqttCfgResTopic
,
mqttData_Back
);
}
})));
}
...
...
@@ -369,7 +346,7 @@ namespace ModbusDemo
for
(
int
i
=
0
;
i
<
ListHandle
.
Count
;
i
++)
{
ModualControl
.
vGetaWay_Receive_Control
(
ListHandle
[
i
],
out
mqttData_Back
);
vControlResponseBack
();
vControlResponseBack
(
mqttBackTopic
,
mqttData_Back
);
ListHandle
.
Remove
(
ListHandle
[
i
]);
}
Thread
.
Sleep
(
100
);
...
...
@@ -396,7 +373,7 @@ namespace ModbusDemo
private
void
Sendout
()
{
Control
.
CheckForIllegalCrossThreadCalls
=
false
;
MQTTTimer
.
Interval
=
20000
l
;
//120500
MQTTTimer
.
Interval
=
20000
;
//120500
MQTTTimer
.
Enabled
=
true
;
MQTTTimer
.
AutoReset
=
true
;
//设置是执行一次(false)还是一直执行(true);
MQTTTimer
.
Start
();
...
...
@@ -404,7 +381,7 @@ namespace ModbusDemo
{
try
{
await
Publish
();
await
Publish
(
mqttTopic
,
mqttData
);
}
catch
(
Exception
ex
)
{
...
...
@@ -1062,17 +1039,17 @@ namespace ModbusDemo
ModbusComm
.
Modbus
.
Transport
.
WriteTimeout
=
1000
;
ModbusComm
.
Modbus
.
Transport
.
WaitToRetryMilliseconds
=
0
;
//
t_AutoControl = new Thread(AtuoControl_run);
//
t_AutoControl.IsBackground = true;
//
t_AutoControl.Start();
t_AutoControl
=
new
Thread
(
AtuoControl_run
);
t_AutoControl
.
IsBackground
=
true
;
t_AutoControl
.
Start
();
modbus_Timer
.
Enabled
=
true
;
btOpenCOM
.
Enabled
=
false
;
btCloseCOM
.
Enabled
=
true
;
if
(
bCre
ta
Thead
==
false
)
if
(
bCre
at
Thead
==
false
)
{
bCre
ta
Thead
=
true
;
bCre
at
Thead
=
true
;
ModbusPollThread
=
new
Thread
(
vModbusPoll
);
ModbusPollThread
.
Start
();
ModbusPollThread
.
Priority
=
ThreadPriority
.
Normal
;
...
...
@@ -1104,12 +1081,18 @@ namespace ModbusDemo
}
private
async
void
run
()
{
comPort
.
PortName
=
"COM2"
;
if
(
LOCALDEBUG
==
true
)
{
comPort
.
PortName
=
"COM6"
;
}
else
{
comPort
.
PortName
=
"COM6"
;
}
comPort
.
BaudRate
=
9600
;
comPort
.
Parity
=
Parity
.
None
;
comPort
.
StopBits
=
StopBits
.
One
;
comPort
.
DataBits
=
8
;
try
{
comPort
.
Open
();
...
...
@@ -1124,35 +1107,32 @@ namespace ModbusDemo
ModbusComm
.
Modbus
.
Transport
.
WriteTimeout
=
1000
;
ModbusComm
.
Modbus
.
Transport
.
WaitToRetryMilliseconds
=
0
;
//t_AutoControl = new Thread(AtuoControl_run)
//{
// IsBackground = true
//};
//t_AutoControl.Start();
modbus_Timer
.
Enabled
=
true
;
btOpenCOM
.
Enabled
=
false
;
btCloseCOM
.
Enabled
=
true
;
if
(
bCre
ta
Thead
==
false
)
if
(
bCre
at
Thead
==
false
)
{
if
(
bCretaThead
==
false
)
{
bCretaThead
=
true
;
ModbusPollThread
=
new
Thread
(
vModbusPoll
);
ModbusPollThread
.
Start
();
ModbusPollThread
.
Priority
=
ThreadPriority
.
Normal
;
bCreatThead
=
true
;
ModbusPollThread
=
new
Thread
(
vModbusPoll
);
ModbusPollThread
.
Start
();
ModbusPollThread
.
Priority
=
ThreadPriority
.
Normal
;
ModbusControlThread
=
new
Thread
(
ModualControl
.
vControl_Poll
);
ModbusControlThread
.
Start
();
ModbusControlThread
.
Priority
=
ThreadPriority
.
BelowNormal
;
ModbusControlThread
=
new
Thread
(
ModualControl
.
vControl_Poll
);
ModbusControlThread
.
Start
();
ModbusControlThread
.
Priority
=
ThreadPriority
.
BelowNormal
;
MqttReceiveThread
=
new
Thread
(
vMqtt_Receive_Handle
);
MqttReceiveThread
.
Start
();
MqttReceiveThread
.
Priority
=
ThreadPriority
.
AboveNormal
;
MqttReceiveThread
=
new
Thread
(
vMqtt_Receive_Handle
);
MqttReceiveThread
.
Start
();
MqttReceiveThread
.
Priority
=
ThreadPriority
.
AboveNormal
;
Task
task1
=
Task
.
Factory
.
StartNew
(
async
()
=>
{
await
ModualControl
.
vControl_Res_Poll
();});
}
Task
task1
=
Task
.
Factory
.
StartNew
(
async
()
=>
{
await
ModualControl
.
vControl_Res_Poll
();});
t_AutoControl
=
new
Thread
(
AtuoControl_run
)
{
IsBackground
=
true
};
t_AutoControl
.
Start
();
t_AutoControl
.
Priority
=
ThreadPriority
.
Normal
;
}
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" =>Open "
+
comPort
.
PortName
+
" sucessfully!"
);
await
Subscribe
();
...
...
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