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
bb1d1cfa
Commit
bb1d1cfa
authored
Jun 30, 2019
by
leon.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix feedback control bug
parent
09f7e49d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
299 additions
and
217 deletions
+299
-217
ModualControl.cs
ModbusDemo/MessageFormat/ModualControl.cs
+72
-54
ModualPoll.cs
ModbusDemo/Modular/ModualPoll.cs
+53
-16
AllPond.cs
ModbusDemo/application/AllPond.cs
+5
-5
AutoControl.cs
ModbusDemo/application/AutoControl.cs
+42
-15
ControlMap.cs
ModbusDemo/application/ControlMap.cs
+124
-124
ModualPool.cs
ModbusDemo/application/ModualPool.cs
+1
-1
Form1.cs
ModbusDemo/windows/Form1.cs
+2
-2
No files found.
ModbusDemo/MessageFormat/ModualControl.cs
View file @
bb1d1cfa
This diff is collapsed.
Click to expand it.
ModbusDemo/Modular/ModualPoll.cs
View file @
bb1d1cfa
...
...
@@ -564,31 +564,45 @@ namespace ModbusDemo.Modular
for
(
int
k
=
0
;
k
<
byX18xReadTypeNumber
;
k
++)
{
string
str
=
"d"
+
k
.
ToString
();
if
(
str
==
strChannelList
[
j
]
)
if
(
ModbusErrorCode
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
switch
(
cx18x
.
beChannelType
[
i
,
k
])
{
case
modual
.
eX18xSensorChannelType
.
Weiertai
:
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
8
);
break
;
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
8
-
1
);
break
;
case
modual
.
eX18xSensorChannelType
.
Mike_5
:
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
5
);
break
;
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
5
);
break
;
case
modual
.
eX18xSensorChannelType
.
Mike_6
:
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
6
);
break
;
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
6
);
break
;
case
modual
.
eX18xSensorChannelType
.
Mike_7
:
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
7
);
break
;
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
((
double
.
Parse
(
strCalculData
[
k
])
-
4
)
/
16
*
7
);
break
;
case
modual
.
eX18xSensorChannelType
.
NormalCurrent
:
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
double
.
Parse
(
strCalculData
[
k
]);
break
;
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
double
.
Parse
(
strCalculData
[
k
]);
break
;
case
modual
.
eX18xSensorChannelType
.
Null
:
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
0
;
break
;
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
0
;
break
;
default
:
break
;
break
;
}
}
else
{
if
(
cx18x
.
sX18xAlarmstruct
[
i
].
usCommFailTimes
[
k
]
>=
COMMFAILALARM
)
{
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
0
;
}
else
{
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
]
=
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
];
}
}
if
(
str
==
strChannelList
[
j
]
)
{
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
cx18x
.
sX18xDataStruct
[
i
].
dNowConvertData
[
k
],
typeof
(
T
)));
}
...
...
@@ -601,7 +615,6 @@ namespace ModbusDemo.Modular
{
if
(
byModbusID
==
ModualPoll
.
cx14P
.
byModbusID
[
i
])
{
if
((
ModbusErrorCode
|=
ModbusComm
.
Modbus_ReadHoldingRegistersTask
(
out
usRegValue
,
byModbusID
,
byX14pReadDataStartAddress
,
byX14pReadDataNumber
))
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
ModualAlarm
.
vSet_Modual_Alarm
(
byModbusID
,
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
false
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
...
...
@@ -628,9 +641,33 @@ namespace ModbusDemo.Modular
{
ModualPoll
.
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
]
=
double
.
Parse
(
strCalculData
[
k
]);
string
str
=
"d"
+
k
.
ToString
();
if
(
ModbusErrorCode
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERERR
)
{
switch
(
cx14P
.
eChannelType
[
i
,
k
])
{
case
modual
.
eX14pSensorChannelType
.
Normal
:
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
]
=
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
];
break
;
case
modual
.
eX14pSensorChannelType
.
Null
:
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
]
=
0
;
break
;
}
}
else
{
if
(
cx14P
.
sX14PAlarmStruct
[
i
].
usCommFailTimes
[
k
]
>=
COMMFAILALARM
)
{
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
]
=
0
;
}
else
{
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
]
=
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
];
}
}
if
(
str
==
strChannelList
[
j
])
{
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
ModualPoll
.
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
],
typeof
(
T
)));
arrayList
.
Add
((
T
)
Convert
.
ChangeType
(
ModualPoll
.
cx14P
.
sX14pDataStruct
[
i
].
dNowConvertData
[
k
],
typeof
(
T
)));
}
}
}
...
...
ModbusDemo/application/AllPond.cs
View file @
bb1d1cfa
...
...
@@ -935,7 +935,7 @@ namespace ModbusDemo.application
strOperationNumber
=
"d2"
,
strChannelNumber
=
new
string
[]
{
"d2"
,
"d3"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
tru
e
},
bCloseOperation
=
new
bool
[]
{
false
,
fals
e
},
bHadRefControl
=
true
,
byResModbusID
=
86
,
strResChannelNumber
=
"d0"
...
...
@@ -972,13 +972,13 @@ namespace ModbusDemo.application
private
static
ModualPool
.
pcOperation
cEastTransitPoolStirrer3Base
=
new
ModualPool
.
pcOperation
{
byModbusID
=
20
,
strOperationNumber
=
"d
0
"
,
strChannelNumber
=
new
string
[]
{
"d
0"
,
"d1
"
},
strOperationNumber
=
"d
4
"
,
strChannelNumber
=
new
string
[]
{
"d
4"
,
"d5
"
},
bOpenOperation
=
new
bool
[]
{
true
,
true
},
bCloseOperation
=
new
bool
[]
{
false
,
false
},
bHadRefControl
=
true
,
byResModbusID
=
86
,
strResChannelNumber
=
"d
4
"
strResChannelNumber
=
"d
1
"
};
private
static
ModualPool
.
pcMachine
cEastTransitPoolStirrer3
=
new
ModualPool
.
pcMachine
(
"EastTransitPoolStirrer_3"
,
cEastTransitPoolStirrer3Base
);
...
...
@@ -1214,7 +1214,7 @@ namespace ModbusDemo.application
public
static
class
cDesiltingPool
{
public
static
double
vSetMaxLevel
;
public
static
double
vSetMaxLevel
;
public
static
double
vSetMinLevel
;
public
static
ModualPool
.
pcTemperature
cTemper
{
get
=>
cDesiltingPoolTemper
;
set
=>
cDesiltingPoolTemper
=
value
;
}
public
static
ModualPool
.
pcLiquidlevel
cLevel
{
get
=>
cDesiltingPoolLevel
;
set
=>
cDesiltingPoolLevel
=
value
;
}
...
...
ModbusDemo/application/AutoControl.cs
View file @
bb1d1cfa
...
...
@@ -532,7 +532,7 @@ namespace ModbusDemo.application
usControl
.
Minimum_Early_Warning
=
false
;
}
if
(
usControl
.
realTimeLevel
<
(
usControl
.
minLevel
-
usControl
.
minLevel
*
0.1
))
if
(
usControl
.
realTimeLevel
<
(
usControl
.
minLevel
))
{
usControl
.
status
=
false
;
usControl
.
Minimum_Early_Warning
=
true
;
...
...
@@ -560,12 +560,13 @@ namespace ModbusDemo.application
TimeSpan
timespan
=
ETime
.
Elapsed
;
// 获取当前实例测量得出的总时间
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
ModbusComm
.
eModbusErrorCode
ModbusErrorCode
=
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
;
if
(
Eenabl
==
true
)
{
if
(
Etimerun
==
false
)
{
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
],
16
,
state_ON
)
if
(
(
ModbusErrorCode
|=
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
],
16
,
state_ON
)
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
...
...
@@ -580,7 +581,7 @@ namespace ModbusDemo.application
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
+
1
],
16
,
state_ON
)
if
(
(
ModbusErrorCode
|=
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
+
1
],
16
,
state_ON
)
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
...
...
@@ -594,8 +595,14 @@ namespace ModbusDemo.application
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
ETime
.
Start
();
// 开始监视运行时间
Etimerun
=
true
;
if
(
ModbusErrorCode
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
Etimerun
=
true
;
ETime
.
Start
();
// 开始监视运行时间
}
else
Etimerun
=
false
;
}
if
(
timespan
.
TotalMinutes
>
Runtimeout
)
{
...
...
@@ -618,7 +625,7 @@ namespace ModbusDemo.application
{
if
(
Etimerun
==
true
)
{
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
],
16
,
state_OFF
)
if
(
(
ModbusErrorCode
|=
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
],
16
,
state_OFF
)
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
...
...
@@ -632,7 +639,7 @@ namespace ModbusDemo.application
(
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
(
(
ModbusErrorCode
|=
ModbusComm
.
Modbus_WriteMultipleCoils
(
EmodbusId
[
i
+
1
],
16
,
state_OFF
)
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
...
...
@@ -648,7 +655,8 @@ namespace ModbusDemo.application
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
if
(
ModbusErrorCode
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
ETime
.
Reset
();
ETime
.
Stop
();
ModualAlarm
.
vSet_Modual_Alarm
(
EmodbusId
[
i
],
...
...
@@ -661,13 +669,18 @@ namespace ModbusDemo.application
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
Etimerun
=
false
;
}
else
Etimerun
=
true
;
}
}
if
(
Wenabl
==
true
)
{
if
(
Wtimerun
==
false
)
{
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
],
16
,
state_ON
)
if
(
(
ModbusErrorCode
|=
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
],
16
,
state_ON
)
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
...
...
@@ -682,7 +695,7 @@ namespace ModbusDemo.application
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
+
1
],
16
,
state_ON
)
if
(
(
ModbusErrorCode
|=
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
+
1
],
16
,
state_ON
)
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
...
...
@@ -698,8 +711,13 @@ namespace ModbusDemo.application
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
if
(
ModbusErrorCode
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
WTime
.
Start
();
//开始监视
Wtimerun
=
true
;
}
else
Wtimerun
=
false
;
}
if
(
Wtime
.
TotalMinutes
>
Runtimeout
)
{
...
...
@@ -722,7 +740,7 @@ namespace ModbusDemo.application
{
if
(
Wtimerun
==
true
)
{
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
],
16
,
state_OFF
)
if
(
(
ModbusErrorCode
|=
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
],
16
,
state_OFF
)
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
...
...
@@ -738,7 +756,7 @@ namespace ModbusDemo.application
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
if
(
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
+
1
],
16
,
state_OFF
)
if
(
(
ModbusErrorCode
|=
ModbusComm
.
Modbus_WriteMultipleCoils
(
WmodbusId
[
i
+
1
],
16
,
state_OFF
)
)
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
...
...
@@ -754,6 +772,8 @@ namespace ModbusDemo.application
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelCommunError
,
true
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
}
if
(
ModbusErrorCode
==
ModbusComm
.
eModbusErrorCode
.
MB_EMASTERNOERR
)
{
WTime
.
Reset
();
WTime
.
Stop
();
//停止监视
ModualAlarm
.
vSet_Modual_Alarm
(
WmodbusId
[
i
],
...
...
@@ -765,7 +785,10 @@ namespace ModbusDemo.application
(
ushort
)
ModualAlarm
.
eAlarmCode
.
ChannelRunOverTimeError
,
false
,
1
,
"d0"
,
"d1"
,
"d2"
,
"d3"
,
"d4"
,
"d5"
,
"d6"
,
"d7"
);
Wtimerun
=
false
;
}
}
else
Wtimerun
=
true
;
}
}
//double Whours = Wtime.TotalHours;
...
...
@@ -789,7 +812,11 @@ namespace ModbusDemo.application
Control
usWcontrolB
=
new
Control
();
FileInfo
file
=
new
FileInfo
(
InIHelper
.
FileName
);
Run_flag_bit
=
true
;
while
(
true
)
InIHelper
.
WriteConfig
(
"MaxLevel"
,
"东·中转池"
,
"8"
);
InIHelper
.
WriteConfig
(
"MinLevel"
,
"东·中转池"
,
"1"
);
InIHelper
.
WriteConfig
(
"MaxLevel"
,
"西·中转池"
,
"8"
);
InIHelper
.
WriteConfig
(
"MinLevel"
,
"西·中转池"
,
"1"
);
while
(
true
)
{
if
(
ModualControl
.
cPoolLevelConfig
.
Count
!=
0
)
{
...
...
ModbusDemo/application/ControlMap.cs
View file @
bb1d1cfa
This diff is collapsed.
Click to expand it.
ModbusDemo/application/ModualPool.cs
View file @
bb1d1cfa
...
...
@@ -93,7 +93,7 @@ namespace ModbusDemo.application
public
byte
byResModbusID
;
public
string
strResChannelNumber
;
public
int
iRefAlarmCnt
=
0
;
public
int
MaxAlarmfeedback
=
2
;
public
int
MaxAlarmfeedback
=
5
;
}
public
class
pcMachine
:
pcOperation
{
...
...
ModbusDemo/windows/Form1.cs
View file @
bb1d1cfa
...
...
@@ -103,7 +103,7 @@ namespace ModbusDemo
}
else
{
mqttIp
=
"
172.16.1.24"
;
//""
mqttIp
=
"
47.101.50.24"
;
mqttClientId
=
GetTimeStamp
()
+
"sxz"
;
mqttPort
=
1883
;
mqttUsername
=
"pasture"
;
...
...
@@ -1110,7 +1110,7 @@ namespace ModbusDemo
}
else
{
comPort
.
PortName
=
"COM
6
"
;
comPort
.
PortName
=
"COM
5
"
;
}
comPort
.
BaudRate
=
9600
;
comPort
.
Parity
=
Parity
.
None
;
...
...
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