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
99e950f7
Commit
99e950f7
authored
Jun 01, 2019
by
leon.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add modual Alarm
parent
1dfb305f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
225 additions
and
84 deletions
+225
-84
ModualAlarm.cs
ModbusDemo/Common/ModualAlarm.cs
+54
-0
ModbusComm.cs
ModbusDemo/MessageFormat/ModbusComm.cs
+12
-4
mqttpacke.cs
ModbusDemo/MessageFormat/mqttpacke.cs
+1
-42
ModbusDemo.csproj
ModbusDemo/ModbusDemo.csproj
+3
-17
ModualPoll.cs
ModbusDemo/Modular/ModualPoll.cs
+129
-11
modual.cs
ModbusDemo/Modular/modual.cs
+26
-10
No files found.
ModbusDemo/Common/ModualAlarm.cs
0 → 100644
View file @
99e950f7
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Collections
;
using
MQTTnet
;
using
MQTTnet.Client
;
using
Newtonsoft.Json
;
namespace
ModbusDemo.Common
{
public
class
ModualAlarm
{
public
const
ushort
usChannelNumber
=
8
;
private
const
string
sAlarmTopic
=
"Witium/WTDS78X/20193261/Alarm"
;
public
Hashtable
hMqtttAlarmMap
=
new
Hashtable
();
public
bool
bErrorHasSend
=
false
;
private
string
sAlarmJson
;
private
string
sAlarmJsonPackage
;
//private IMqttClient mqttClient = null;
public
enum
eAlarmCode
:
sbyte
{
ChannelNoError
=
0
,
ChannelCommunError
=
1
,
ChannelCollectDataError
=
2
,
ChannelDataRespError
=
4
,
ChannelDataChangeError
=
8
}
public
void
vSetAlarmList
(
ushort
usAddress
,
ushort
[]
usChannel
,
ushort
[]
usChannelAlarmcode
)
{
ushort
i
=
0
;
hMqtttAlarmMap
.
Add
(
"addr"
,
usAddress
.
ToString
());
string
sAlarm
=
"alm"
;
foreach
(
ushort
usdata
in
usChannelAlarmcode
)
{
hMqtttAlarmMap
.
Add
(
sAlarm
+
i
,
usChannelAlarmcode
[
i
]);
i
++;
}
hMqtttAlarmMap
.
Add
(
"ts"
,
Form1
.
GetTimeStamp
());
sAlarmJson
=
JsonConvert
.
SerializeObject
(
hMqtttAlarmMap
);
}
public
async
Task
vPublishAlarmPackageJson
(
IMqttClient
mqttClient
)
{
sAlarmJson
=
"["
+
sAlarmJson
+
"]"
;
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
sAlarmTopic
)
.
WithPayload
(
sAlarmJson
)
.
WithAtMostOnceQoS
()
.
WithRetainFlag
(
false
)
.
Build
();
await
mqttClient
.
PublishAsync
(
message
);
}
}
}
ModbusDemo/MessageFormat/ModbusComm.cs
View file @
99e950f7
...
@@ -30,8 +30,9 @@ namespace ModbusDemo.MessageFormat
...
@@ -30,8 +30,9 @@ namespace ModbusDemo.MessageFormat
}
}
public
static
ModbusMaster
Modbus
;
public
static
ModbusMaster
Modbus
;
public
static
ushort
usCommunFailTimes
=
0
;
public
static
ushort
usCommunFailTimes
=
0
;
public
static
void
Modbus_ReadHoldingRegistersTask
(
out
ushort
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoints
,
out
eModbusErrorCode
ModbusErrorCode
)
public
static
eModbusErrorCode
Modbus_ReadHoldingRegistersTask
(
out
ushort
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoints
)
{
{
eModbusErrorCode
ModbusErrorCode
;
try
try
{
{
OutputValue
=
Modbus
.
ReadHoldingRegisters
(
slaveAddress
,
startAddress
,
numberOfPoints
);
OutputValue
=
Modbus
.
ReadHoldingRegisters
(
slaveAddress
,
startAddress
,
numberOfPoints
);
...
@@ -108,9 +109,11 @@ namespace ModbusDemo.MessageFormat
...
@@ -108,9 +109,11 @@ namespace ModbusDemo.MessageFormat
OutputValue
=
new
ushort
[
numberOfPoints
];
OutputValue
=
new
ushort
[
numberOfPoints
];
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
}
}
return
ModbusErrorCode
;
}
}
public
static
void
Modbus_ReadCoilsTask
(
out
bool
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoints
,
out
eModbusErrorCode
ModbusErrorCode
)
public
static
eModbusErrorCode
Modbus_ReadCoilsTask
(
out
bool
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoints
)
{
{
eModbusErrorCode
ModbusErrorCode
;
try
try
{
{
OutputValue
=
Modbus
.
ReadCoils
(
slaveAddress
,
startAddress
,
numberOfPoints
);
OutputValue
=
Modbus
.
ReadCoils
(
slaveAddress
,
startAddress
,
numberOfPoints
);
...
@@ -187,9 +190,11 @@ namespace ModbusDemo.MessageFormat
...
@@ -187,9 +190,11 @@ namespace ModbusDemo.MessageFormat
OutputValue
=
new
bool
[
numberOfPoints
];
OutputValue
=
new
bool
[
numberOfPoints
];
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
}
}
return
ModbusErrorCode
;
}
}
public
static
void
Modbus_WriteSingleCoil
(
byte
slaveAddress
,
ushort
startAddress
,
bool
[]
value
,
out
eModbusErrorCode
ModbusErrorCod
e
)
public
static
eModbusErrorCode
Modbus_WriteSingleCoil
(
byte
slaveAddress
,
ushort
startAddress
,
bool
[]
valu
e
)
{
{
eModbusErrorCode
ModbusErrorCode
;
try
try
{
{
Modbus
.
WriteMultipleCoils
(
slaveAddress
,
startAddress
,
value
);
Modbus
.
WriteMultipleCoils
(
slaveAddress
,
startAddress
,
value
);
...
@@ -263,9 +268,11 @@ namespace ModbusDemo.MessageFormat
...
@@ -263,9 +268,11 @@ namespace ModbusDemo.MessageFormat
}
}
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
}
}
return
ModbusErrorCode
;
}
}
public
static
void
Modbus_WriteMultipleCoils
(
byte
slaveAddress
,
ushort
startAddress
,
bool
[]
data
,
out
eModbusErrorCode
ModbusErrorCode
)
public
static
eModbusErrorCode
Modbus_WriteMultipleCoils
(
byte
slaveAddress
,
ushort
startAddress
,
bool
[]
data
)
{
{
eModbusErrorCode
ModbusErrorCode
;
try
try
{
{
Modbus
.
WriteMultipleCoils
(
slaveAddress
,
startAddress
,
data
);
Modbus
.
WriteMultipleCoils
(
slaveAddress
,
startAddress
,
data
);
...
@@ -339,6 +346,7 @@ namespace ModbusDemo.MessageFormat
...
@@ -339,6 +346,7 @@ namespace ModbusDemo.MessageFormat
}
}
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
}
}
return
ModbusErrorCode
;
}
}
//private void Init_Read_data()
//private void Init_Read_data()
//{
//{
...
...
ModbusDemo/MessageFormat/mqttpacke.cs
View file @
99e950f7
...
@@ -225,46 +225,5 @@ namespace ModbusDemo
...
@@ -225,46 +225,5 @@ namespace ModbusDemo
}
}
}
}
public
class
pcDeviceAlarm
{
public
const
ushort
usChannelNumber
=
8
;
private
const
string
sAlarmTopic
=
"Witium/WTDS78X/20193261/Alarm"
;
public
Hashtable
hMqtttAlarmMap
=
new
Hashtable
();
public
bool
bErrorHasSend
=
false
;
private
string
sAlarmJson
;
private
string
sAlarmJsonPackage
;
//private IMqttClient mqttClient = null;
public
enum
eAlarmCode
:
sbyte
{
ChannelNoError
=
0
,
ChannelCommunError
=
1
,
ChannelCollectDataError
=
2
,
ChannelDataRespError
=
4
,
ChannelDataChangeError
=
8
}
public
void
vSetAlarmList
(
ushort
usAddress
,
ushort
[]
usChannel
,
eAlarmCode
[]
usChannelAlarmcode
)
{
ushort
i
=
0
;
hMqtttAlarmMap
.
Add
(
"addr"
,
usAddress
.
ToString
());
string
sAlarm
=
"alm"
;
foreach
(
ushort
usdata
in
usChannelAlarmcode
)
{
hMqtttAlarmMap
.
Add
(
sAlarm
+
i
,
usChannelAlarmcode
[
i
]);
i
++;
}
hMqtttAlarmMap
.
Add
(
"ts"
,
Form1
.
GetTimeStamp
());
sAlarmJson
=
JsonConvert
.
SerializeObject
(
hMqtttAlarmMap
);
}
public
async
Task
vPublishAlarmPackageJson
(
IMqttClient
mqttClient
)
{
sAlarmJson
=
"["
+
sAlarmJson
+
"]"
;
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
sAlarmTopic
)
.
WithPayload
(
sAlarmJson
)
.
WithAtMostOnceQoS
()
.
WithRetainFlag
(
false
)
.
Build
();
await
mqttClient
.
PublishAsync
(
message
);
}
}
}
}
ModbusDemo/ModbusDemo.csproj
View file @
99e950f7
...
@@ -74,9 +74,8 @@
...
@@ -74,9 +74,8 @@
<Reference
Include=
"Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"
>
<Reference
Include=
"Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll
</HintPath>
<HintPath>
..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll
</HintPath>
</Reference>
</Reference>
<Reference
Include=
"nmodbuspc, Version=1.12.0.0, Culture=neutral, processorArchitecture=MSIL"
>
<Reference
Include=
"NModbus4, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\packages\NModbus4.2.1.0\lib\net40\NModbus4.dll
</HintPath>
<HintPath>
bin\Debug\nmodbuspc.dll
</HintPath>
</Reference>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Core"
/>
...
@@ -93,6 +92,7 @@
...
@@ -93,6 +92,7 @@
<Compile
Include=
"application\PoolModbusSet.cs"
/>
<Compile
Include=
"application\PoolModbusSet.cs"
/>
<Compile
Include=
"application\ModbusToPool.cs"
/>
<Compile
Include=
"application\ModbusToPool.cs"
/>
<Compile
Include=
"application\Pond.cs"
/>
<Compile
Include=
"application\Pond.cs"
/>
<Compile
Include=
"Common\ModualAlarm.cs"
/>
<Compile
Include=
"MessageFormat\ModbusComm.cs"
/>
<Compile
Include=
"MessageFormat\ModbusComm.cs"
/>
<Compile
Include=
"Modular\414P.cs"
/>
<Compile
Include=
"Modular\414P.cs"
/>
<Compile
Include=
"Modular\478C.cs"
/>
<Compile
Include=
"Modular\478C.cs"
/>
...
@@ -164,20 +164,6 @@
...
@@ -164,20 +164,6 @@
</ItemGroup>
</ItemGroup>
<ItemGroup
/>
<ItemGroup
/>
<ItemGroup
/>
<ItemGroup
/>
<ItemGroup
Condition=
"$(VisualStudioVersion) == '15.0'"
>
<Reference
Include=
"Microsoft.Data.Tools.Schema.Sql, Version=13.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
>
<HintPath>
$(SSDTPath)\Microsoft.Data.Tools.Schema.Sql.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"Microsoft.Data.Tools.Schema.Sql.UnitTesting, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
>
<HintPath>
$(SSDTUnitTestPath)\Microsoft.Data.Tools.Schema.Sql.UnitTesting.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"Microsoft.Data.Tools.Schema.Sql.UnitTestingAdapter, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
>
<HintPath>
$(SSDTUnitTestPath)\Microsoft.Data.Tools.Schema.Sql.UnitTestingAdapter.dll
</HintPath>
<Private>
True
</Private>
</Reference>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<PropertyGroup>
<PropertyGroup>
<SsdtUnitTestVersion>
3.1
</SsdtUnitTestVersion>
<SsdtUnitTestVersion>
3.1
</SsdtUnitTestVersion>
...
...
ModbusDemo/Modular/ModualPoll.cs
View file @
99e950f7
This diff is collapsed.
Click to expand it.
ModbusDemo/Modular/modual.cs
View file @
99e950f7
...
@@ -4,20 +4,30 @@ using System.Linq;
...
@@ -4,20 +4,30 @@ using System.Linq;
using
System.Text
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
ModbusDemo.MessageFormat
;
using
ModbusDemo.MessageFormat
;
using
ModbusDemo.Common
;
namespace
ModbusDemo.Modular
namespace
ModbusDemo.Modular
{
{
class
modual
class
modual
{
{
public
struct
psx14p
public
struct
psx14p
Data
{
{
public
ushort
[]
usX14pRegData
;
public
ushort
[]
usX14pRegData
;
public
ushort
[]
usX14pRegType
;
public
ushort
[]
usX14pRegType
;
public
double
[]
dX14pConvertData
;
public
double
[]
dX14pNowConvertData
;
public
double
[]
dX14pBeforeConvertData
;
}
public
struct
psxModualAlarm
{
public
bool
bDataNotFirstIncreaseOrDecrease
;
public
ModualAlarm
.
eAlarmCode
[]
eNowAlarmCode
;
public
ModualAlarm
.
eAlarmCode
[]
eBeforeAlarmCode
;
}
}
public
class
pcx14P
public
class
pcx14P
{
{
public
byte
[]
byModbusID
;
public
byte
[]
byModbusID
;
public
psx14p
[]
sX14pDataStruct
;
public
psx14pData
[]
sX14pDataStruct
;
public
psxModualAlarm
[]
sX14PAlarmStruct
;
public
ModbusComm
.
eModbusErrorCode
[]
ModbusErrorCode
;
public
ModbusComm
.
eModbusErrorCode
[]
ModbusErrorCode
;
public
pcx14P
(
byte
[]
InitIDlist
)
public
pcx14P
(
byte
[]
InitIDlist
)
{
{
...
@@ -30,17 +40,19 @@ namespace ModbusDemo.Modular
...
@@ -30,17 +40,19 @@ namespace ModbusDemo.Modular
Level
,
Level
,
}
}
public
struct
psX18x
public
struct
psX18x
Data
{
{
public
ushort
[]
usRegData
;
public
ushort
[]
usRegData
;
public
ushort
[]
usTypeData
;
public
ushort
[]
usTypeData
;
public
eX18xSensorChannelType
[]
eChannelType
;
public
eX18xSensorChannelType
[]
eChannelType
;
public
double
[]
dConvertData
;
public
double
[]
dNowConvertData
;
public
double
[]
dBeforeConvertData
;
}
}
public
class
pcx18X
public
class
pcx18X
{
{
public
byte
[]
byModbusID
;
public
byte
[]
byModbusID
;
public
psX18x
[]
sX18xDataStruct
;
public
psX18xData
[]
sX18xDataStruct
;
public
psxModualAlarm
[]
sX18xAlarmstruct
;
public
ModbusComm
.
eModbusErrorCode
[]
ModbusErrorCode
;
public
ModbusComm
.
eModbusErrorCode
[]
ModbusErrorCode
;
public
pcx18X
(
byte
[]
InitIDlist
,
eX18xSensorChannelType
[,]
eChannnelType
)
public
pcx18X
(
byte
[]
InitIDlist
,
eX18xSensorChannelType
[,]
eChannnelType
)
{
{
...
@@ -57,12 +69,14 @@ namespace ModbusDemo.Modular
...
@@ -57,12 +69,14 @@ namespace ModbusDemo.Modular
public
struct
psx78C
public
struct
psx78C
{
{
public
bool
[]
bInputRegStatus
;
public
bool
[]
bInputRegStatus
;
public
bool
[]
bOutPutRegStatus
;
public
bool
[]
bOutPutRegStatus
;
public
bool
bX78cAllChannelAlarm
;
}
}
public
class
pcx78C
public
class
pcx78C
{
{
public
byte
[]
byModbusID
;
public
byte
[]
byModbusID
;
public
psx78C
[]
sx78CRegDataStructStatus
;
public
psx78C
[]
sX78cRegStatusStruct
;
public
psxModualAlarm
[]
sX78cAlarmStruct
;
public
ModbusComm
.
eModbusErrorCode
[]
ModbusErrorCode
;
public
ModbusComm
.
eModbusErrorCode
[]
ModbusErrorCode
;
public
pcx78C
(
byte
[]
InitIDlist
)
public
pcx78C
(
byte
[]
InitIDlist
)
{
{
...
@@ -72,11 +86,13 @@ namespace ModbusDemo.Modular
...
@@ -72,11 +86,13 @@ namespace ModbusDemo.Modular
public
struct
psx66C
public
struct
psx66C
{
{
public
bool
[]
bRegRelayStatus
;
public
bool
[]
bRegRelayStatus
;
public
bool
[]
bX66CAllChannelAlarm
;
}
}
public
class
pcx66C
public
class
pcx66C
{
{
public
byte
[]
byModbusID
;
public
byte
[]
byModbusID
;
public
psx78C
[]
sx78CDatastructStatus
;
public
psx78C
[]
sX66cRegStatusStruct
;
public
psxModualAlarm
[]
sX66cAlarmStruct
;
public
ModbusComm
.
eModbusErrorCode
[]
ModbusErrorCode
;
public
ModbusComm
.
eModbusErrorCode
[]
ModbusErrorCode
;
public
pcx66C
(
byte
[]
InitIDlist
)
public
pcx66C
(
byte
[]
InitIDlist
)
{
{
...
...
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