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
4a5bdbd8
Commit
4a5bdbd8
authored
Jun 20, 2019
by
leon.huang
Browse files
Options
Browse Files
Download
Plain Diff
start test
parents
bfa5625c
de89515f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
375 additions
and
107 deletions
+375
-107
ModbusComm.cs
ModbusDemo/MessageFormat/ModbusComm.cs
+8
-3
ModualControl.cs
ModbusDemo/MessageFormat/ModualControl.cs
+212
-32
ModbusDemo.csproj
ModbusDemo/ModbusDemo.csproj
+0
-6
ModualPoll.cs
ModbusDemo/Modular/ModualPoll.cs
+8
-3
AllPond.cs
ModbusDemo/application/AllPond.cs
+3
-3
AutoControl.cs
ModbusDemo/application/AutoControl.cs
+76
-28
ControlMap.cs
ModbusDemo/application/ControlMap.cs
+26
-5
ModualPool.cs
ModbusDemo/application/ModualPool.cs
+5
-4
Form1.cs
ModbusDemo/windows/Form1.cs
+37
-23
No files found.
ModbusDemo/MessageFormat/ModbusComm.cs
View file @
4a5bdbd8
...
...
@@ -28,9 +28,10 @@ namespace ModbusDemo.MessageFormat
MB_EMASTERSENT
,
MB_RTUERNOERR
}
public
static
ModbusMaster
Modbus
;
public
static
ushort
usCommunFailTimes
=
0
;
static
object
oLock
=
new
object
();
public
static
ModbusMaster
Modbus
;
public
static
ushort
usCommunFailTimes
=
0
;
private
static
object
oLock
=
new
object
();
public
static
eModbusErrorCode
Modbus_ReadHoldingRegistersTask
(
out
ushort
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoints
)
{
lock
(
oLock
)
...
...
@@ -53,6 +54,7 @@ namespace ModbusDemo.MessageFormat
OutputValue
=
new
ushort
[
numberOfPoints
];
ModbusErrorCode
=
eModbusErrorCode
.
MB_ETIMEDOUT
;
usCommunFailTimes
++;
Console
.
WriteLine
(
slaveAddress
.
ToString
());
}
//The server return error code.
//You can get the function code and exception code.
...
...
@@ -137,6 +139,7 @@ namespace ModbusDemo.MessageFormat
OutputValue
=
new
bool
[
numberOfPoints
];
ModbusErrorCode
=
eModbusErrorCode
.
MB_ETIMEDOUT
;
usCommunFailTimes
++;
Console
.
WriteLine
(
slaveAddress
.
ToString
());
}
//The server return error code.
//You can get the function code and exception code.
...
...
@@ -220,6 +223,7 @@ namespace ModbusDemo.MessageFormat
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
+
"Modbus_WriteSingleCoil"
);
ModbusErrorCode
=
eModbusErrorCode
.
MB_ETIMEDOUT
;
usCommunFailTimes
++;
Console
.
WriteLine
(
slaveAddress
.
ToString
());
}
//The server return error code.
//You can get the function code and exception code.
...
...
@@ -302,6 +306,7 @@ namespace ModbusDemo.MessageFormat
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
+
"Modbus_WriteMultipleCoils"
);
ModbusErrorCode
=
eModbusErrorCode
.
MB_ETIMEDOUT
;
usCommunFailTimes
++;
Console
.
WriteLine
(
slaveAddress
.
ToString
());
}
//The server return error code.
//You can get the function code and exception code.
...
...
ModbusDemo/MessageFormat/ModualControl.cs
View file @
4a5bdbd8
...
...
@@ -13,6 +13,7 @@ using ModbusDemo.Modular;
using
ModbusDemo.Common
;
using
System.Threading
;
using
ModbusDemo.application
;
using
System.Windows.Forms
;
namespace
ModbusDemo.MessageFormat
{
public
class
ModualControl
...
...
@@ -142,7 +143,7 @@ namespace ModbusDemo.MessageFormat
try
{
cControl
=
JsonConvert
.
DeserializeObject
<
MqttRoot
>(
sDataString
);
jsonObj
=
JObject
.
Parse
(
sDataString
);
jsonObj
=
JObject
.
Parse
(
sDataString
);
}
catch
(
Exception
exception
)
{
...
...
@@ -150,7 +151,7 @@ namespace ModbusDemo.MessageFormat
}
for
(
int
i
=
0
;
i
<
cControl
.
ss
.
Count
;
i
++)
{
bool
[]
b
tReadTempData
=
new
bool
[
6
]
;
bool
[]
b
OperationStatus
=
new
bool
[
8
]
{
false
,
false
,
false
,
false
,
false
,
false
,
false
,
false
}
;
ModualCntrol
cModualCntrol
=
new
ModualCntrol
{
sbModbusID
=
byte
.
Parse
(
cControl
.
ss
[
i
].
addr
),
...
...
@@ -185,20 +186,27 @@ namespace ModbusDemo.MessageFormat
{
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
;
cModualCntrol
.
strOperationChannelName
=
strOperation
.
ToArray
();
if
(
ControlMap
.
bControl_Map
(
cModualCntrol
.
bOpenMachine
,
cModualCntrol
.
sbModbusID
,
cModualCntrol
.
bControlData
,
cModualCntrol
.
strOperationChannelName
[
0
]))
for
(
int
j
=
0
;
j
<
cModualCntrol
.
strOperationChannelName
.
Count
();
j
++)
{
cModualCntrol
.
bControlStatus
=
ControlMap
.
bDelege_Operation
(
cModualCntrol
.
bControlData
);
}
else
{
cModualCntrol
.
bControlStatus
=
false
;
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
{
cModualCntrol
.
bControlStatus
=
false
;
bOperationStatus
[
j
]
=
false
;
}
}
//Form1.vSuspend_Poll_Control(false);
}
if
(
cModualCntrol
.
bControlStatus
==
true
)
if
(
cModualCntrol
.
bControlStatus
==
true
&&
cModualCntrol
.
strOperationChannelName
.
Count
()
<=
1
)
{
lock
(
obLock
)
{
...
...
@@ -209,13 +217,13 @@ namespace ModbusDemo.MessageFormat
}
else
if
(
cModualCntrol
.
bStartControl
==
false
&&
cModualCntrol
.
ulStartTime
!=
0
)
{
liModuualControl
.
Add
(
cModualCntrol
);
liModuualControl
.
Add
(
cModualCntrol
);
}
}
}
for
(
int
k
=
0
;
k
<
8
;
k
++)
{
if
(
cModualCntrol
.
bControlBit
[
k
]
==
true
&&
cModualCntrol
.
bControlStatus
==
true
)
if
(
cModualCntrol
.
bControlBit
[
k
]
==
true
&&
(
cModualCntrol
.
bControlStatus
==
true
||
bOperationStatus
[
k
]
==
true
)
)
{
string
str
=
"d"
+
k
.
ToString
();
jsonObj
[
"ss"
][
i
][
"op"
][
str
]
=
1
;
...
...
@@ -230,13 +238,13 @@ namespace ModbusDemo.MessageFormat
stResponseData
=
jsonObj
.
ToString
();
}
public
static
void
vControl_Poll
()
public
static
void
vControl_Poll
()
//async Task
{
while
(
true
)
{
lock
(
obLock
)
{
for
(
sbyte
i
=
0
;
i
<
liModuualControl
.
Count
;
i
++)
for
(
sbyte
i
=
0
;
i
<
liModuualControl
.
Count
;
i
++)
{
if
(
liModuualControl
[
i
].
bStartControl
==
false
)
{
...
...
@@ -244,8 +252,8 @@ namespace ModbusDemo.MessageFormat
{
liModuualControl
[
i
].
bStartControl
=
true
;
bool
[]
bControlData
;
liModuualControl
[
i
].
bControlStatus
=
ModualPoll
.
bGet_channel_Value
<
bool
>(
liModuualControl
[
i
].
sbModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
if
(
ControlMap
.
bControl_Map
(
liModuualControl
[
i
].
bOpenMachine
,
liModuualControl
[
i
].
sbModbusID
,
liModuualControl
[
i
].
bControlData
,
liModuualControl
[
i
].
strOperationChannelName
[
0
]))
liModuualControl
[
i
].
bControlStatus
=
ModualPoll
.
bGet_channel_Value
<
bool
>(
liModuualControl
[
i
].
sbModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
if
(
ControlMap
.
bControl_Map
(
liModuualControl
[
i
].
bOpenMachine
,
liModuualControl
[
i
].
sbModbusID
,
liModuualControl
[
i
].
bControlData
,
liModuualControl
[
i
].
strOperationChannelName
[
0
]))
{
liModuualControl
[
i
].
bControlStatus
=
ControlMap
.
bDelege_Operation
(
bControlData
);
}
...
...
@@ -256,8 +264,17 @@ namespace ModbusDemo.MessageFormat
if
((
liModuualControl
[
i
].
usDurationTime
+
liModuualControl
[
i
].
ulStartTime
)
<=
Form1
.
GetTimeStamp
())
{
bool
[]
bControlData
;
liModuualControl
[
i
].
bControlStatus
=
ModualPoll
.
bGet_channel_Value
<
bool
>(
liModuualControl
[
i
].
sbModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
if
(
ControlMap
.
bControl_Map
(
liModuualControl
[
i
].
bOpenMachine
,
liModuualControl
[
i
].
sbModbusID
,
liModuualControl
[
i
].
bControlData
,
liModuualControl
[
i
].
strOperationChannelName
[
0
]))
string
str
;
liModuualControl
[
i
].
bControlStatus
=
ModualPoll
.
bGet_channel_Value
<
bool
>(
liModuualControl
[
i
].
sbModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
for
(
int
j
=
0
;
j
<
8
;
j
++)
{
str
=
"d"
+
j
.
ToString
();
if
(
str
==
liModuualControl
[
i
].
strOperationChannelName
[
0
])
{
liModuualControl
[
i
].
bControlData
[
j
]
=
!
liModuualControl
[
i
].
bControlData
[
j
];
}
}
if
(
ControlMap
.
bControl_Map
(!
liModuualControl
[
i
].
bOpenMachine
,
liModuualControl
[
i
].
sbModbusID
,
liModuualControl
[
i
].
bControlData
,
liModuualControl
[
i
].
strOperationChannelName
[
0
]))
{
liModuualControl
[
i
].
bControlStatus
=
ControlMap
.
bDelege_Operation
(
bControlData
);
}
...
...
@@ -266,33 +283,193 @@ namespace ModbusDemo.MessageFormat
}
}
}
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
}
Thread
.
Sleep
(
100
);
}
}
public
static
Task
vControl_Res_Poll
()
{
while
(
true
)
{
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
true
)
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
<
OPENCURRENT
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
<
OPENCURRENT
)
bool
[]
bControlData
;
if
(
ModualPoll
.
bGet_channel_Value
<
bool
>(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
)
==
true
)
{
bool
[]
bControlData
;
if
(
ModualPoll
.
bGet_channel_Value
<
bool
>(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
)
==
true
)
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bClose_Machine
(
bControlData
)
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bClose_Machine
(
bControlData
)
==
true
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
}
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
false
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
>
CLOSECURRENT
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
Thread
.
Sleep
(
200
);
}
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
<
OPENCURRENT
)
{
bool
[]
bControlData
;
if
(
ModualPoll
.
bGet_channel_Value
<
bool
>(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
)
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bClose_Machine
(
bControlData
)
==
true
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
false
)
}
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
false
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
>
CLOSECURRENT
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
Thread
.
Sleep
(
200
);
}
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
<
OPENCURRENT
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
>
CLOSECURRENT
)
bool
[]
bControlData
;
if
(
ModualPoll
.
bGet_channel_Value
<
bool
>(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
)
==
true
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bClose_Machine
(
bControlData
)
==
true
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
}
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
false
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
>
CLOSECURRENT
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
Thread
.
Sleep
(
200
);
}
Thread
.
Sleep
(
100
);
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
<
OPENCURRENT
)
{
bool
[]
bControlData
;
if
(
ModualPoll
.
bGet_channel_Value
<
bool
>(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
)
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bClose_Machine
(
bControlData
)
==
true
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
}
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
false
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
>
CLOSECURRENT
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
Thread
.
Sleep
(
200
);
}
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
<
OPENCURRENT
)
{
bool
[]
bControlData
;
if
(
ModualPoll
.
bGet_channel_Value
<
bool
>(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
)
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bClose_Machine
(
bControlData
)
==
true
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
}
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
false
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
>
CLOSECURRENT
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
Thread
.
Sleep
(
200
);
}
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
<
OPENCURRENT
)
{
bool
[]
bControlData
;
if
(
ModualPoll
.
bGet_channel_Value
<
bool
>(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
)
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bClose_Machine
(
bControlData
)
==
true
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
}
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
false
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
>
CLOSECURRENT
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
for
(
sbyte
sbEastTransitPoolIndex
=
0
;
sbEastTransitPoolIndex
<
AllPond
.
EastTransitPoolList
.
Count
();
sbEastTransitPoolIndex
++)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
<
OPENCURRENT
)
{
bool
[]
bControlData
;
if
(
ModualPoll
.
bGet_channel_Value
<
bool
>(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
out
bControlData
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
)
==
true
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bClose_Machine
(
bControlData
)
==
true
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
}
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadRefControl
==
true
&&
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
bHadOpenPumb
==
false
)
{
if
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
dChannelCurrent
>
CLOSECURRENT
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
true
,
1
,
AllPond
.
EastTransitPoolList
[
sbEastTransitPoolIndex
].
strChannelNumber
);
}
}
}
Thread
.
Sleep
(
1000
);
}
}
public
static
modual
.
eModualType
eModdusId_Find_ModualType
(
string
sModbusID
)
{
...
...
@@ -322,14 +499,16 @@ namespace ModbusDemo.MessageFormat
return
modual
.
eModualType
.
IDLE
;
}
public
static
bool
bOperation_Machine
(
bool
bOpenMachine
,
byte
sbModbusID
,
bool
[]
bControlData
,
bool
[]
bControlBit
,
byte
byResModualID
,
string
stResChannel
)
public
static
bool
bOperation_Machine
(
bool
bOpenMachine
,
byte
sbModbusID
,
bool
[]
bControlData
,
bool
[]
bControlBit
,
out
bool
bHadOpenMachine
,
byte
byResModualID
,
string
stResChannel
)
{
bHadOpenMachine
=
true
;
bool
bControlStatus
=
true
;
if
(
ModualPoll
.
bSet_All_Channel_Value
(
sbModbusID
,
bControlData
)
==
true
)
{
if
(
bOpenMachine
==
true
&&
stResChannel
!=
null
)
{
double
[]
dConvertData
;
bHadOpenMachine
=
true
;
Thread
.
Sleep
(
1000
);
bControlStatus
=
ModualPoll
.
bGet_channel_Value
<
double
>(
byResModualID
,
out
dConvertData
,
stResChannel
);
if
(
dConvertData
[
0
]
>
OPENCURRENT
&&
bControlStatus
==
true
)
...
...
@@ -344,6 +523,7 @@ namespace ModbusDemo.MessageFormat
else
if
(
bOpenMachine
==
false
&&
stResChannel
!=
null
)
{
double
[]
dConvertData
;
bHadOpenMachine
=
false
;
Thread
.
Sleep
(
1000
);
bControlStatus
=
ModualPoll
.
bGet_channel_Value
<
double
>(
byResModualID
,
out
dConvertData
,
stResChannel
);
if
(
dConvertData
[
0
]
<
CLOSECURRENT
&&
bControlStatus
==
true
)
...
...
ModbusDemo/ModbusDemo.csproj
View file @
4a5bdbd8
...
...
@@ -178,15 +178,9 @@
</PropertyGroup>
<Import
Project=
"$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets"
Condition=
"$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' != ''"
/>
<Import
Project=
"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.Sql.UnitTesting.targets"
Condition=
"$(VisualStudioVersion) != '15.0' And '$(SQLDBExtensionsRefPath)' == ''"
/>
<!-- <<<<<<< HEAD -->
<!-- <<<<<<< HEAD -->
<!-- ======= -->
<!-- ======= -->
<!-- >>>>>>> 5635bdf708c90bb2146f99466d1145dda5dabb37 -->
<PropertyGroup>
<SsdtUnitTestVersion>
3.1
</SsdtUnitTestVersion>
</PropertyGroup>
<!-- >>>>>>> origin/master -->
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
...
...
ModbusDemo/Modular/ModualPoll.cs
View file @
4a5bdbd8
...
...
@@ -2,6 +2,7 @@
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
ModbusDemo.MessageFormat
;
using
ModbusDemo.Common
;
...
...
@@ -35,7 +36,7 @@ namespace ModbusDemo.Modular
public
static
_414P
c14formulasormual
=
new
_414P
();
#if DEBUG_TEST
public
const
byte
byX18xNumber
=
1
;
public
static
byte
[]
byX18xIdlist
=
{
13
};
public
static
byte
[]
byX18xIdlist
=
{
13
,
};
private
static
modual
.
eX18xSensorChannelType
[,]
sX18xChannelType
=
new
modual
.
eX18xSensorChannelType
[
byX18xNumber
,
byX18xReadDataNumber
]
{
{
modual
.
eX18xSensorChannelType
.
NormalCurrent
,
modual
.
eX18xSensorChannelType
.
Null
,
modual
.
eX18xSensorChannelType
.
NormalCurrent
,
modual
.
eX18xSensorChannelType
.
Null
,
modual
.
eX18xSensorChannelType
.
Null
,
modual
.
eX18xSensorChannelType
.
Null
,
modual
.
eX18xSensorChannelType
.
Null
,
modual
.
eX18xSensorChannelType
.
Null
}
};
#else
public
const
byte
byX18xNumber
=
6
;
...
...
@@ -58,8 +59,8 @@ namespace ModbusDemo.Modular
private
static
_418X
c18xformulasormual
=
new
_418X
();
#if DEBUG_TEST
public
const
byte
byX78cNumber
=
1
;
public
static
byte
[]
byX78cIdlist
=
{
20
};
public
const
byte
byX78cNumber
=
1
;
public
static
byte
[]
byX78cIdlist
=
{
20
};
#else
public
const
byte
byX78cNumber
=
0
;
public
static
byte
[]
byX78cIdlist
=
{
11
,
20
,
33
,
34
,
55
,
56
};
...
...
@@ -148,6 +149,7 @@ namespace ModbusDemo.Modular
cx14P
.
sX14pDataStruct
[
i
].
dBeforeConvertData
[
j
]
=
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
j
];
}
cx14P
.
sX14PAlarmStruct
[
i
].
bDataNotFirstIncreaseOrDecrease
=
true
;
Thread
.
Sleep
(
100
);
}
for
(
byte
i
=
0
;
i
<
byX18xNumber
;
i
++)
...
...
@@ -227,6 +229,7 @@ namespace ModbusDemo.Modular
cx18x
.
sX18xDataStruct
[
i
].
dBeforeConvertData
[
j
]
=
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
j
];
}
cx18x
.
sX18xAlarmstruct
[
i
].
bDataNotFirstIncreaseOrDecrease
=
true
;
Thread
.
Sleep
(
100
);
}
for
(
byte
i
=
0
;
i
<
byX78cNumber
;
i
++)
{
...
...
@@ -249,6 +252,7 @@ namespace ModbusDemo.Modular
cx78c
.
sX78cAlarmStruct
[
i
].
usCommFailTimes
[
j
]
=
0
;
}
}
Thread
.
Sleep
(
100
);
}
for
(
byte
i
=
0
;
i
<
byX66cNumber
;
i
++)
...
...
@@ -271,6 +275,7 @@ namespace ModbusDemo.Modular
cx66c
.
sX66cAlarmStruct
[
i
].
usCommFailTimes
[
j
]
=
0
;
}
}
Thread
.
Sleep
(
100
);
}
}
public
static
string
stAll_Poll_Package
()
...
...
ModbusDemo/application/AllPond.cs
View file @
4a5bdbd8
...
...
@@ -19,9 +19,9 @@ namespace ModbusDemo.application
strChannelNumber
=
new
string
[]
{
"d1"
,
"d2"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
fals
e
,
byResModbusID
=
0
,
strResChannelNumber
=
null
bHadRefControl
=
tru
e
,
byResModbusID
=
13
,
strResChannelNumber
=
"d0"
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolSouthWater
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolSouthWater"
,
cEastTransitPoolSouthWaterBase
);
...
...
ModbusDemo/application/AutoControl.cs
View file @
4a5bdbd8
...
...
@@ -35,15 +35,11 @@ namespace ModbusDemo.application
public
string
Name
;
public
double
StatusTime
;
public
int
modularx
;
public
byte
modbusID
;
}
public
static
void
CriticalValueMonitoring
(
ref
Control
usControl
,
bool
Enabl
,
string
Affiliation
,
out
Control
control
)
{
//Control usControl = new Control
//{
// Enablation = Enabl,
// Name = Affiliation,
//};
if
(
usControl
.
Enablation
==
true
)
{
if
(
usControl
.
maxLevel
!=
0.0
&&
usControl
.
minLevel
!=
0.0
)
...
...
@@ -67,7 +63,6 @@ namespace ModbusDemo.application
}
else
if
(
usControl
.
realTimeLevel
<
usControl
.
maxLevel
&&
usControl
.
realTimeLevel
>
(
usControl
.
minLevel
+
usControl
.
minLevel
*
0.15
))
{
//usControl.status = true;
usControl
.
normal
=
true
;
}
...
...
@@ -99,7 +94,7 @@ namespace ModbusDemo.application
public
static
bool
Wtimerun
=
false
;
static
System
.
Diagnostics
.
Stopwatch
ETime
=
new
System
.
Diagnostics
.
Stopwatch
();
static
System
.
Diagnostics
.
Stopwatch
WTime
=
new
System
.
Diagnostics
.
Stopwatch
();
//public static string
public
static
void
Automatic_control
(
bool
Eenabl
,
bool
Wenabl
)
{
TimeSpan
Wtime
=
WTime
.
Elapsed
;
...
...
@@ -146,36 +141,54 @@ namespace ModbusDemo.application
}
if
(
timespan
.
TotalMinutes
>
2
)
{
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
],
16
,
state_OFF
)
ModualAlarm
.
vSet_Modual_Alarm
(
EmodbusId
[
i
],
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
|
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelRunOverTimeError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
ModualAlarm
.
vSet_Modual_Alarm
(
EmodbusId
[
i
+
1
],
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
|
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelRunOverTimeError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
ETime
.
Reset
();
ETime
.
Stop
();
// 停止监视
}
}
else
{
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
],
16
,
state_OFF
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
EmodbusId
[
i
],
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
false
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
else
{
ModualAlarm
.
vSet_Modual_Alarm
(
EmodbusId
[
i
],
(
ushort
)
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
|
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
+
1
],
16
,
state_OFF
)
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
],
16
,
state_OFF
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
EmodbusId
[
i
+
1
],
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
false
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
else
{
ModualAlarm
.
vSet_Modual_Alarm
(
EmodbusId
[
i
+
1
],
(
ushort
)
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
|
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
ETime
.
Reset
();
ETime
.
Stop
();
// 停止监视
//timerun = false;
}
}
else
{
ETime
.
Reset
();
ETime
.
Stop
();
// 停止监视
timerun
=
false
;
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
],
16
,
state_OFF
);
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
+
1
],
16
,
state_OFF
);
}
if
(
Wenabl
==
true
)
...
...
@@ -216,26 +229,61 @@ namespace ModbusDemo.application
WTime
.
Start
();
//开始监视
Wtimerun
=
true
;
}
if
(
Wtime
.
TotalMinutes
>
2
)
if
(
Wtime
.
TotalMinutes
>
1
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
WmodbusId
[
i
],
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
|
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelRunOverTimeError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
ModualAlarm
.
vSet_Modual_Alarm
(
WmodbusId
[
i
+
1
],
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
|
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelRunOverTimeError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
WTime
.
Reset
();
WTime
.
Stop
();
//停止监视
Wtimerun
=
false
;
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
],
16
,
state_OFF
);
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
+
1
],
16
,
state_OFF
);
}
}
else
{
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
],
16
,
state_OFF
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
WmodbusId
[
i
],
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
false
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
else
{
ModualAlarm
.
vSet_Modual_Alarm
(
WmodbusId
[
i
],
(
ushort
)
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
|
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
+
1
],
16
,
state_OFF
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
WmodbusId
[
i
+
1
],
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelControlError
,
false
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
else
{
ModualAlarm
.
vSet_Modual_Alarm
(
WmodbusId
[
i
+
1
],
(
ushort
)
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
|
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
WTime
.
Reset
();
WTime
.
Stop
();
//停止监视
Wtimerun
=
false
;
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
],
16
,
state_OFF
);
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
+
1
],
16
,
state_OFF
);
}
double
Whours
=
Wtime
.
TotalHours
;
double
Wminures
=
Wtime
.
TotalMinutes
;
double
Wseconds
=
Wtime
.
TotalSeconds
;
...
...
ModbusDemo/application/ControlMap.cs
View file @
4a5bdbd8
...
...
@@ -14,10 +14,11 @@ namespace ModbusDemo.application
public
static
byte
byMapIdleID
;
public
static
bool
[]
byMapIdleControlData
;
public
static
string
[]
strMapIdleChannelName
;
public
static
bool
bMap_Idle_Ope
ratio
n_Control
(
bool
[]
bControldata
)
public
static
bool
bMap_Idle_Open_Control
(
bool
[]
bControldata
)
{
bool
[]
bControlBit
=
new
bool
[
bControldata
.
Count
()];
bool
bStatus
;
bool
bHadOperation
;
for
(
int
i
=
0
;
i
<
bControldata
.
Count
();
i
++)
{
string
str
=
"d"
+
i
.
ToString
();
...
...
@@ -30,10 +31,30 @@ namespace ModbusDemo.application
}
}
}
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byMapIdleID
,
bControldata
,
bControlBit
,
0
,
null
);
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byMapIdleID
,
bControldata
,
bControlBit
,
out
bHadOperation
,
0
,
null
);
return
bStatus
;
}
public
static
bool
bControl_Map
(
bool
bOpen
,
byte
byControlID
,
bool
[]
bControlData
,
params
string
[]
strOperationChannelName
)
public
static
bool
bMap_Idle_Close_Control
(
bool
[]
bControldata
)
{
bool
[]
bControlBit
=
new
bool
[
bControldata
.
Count
()];
bool
bStatus
;
bool
bHadOperation
;
for
(
int
i
=
0
;
i
<
bControldata
.
Count
();
i
++)
{
string
str
=
"d"
+
i
.
ToString
();
for
(
int
j
=
0
;
j
<
strMapIdleChannelName
.
Count
();
j
++)
{
if
(
str
==
strMapIdleChannelName
[
j
])
{
bControlBit
[
i
]
=
true
;
bControldata
[
i
]
=
byMapIdleControlData
[
i
];
}
}
}
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byMapIdleID
,
bControldata
,
bControlBit
,
out
bHadOperation
,
0
,
null
);
return
bStatus
;
}
public
static
bool
bControl_Map
(
bool
bOpen
,
byte
byControlID
,
bool
[]
bControlData
,
params
string
[]
strOperationChannelName
)
{
bool
bMapStatus
=
true
;
if
(
bOpen
==
true
)
...
...
@@ -71,7 +92,7 @@ namespace ModbusDemo.application
byMapIdleID
=
byControlID
;
strMapIdleChannelName
=
strOperationChannelName
;
byMapIdleControlData
=
bControlData
;
bDelege_Operation
=
bMap_Idle_Ope
ratio
n_Control
;
bDelege_Operation
=
bMap_Idle_Open_Control
;
}
}
else
...
...
@@ -109,7 +130,7 @@ namespace ModbusDemo.application
byMapIdleID
=
byControlID
;
strMapIdleChannelName
=
strOperationChannelName
;
byMapIdleControlData
=
bControlData
;
bDelege_Operation
=
bMap_Idle_
Operation
_Control
;
bDelege_Operation
=
bMap_Idle_
Close
_Control
;
}
}
return
bMapStatus
;
...
...
ModbusDemo/application/ModualPool.cs
View file @
4a5bdbd8
...
...
@@ -127,7 +127,7 @@ namespace ModbusDemo.application
}
}
}
if
((
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byModbusID
,
bControldata
,
bControlBit
,
byResModbusID
,
strResChannelNumber
))
==
true
)
if
((
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byModbusID
,
bControldata
,
bControlBit
,
out
bHadOpenPumb
,
byResModbusID
,
strResChannelNumber
))
==
true
)
{
bHadOpenPumb
=
true
;
}
...
...
@@ -149,7 +149,7 @@ namespace ModbusDemo.application
}
}
}
if
((
bStatus
=
ModualControl
.
bOperation_Machine
(
false
,
byModbusID
,
bControldata
,
bControlBit
,
byResModbusID
,
strResChannelNumber
))
==
true
)
if
((
bStatus
=
ModualControl
.
bOperation_Machine
(
false
,
byModbusID
,
bControldata
,
bControlBit
,
out
bHadOpenPumb
,
byResModbusID
,
strResChannelNumber
))
==
true
)
{
bHadOpenPumb
=
false
;
}
...
...
@@ -201,6 +201,7 @@ namespace ModbusDemo.application
public
bool
bOpreation_Button
(
bool
[]
bControldata
)
{
bool
bStatus
;
bool
bHadOpenButton
;
bool
[]
bControlBit
=
new
bool
[
bControldata
.
Count
()];
for
(
int
i
=
0
;
i
<
bControldata
.
Count
();
i
++)
{
...
...
@@ -214,7 +215,7 @@ namespace ModbusDemo.application
}
}
}
if
((
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byModbusID
,
bControldata
,
bControlBit
,
0
,
null
))
==
true
)
if
((
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byModbusID
,
bControldata
,
bControlBit
,
out
bHadOpenButton
,
0
,
null
))
==
true
)
{
for
(
int
i
=
0
;
i
<
bControldata
.
Count
();
i
++)
{
...
...
@@ -228,7 +229,7 @@ namespace ModbusDemo.application
}
}
}
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byModbusID
,
bControldata
,
bControlBit
,
0
,
null
);
bStatus
=
ModualControl
.
bOperation_Machine
(
true
,
byModbusID
,
bControldata
,
bControlBit
,
out
bHadOpenButton
,
0
,
null
);
}
return
bStatus
;
...
...
ModbusDemo/windows/Form1.cs
View file @
4a5bdbd8
...
...
@@ -137,6 +137,8 @@ namespace ModbusDemo
//定义一个委托变量
public
UpdateTxt
updateTxt
;
private
Thread
ModbusControlThread
;
private
Thread
MqttReceiveThread
;
public
List
<
string
>
ListHandle
=
new
List
<
string
>();
private
async
Task
Publish
()
{
var
message
=
new
MqttApplicationMessageBuilder
()
...
...
@@ -150,7 +152,7 @@ namespace ModbusDemo
await
mqttClient
.
PublishAsync
(
message
);
}
}
private
async
Task
vControlResponseBack
()
private
void
vControlResponseBack
()
{
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
mqttBackTopic
)
...
...
@@ -158,7 +160,7 @@ namespace ModbusDemo
.
WithAtLeastOnceQoS
()
.
WithRetainFlag
(
false
)
.
Build
();
await
mqttClient
.
PublishAsync
(
message
);
mqttClient
.
PublishAsync
(
message
);
totxt
.
Log
(
"我在247,执行了Back"
);
}
...
...
@@ -203,6 +205,7 @@ namespace ModbusDemo
//txtReceiveMessage.AppendText($"已订阅[{Data}]主题{Environment.NewLine}");
})));
}
//private async Task ConnectMqttServerAsync()
private
async
Task
ConnectMqttServerAsync
()
{
// Create a new MQTT client.
...
...
@@ -327,12 +330,11 @@ namespace ModbusDemo
//收到的消息啦
txtReceiveMessage
.
AppendText
(
$">>
{
"### RECEIVED APPLICATION MESSAGE ###"
}{
Environment
.
NewLine
}
"
);
totxt
.
Log
(
$">>
{
"### RECEIVED APPLICATION MESSAGE ###"
}{
Environment
.
NewLine
}
"
);
})));
Invoke
((
new
Action
(()
=>
{
//我的订阅主题是。。。。。
txtReceiveMessage
.
AppendText
(
$">> Topic =
{
e
.
ApplicationMessage
.
Topic
}{
Environment
.
NewLine
}
"
);
totxt
.
Log
(
$">> Topic =
{
e
.
ApplicationMessage
.
Topic
}{
Environment
.
NewLine
}
"
);
txtReceiveMessage
.
AppendText
(
$">> QoS =
{
e
.
ApplicationMessage
.
QualityOfServiceLevel
}{
Environment
.
NewLine
}
"
);
txtReceiveMessage
.
AppendText
(
$">> Retain =
{
e
.
ApplicationMessage
.
Retain
}{
Environment
.
NewLine
}
"
);
})));
Invoke
((
new
Action
(
async
()
=>
{
...
...
@@ -344,8 +346,7 @@ namespace ModbusDemo
Console
.
WriteLine
(
stConvertString
);
if
(
e
.
ApplicationMessage
.
Topic
==
mqttSubscribeControlTopic
)
{
ModualControl
.
vGetaWay_Receive_Control
(
stConvertString
,
out
mqttData_Back
);
await
vControlResponseBack
();
ListHandle
.
Add
(
stConvertString
);
}
else
if
(
e
.
ApplicationMessage
.
Topic
==
mqttCfgTopic
)
{
...
...
@@ -353,24 +354,28 @@ namespace ModbusDemo
await
vCfgResponseBack
(
mqttData_Back
);
}
})));
Invoke
((
new
Action
(()
=>
{
txtReceiveMessage
.
AppendText
(
$">> QoS =
{
e
.
ApplicationMessage
.
QualityOfServiceLevel
}{
Environment
.
NewLine
}
"
);
//totxt.Log($">> QoS = {e.ApplicationMessage.QualityOfServiceLevel}{Environment.NewLine}");
})));
Invoke
((
new
Action
(()
=>
}
private
void
vMqtt_Receive_Handle
()
{
while
(
true
)
{
txtReceiveMessage
.
AppendText
(
$">> Retain =
{
e
.
ApplicationMessage
.
Retain
}{
Environment
.
NewLine
}
"
);
//totxt.Log($">> Retain = {e.ApplicationMessage.Retain}{Environment.NewLine}");
})));
mqttData
=
null
;
for
(
int
i
=
0
;
i
<
ListHandle
.
Count
;
i
++)
{
ModualControl
.
vGetaWay_Receive_Control
(
ListHandle
[
i
],
out
mqttData_Back
);
vControlResponseBack
();
ListHandle
.
Remove
(
ListHandle
[
i
]);
}
Thread
.
Sleep
(
100
);
}
}
#
endregion
#
region
modbus
线程
private
static
bool
bSetDataIsRunning
=
false
;
private
Thread
ModbusPollThread
;
private
Thread
ModbusPollThread
;
private
void
T_AutoControl
()
{
AutoControl
.
Control
usEcontrol
=
new
AutoControl
.
Control
();
...
...
@@ -391,12 +396,14 @@ namespace ModbusDemo
usWcontrol
.
realTimeLevel
=
ModualPoll
.
cx18x
.
sX18xDataStruct
[
j
].
dNowConvertData
[
0
];
usWcontrol
.
modularx
=
j
;
usWcontrol
.
modbusID
=
LevelmodbusID
[
0
];
}
if
(
ModualPoll
.
cx18x
.
byModbusID
[
j
]
==
LevelmodbusID
[
1
])
{
usEcontrol
.
realTimeLevel
=
ModualPoll
.
cx18x
.
sX18xDataStruct
[
j
].
dNowConvertData
[
0
];
usEcontrol
.
modularx
=
j
;
usEcontrol
.
modbusID
=
LevelmodbusID
[
1
];
}
}
if
(
ModualControl
.
cPoolLevelConfig
[
i
].
byModbusID
==
LevelmodbusID
[
0
])
...
...
@@ -431,8 +438,7 @@ namespace ModbusDemo
}
AutoControl
.
Automatic_control
(
usWcontrolB
.
status
,
usEcontrolB
.
status
);
}
else
if
(
file
.
Length
!=
0
)
else
if
(
file
.
Length
!=
0
)
{
usEcontrol
.
modularx
=
InIHelper
.
ReadConfig
<
int
>(
"Channel number"
,
"东液位通道"
);
usWcontrol
.
modularx
=
InIHelper
.
ReadConfig
<
int
>(
"Channel number"
,
"西液位通道"
);
...
...
@@ -1083,7 +1089,6 @@ namespace ModbusDemo
{
}
private
async
void
SubscribeBut_Click
(
object
sender
,
EventArgs
e
)
{
await
Subscribe
();
...
...
@@ -1138,7 +1143,7 @@ namespace ModbusDemo
SetMqtt
();
MQTT_thread
=
new
MethodInvoker
(
Sendout
);
MQTT_thread
.
BeginInvoke
(
null
,
null
);
Task
.
Run
(
async
()
=>
{
await
ConnectMqttServerAsync
();
});
Task
.
Run
(
async
()
=>
{
await
ConnectMqttServerAsync
();
});
ModbusComm
.
Modbus
=
ModbusSerialMaster
.
CreateRtu
(
comPort
);
ModbusComm
.
Modbus
.
Transport
.
Retries
=
0
;
ModbusComm
.
Modbus
.
Transport
.
ReadTimeout
=
1000
;
...
...
@@ -1155,9 +1160,18 @@ namespace ModbusDemo
bCretaThead
=
true
;
ModbusPollThread
=
new
Thread
(
vModbusPoll
);
ModbusPollThread
.
Start
();
ModbusPollThread
.
Priority
=
ThreadPriority
.
Normal
;
ModbusControlThread
=
new
Thread
(
ModualControl
.
vControl_Poll
);
ModbusControlThread
.
Start
();
ModbusControlThread
.
Priority
=
ThreadPriority
.
BelowNormal
;
MqttReceiveThread
=
new
Thread
(
vMqtt_Receive_Handle
);
MqttReceiveThread
.
Start
();
MqttReceiveThread
.
Priority
=
ThreadPriority
.
AboveNormal
;
Task
task1
=
Task
.
Factory
.
StartNew
(
async
()
=>
{
await
ModualControl
.
vControl_Res_Poll
();});
}
else
{
...
...
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