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
be6916d5
Commit
be6916d5
authored
Jun 05, 2019
by
shaxuezheng
Browse files
Options
Browse Files
Download
Plain Diff
合并线程池与数据轮询
parents
23d54b9c
ea27c868
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1392 additions
and
717 deletions
+1392
-717
Modbuslib.cs
ModbusDemo/Common/Modbuslib.cs
+0
-2
ModualAlarm.cs
ModbusDemo/Common/ModualAlarm.cs
+58
-0
ModbusComm.cs
ModbusDemo/MessageFormat/ModbusComm.cs
+103
-80
mqttpacke.cs
ModbusDemo/MessageFormat/mqttpacke.cs
+58
-54
ModbusDemo.csproj
ModbusDemo/ModbusDemo.csproj
+5
-17
418X.cs
ModbusDemo/Modular/418X.cs
+1
-1
ModualPoll.cs
ModbusDemo/Modular/ModualPoll.cs
+338
-0
modual.cs
ModbusDemo/Modular/modual.cs
+126
-0
ModbusToPool.cs
ModbusDemo/application/ModbusToPool.cs
+157
-157
Pond.cs
ModbusDemo/application/Pond.cs
+16
-16
PoolModbusSet.cs
ModbusDemo/application/PoolModbusSet.cs
+373
-254
Form1.Designer.cs
ModbusDemo/windows/Form1.Designer.cs
+26
-2
Form1.cs
ModbusDemo/windows/Form1.cs
+131
-134
No files found.
ModbusDemo/Common/Modbuslib.cs
View file @
be6916d5
...
@@ -233,7 +233,6 @@ namespace ModbusDemo.windows
...
@@ -233,7 +233,6 @@ namespace ModbusDemo.windows
public
String
GetVersion
(
Byte
slaveid
)
public
String
GetVersion
(
Byte
slaveid
)
{
{
int
ret
;
int
ret
;
String
version
=
"0.0"
;
String
version
=
"0.0"
;
String
ip
=
"127.0.0.1"
;
String
ip
=
"127.0.0.1"
;
UInt16
[]
buf
=
new
ushort
[
2
];
UInt16
[]
buf
=
new
ushort
[
2
];
...
@@ -247,6 +246,5 @@ namespace ModbusDemo.windows
...
@@ -247,6 +246,5 @@ namespace ModbusDemo.windows
}
}
return
version
;
return
version
;
}
}
}
}
}
}
ModbusDemo/Common/ModualAlarm.cs
0 → 100644
View file @
be6916d5
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
:
ushort
{
ChannelNoError
=
0
,
ChannelCommunError
=
1
,
ChannelCollectDataError
=
2
,
ChannelDataRespError
=
4
,
ChannelDataChangeError
=
8
}
public
void
vSetAlarmList
(
ushort
usAddress
,
ushort
[]
usChannel
,
ushort
[]
usChannelAlarmcode
,
bool
bStringIncrease
)
{
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
);
if
(
bStringIncrease
==
true
)
{
sAlarmJson
+=
","
;
}
}
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 @
be6916d5
...
@@ -13,14 +13,30 @@ namespace ModbusDemo.MessageFormat
...
@@ -13,14 +13,30 @@ namespace ModbusDemo.MessageFormat
{
{
public
static
class
ModbusComm
public
static
class
ModbusComm
{
{
public
enum
eModbusErrorCode
:
byte
{
MB_ENOERR
,
/*!< no error. */
MB_ENOREG
,
/*!< illegal register address. */
MB_EINVAL
,
/*!< illegal argument. */
MB_EPORTERR
,
/*!< porting layer error. */
MB_ENORES
,
/*!< insufficient resources. */
MB_EIO
,
/*!< I/O error. */
MB_EILLSTATE
,
/*!< protocol stack in illegal state. */
MB_ETIMEDOUT
,
/*!< timeout error occurred. */
MB_EMASTERNOERR
,
/*!< master mode no error. */
MB_EMASTERERR
,
/*!< master mode error. */
MB_EMASTERSENT
,
MB_RTUERNOERR
}
public
static
ModbusMaster
Modbus
;
public
static
ModbusMaster
Modbus
;
public
static
ushort
usCommunFailTimes
=
0
;
public
static
void
Modbus_ReadHoldingRegistersTask
(
out
ushort
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoints
,
out
bool
bCommStatu
s
)
public
static
eModbusErrorCode
Modbus_ReadHoldingRegistersTask
(
out
ushort
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoint
s
)
{
{
eModbusErrorCode
ModbusErrorCode
;
try
try
{
{
OutputValue
=
Modbus
.
ReadHoldingRegisters
(
slaveAddress
,
startAddress
,
numberOfPoints
);
OutputValue
=
Modbus
.
ReadHoldingRegisters
(
slaveAddress
,
startAddress
,
numberOfPoints
);
bCommStatus
=
true
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERNOERR
;
}
}
catch
(
Exception
exception
)
catch
(
Exception
exception
)
{
{
...
@@ -32,7 +48,8 @@ namespace ModbusDemo.MessageFormat
...
@@ -32,7 +48,8 @@ namespace ModbusDemo.MessageFormat
Console
.
WriteLine
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Console
.
WriteLine
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
OutputValue
=
new
ushort
[
numberOfPoints
];
OutputValue
=
new
ushort
[
numberOfPoints
];
bCommStatus
=
false
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_ETIMEDOUT
;
usCommunFailTimes
++;
}
}
//The server return error code.
//The server return error code.
//You can get the function code and exception code.
//You can get the function code and exception code.
...
@@ -90,15 +107,17 @@ namespace ModbusDemo.MessageFormat
...
@@ -90,15 +107,17 @@ namespace ModbusDemo.MessageFormat
}
}
}
}
OutputValue
=
new
ushort
[
numberOfPoints
];
OutputValue
=
new
ushort
[
numberOfPoints
];
bCommStatus
=
false
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
}
}
return
ModbusErrorCode
;
}
}
public
static
void
Modbus_ReadCoilsTask
(
out
bool
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoints
,
out
bool
bComStatu
s
)
public
static
eModbusErrorCode
Modbus_ReadCoilsTask
(
out
bool
[]
OutputValue
,
byte
slaveAddress
,
ushort
startAddress
,
ushort
numberOfPoint
s
)
{
{
eModbusErrorCode
ModbusErrorCode
;
try
try
{
{
OutputValue
=
Modbus
.
ReadCoils
(
slaveAddress
,
startAddress
,
numberOfPoints
);
OutputValue
=
Modbus
.
ReadCoils
(
slaveAddress
,
startAddress
,
numberOfPoints
);
bComStatus
=
true
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERNOERR
;
}
}
catch
(
Exception
exception
)
catch
(
Exception
exception
)
{
{
...
@@ -110,7 +129,8 @@ namespace ModbusDemo.MessageFormat
...
@@ -110,7 +129,8 @@ namespace ModbusDemo.MessageFormat
Console
.
WriteLine
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Console
.
WriteLine
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
OutputValue
=
new
bool
[
numberOfPoints
];
OutputValue
=
new
bool
[
numberOfPoints
];
bComStatus
=
false
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_ETIMEDOUT
;
usCommunFailTimes
++;
}
}
//The server return error code.
//The server return error code.
//You can get the function code and exception code.
//You can get the function code and exception code.
...
@@ -168,15 +188,17 @@ namespace ModbusDemo.MessageFormat
...
@@ -168,15 +188,17 @@ namespace ModbusDemo.MessageFormat
}
}
}
}
OutputValue
=
new
bool
[
numberOfPoints
];
OutputValue
=
new
bool
[
numberOfPoints
];
bComStatus
=
false
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
}
}
return
ModbusErrorCode
;
}
}
public
static
void
Modbus_WriteSingleCoil
(
byte
slaveAddress
,
ushort
startAddress
,
bool
[]
value
,
out
bool
bComStatus
)
public
static
eModbusErrorCode
Modbus_WriteSingleCoil
(
byte
slaveAddress
,
ushort
startAddress
,
bool
[]
value
)
{
{
eModbusErrorCode
ModbusErrorCode
;
try
try
{
{
Modbus
.
WriteMultipleCoils
(
slaveAddress
,
startAddress
,
value
);
Modbus
.
WriteMultipleCoils
(
slaveAddress
,
startAddress
,
value
);
bComStatus
=
true
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_ENOERR
;
}
}
catch
(
Exception
exception
)
catch
(
Exception
exception
)
{
{
...
@@ -187,7 +209,7 @@ namespace ModbusDemo.MessageFormat
...
@@ -187,7 +209,7 @@ namespace ModbusDemo.MessageFormat
{
{
Console
.
WriteLine
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Console
.
WriteLine
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
bComStatus
=
false
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_ETIMEDOUT
;
}
}
//The server return error code.
//The server return error code.
//You can get the function code and exception code.
//You can get the function code and exception code.
...
@@ -244,16 +266,17 @@ namespace ModbusDemo.MessageFormat
...
@@ -244,16 +266,17 @@ namespace ModbusDemo.MessageFormat
break
;
break
;
}
}
}
}
bComStatus
=
false
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
}
}
return
ModbusErrorCode
;
}
}
public
static
void
Modbus_WriteMultipleCoils
(
byte
slaveAddress
,
ushort
startAddress
,
bool
[]
data
,
out
bool
bComStatus
)
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
);
bComStatus
=
true
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_ENOERR
;
}
}
catch
(
Exception
exception
)
catch
(
Exception
exception
)
{
{
...
@@ -264,7 +287,7 @@ namespace ModbusDemo.MessageFormat
...
@@ -264,7 +287,7 @@ namespace ModbusDemo.MessageFormat
{
{
Console
.
WriteLine
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Console
.
WriteLine
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
Form1
.
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" "
+
exception
.
Message
);
bComStatus
=
false
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_ETIMEDOUT
;
}
}
//The server return error code.
//The server return error code.
//You can get the function code and exception code.
//You can get the function code and exception code.
...
@@ -321,9 +344,9 @@ namespace ModbusDemo.MessageFormat
...
@@ -321,9 +344,9 @@ namespace ModbusDemo.MessageFormat
break
;
break
;
}
}
}
}
bComStatus
=
false
;
ModbusErrorCode
=
eModbusErrorCode
.
MB_EMASTERERR
;
}
}
}
return
ModbusErrorCode
;
}
}
//private void Init_Read_data()
//private void Init_Read_data()
//{
//{
...
...
ModbusDemo/MessageFormat/mqttpacke.cs
View file @
be6916d5
...
@@ -21,15 +21,15 @@ namespace ModbusDemo
...
@@ -21,15 +21,15 @@ namespace ModbusDemo
{
{
public
string
addr
{
get
;
set
;
}
public
string
addr
{
get
;
set
;
}
public
double
d0
{
get
;
set
;
}
public
double
d0
{
get
;
set
;
}
public
int
d1
{
get
;
set
;
}
public
double
d1
{
get
;
set
;
}
public
int
d2
{
get
;
set
;
}
public
double
d2
{
get
;
set
;
}
public
int
d3
{
get
;
set
;
}
public
double
d3
{
get
;
set
;
}
public
int
d4
{
get
;
set
;
}
public
double
d4
{
get
;
set
;
}
public
int
d5
{
get
;
set
;
}
public
double
d5
{
get
;
set
;
}
public
int
d6
{
get
;
set
;
}
public
double
d6
{
get
;
set
;
}
public
int
d7
{
get
;
set
;
}
public
double
d7
{
get
;
set
;
}
public
UInt64
ts
{
get
;
set
;
}
public
UInt64
ts
{
get
;
set
;
}
public
WTDR18X
(
string
addr
,
double
d0
,
int
d1
,
int
d2
,
int
d3
,
int
d4
,
int
d5
,
int
d6
,
int
d7
,
UInt64
ts
)
public
WTDR18X
(
string
addr
,
double
d0
,
double
d1
,
double
d2
,
double
d3
,
double
d4
,
double
d5
,
double
d6
,
double
d7
,
UInt64
ts
)
{
{
this
.
addr
=
addr
;
this
.
addr
=
addr
;
this
.
d0
=
d0
;
this
.
d0
=
d0
;
...
@@ -47,11 +47,11 @@ namespace ModbusDemo
...
@@ -47,11 +47,11 @@ namespace ModbusDemo
{
{
public
string
addr
{
get
;
set
;
}
public
string
addr
{
get
;
set
;
}
public
double
d0
{
get
;
set
;
}
public
double
d0
{
get
;
set
;
}
public
int
d1
{
get
;
set
;
}
public
double
d1
{
get
;
set
;
}
public
int
d2
{
get
;
set
;
}
public
double
d2
{
get
;
set
;
}
public
int
d3
{
get
;
set
;
}
public
double
d3
{
get
;
set
;
}
public
UInt64
ts
{
get
;
set
;
}
public
UInt64
ts
{
get
;
set
;
}
public
WTDR14P
(
string
addr
,
double
d0
,
int
d1
,
int
d2
,
int
d3
,
UInt64
ts
)
public
WTDR14P
(
string
addr
,
double
d0
,
double
d1
,
double
d2
,
double
d3
,
UInt64
ts
)
{
{
this
.
addr
=
addr
;
this
.
addr
=
addr
;
this
.
d0
=
d0
;
this
.
d0
=
d0
;
...
@@ -85,6 +85,51 @@ namespace ModbusDemo
...
@@ -85,6 +85,51 @@ namespace ModbusDemo
}
}
}
}
class
WTDR78C
{
public
string
addr
{
get
;
set
;
}
public
int
d0
{
get
;
set
;
}
public
int
d1
{
get
;
set
;
}
public
int
d2
{
get
;
set
;
}
public
int
d3
{
get
;
set
;
}
public
int
d4
{
get
;
set
;
}
public
int
d5
{
get
;
set
;
}
public
int
d6
{
get
;
set
;
}
public
int
d7
{
get
;
set
;
}
public
int
d8
{
get
;
set
;
}
public
int
d9
{
get
;
set
;
}
public
int
d10
{
get
;
set
;
}
public
int
d11
{
get
;
set
;
}
public
int
d12
{
get
;
set
;
}
public
int
d13
{
get
;
set
;
}
public
int
d14
{
get
;
set
;
}
public
int
d15
{
get
;
set
;
}
public
UInt64
ts
{
get
;
set
;
}
public
WTDR78C
(
string
addr
,
int
d0
,
int
d1
,
int
d2
,
int
d3
,
int
d4
,
int
d5
,
int
d6
,
int
d7
,
int
d8
,
int
d9
,
int
d10
,
int
d11
,
int
d12
,
int
d13
,
int
d14
,
int
d15
,
UInt64
ts
)
{
this
.
addr
=
addr
;
this
.
d0
=
d0
;
this
.
d1
=
d1
;
this
.
d2
=
d2
;
this
.
d3
=
d3
;
this
.
d4
=
d4
;
this
.
d5
=
d5
;
this
.
d6
=
d6
;
this
.
d7
=
d7
;
this
.
d8
=
d8
;
this
.
d9
=
d9
;
this
.
d10
=
d10
;
this
.
d11
=
d11
;
this
.
d12
=
d12
;
this
.
d13
=
d13
;
this
.
d14
=
d14
;
this
.
d15
=
d15
;
this
.
ts
=
ts
;
}
}
public
class
Ctrl
public
class
Ctrl
{
{
...
@@ -225,46 +270,5 @@ namespace ModbusDemo
...
@@ -225,46 +270,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 @
be6916d5
...
@@ -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"
/>
...
@@ -94,11 +93,14 @@
...
@@ -94,11 +93,14 @@
<Compile
Include=
"application\ModbusToPool.cs"
/>
<Compile
Include=
"application\ModbusToPool.cs"
/>
<Compile
Include=
"application\Pond.cs"
/>
<Compile
Include=
"application\Pond.cs"
/>
<Compile
Include=
"application\UsThread.cs"
/>
<Compile
Include=
"application\UsThread.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"
/>
<Compile
Include=
"Modular\418X.cs"
/>
<Compile
Include=
"Modular\418X.cs"
/>
<Compile
Include=
"Common\Modbuslib.cs"
/>
<Compile
Include=
"Common\Modbuslib.cs"
/>
<Compile
Include=
"Modular\ModualPoll.cs"
/>
<Compile
Include=
"Modular\modual.cs"
/>
<Compile
Include=
"windows\Form1.cs"
>
<Compile
Include=
"windows\Form1.cs"
>
<SubType>
Form
</SubType>
<SubType>
Form
</SubType>
</Compile>
</Compile>
...
@@ -163,20 +165,6 @@
...
@@ -163,20 +165,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/418X.cs
View file @
be6916d5
...
@@ -60,7 +60,7 @@ namespace ModbusDemo
...
@@ -60,7 +60,7 @@ namespace ModbusDemo
users
.
UserCompany
=
Strcom
[
Inputtype
[
0
]];
//通道类型
users
.
UserCompany
=
Strcom
[
Inputtype
[
0
]];
//通道类型
users
.
UserModel
=
Inputtype
[
0
];
//确定计算公式
users
.
UserModel
=
Inputtype
[
0
];
//确定计算公式
/********************/
/********************/
users1
.
UserId
=
1
;
//通道
users1
.
UserId
=
1
;
//通道
;
users1
.
Data
=
typeData
[
1
];
//数据
users1
.
Data
=
typeData
[
1
];
//数据
users1
.
UserCompany
=
Strcom
[
Inputtype
[
1
]];
//通道类型
users1
.
UserCompany
=
Strcom
[
Inputtype
[
1
]];
//通道类型
users1
.
UserModel
=
Inputtype
[
1
];
//确定计算公式
users1
.
UserModel
=
Inputtype
[
1
];
//确定计算公式
...
...
ModbusDemo/Modular/ModualPoll.cs
0 → 100644
View file @
be6916d5
This diff is collapsed.
Click to expand it.
ModbusDemo/Modular/modual.cs
0 → 100644
View file @
be6916d5
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
ModbusDemo.MessageFormat
;
using
ModbusDemo.Common
;
namespace
ModbusDemo.Modular
{
public
class
modual
{
public
struct
psx14pData
{
public
ushort
[]
usX14pRegData
;
public
ushort
[]
usX14pRegType
;
public
double
[]
dNowConvertData
;
public
double
[]
dBeforeConvertData
;
}
public
struct
psxModualAlarm
{
public
bool
bDataNotFirstIncreaseOrDecrease
;
public
ushort
[]
usNowAlarmCode
;
public
ushort
[]
usBeforeAlarmCode
;
}
public
class
pcx14P
{
public
byte
[]
byModbusID
;
public
psx14pData
[]
sX14pDataStruct
=
new
psx14pData
[
ModualPoll
.
byX14pNumber
];
public
psxModualAlarm
[]
sX14PAlarmStruct
=
new
psxModualAlarm
[
ModualPoll
.
byX14pNumber
];
public
pcx14P
(
byte
[]
InitIDlist
)
{
this
.
byModbusID
=
InitIDlist
;
for
(
byte
i
=
0
;
i
<
ModualPoll
.
byX14pNumber
;
i
++)
{
this
.
sX14pDataStruct
[
i
].
dBeforeConvertData
=
new
double
[
ModualPoll
.
byX14pReadDataNumber
];
this
.
sX14pDataStruct
[
i
].
dNowConvertData
=
new
double
[
ModualPoll
.
byX14pReadDataNumber
];
//this.sX14pDataStruct[i].usX14pRegType = new ushort[ModualPoll.byX14pReadDataNumber];
//this.sX14pDataStruct[i].usX14pRegData = new ushort[ModualPoll.byX14pReadDataNumber];
this
.
sX14PAlarmStruct
[
i
].
usBeforeAlarmCode
=
new
ushort
[
ModualPoll
.
byX14pReadDataNumber
];
this
.
sX14PAlarmStruct
[
i
].
usNowAlarmCode
=
new
ushort
[
ModualPoll
.
byX14pReadDataNumber
];
}
}
}
public
enum
eX18xSensorChannelType
:
byte
{
Null
=
0
,
Weiertai
,
Mike_5
,
Mike_6
,
Mike_7
,
Level
,
}
public
struct
psX18xData
{
public
ushort
[]
usRegData
;
public
ushort
[]
usTypeData
;
public
double
[]
dNowConvertData
;
public
double
[]
dBeforeConvertData
;
}
public
class
pcx18X
{
public
byte
[]
byModbusID
;
public
psX18xData
[]
sX18xDataStruct
=
new
psX18xData
[
ModualPoll
.
byX18xNumber
];
public
psxModualAlarm
[]
sX18xAlarmstruct
=
new
psxModualAlarm
[
ModualPoll
.
byX18xNumber
];
public
eX18xSensorChannelType
[,]
beChannelType
;
public
pcx18X
(
byte
[]
InitIDlist
,
eX18xSensorChannelType
[,]
eChannnelType
)
{
this
.
byModbusID
=
InitIDlist
;
this
.
beChannelType
=
eChannnelType
;
for
(
byte
i
=
0
;
i
<
ModualPoll
.
byX18xNumber
;
i
++)
{
this
.
sX18xDataStruct
[
i
].
dBeforeConvertData
=
new
double
[
ModualPoll
.
byX18xReadDataNumber
];
this
.
sX18xDataStruct
[
i
].
dNowConvertData
=
new
double
[
ModualPoll
.
byX18xReadDataNumber
];
//this.sX18xDataStruct[i].usRegData = new ushort[ModualPoll.byX18xReadDataNumber];
//this.sX18xDataStruct[i].usTypeData = new ushort[ModualPoll.byX18xReadDataNumber];
this
.
sX18xAlarmstruct
[
i
].
usBeforeAlarmCode
=
new
ushort
[
ModualPoll
.
byX18xReadDataNumber
];
this
.
sX18xAlarmstruct
[
i
].
usNowAlarmCode
=
new
ushort
[
ModualPoll
.
byX18xReadDataNumber
];
}
}
}
public
struct
psx78C
{
public
bool
[]
bInputRegStatus
;
public
bool
[]
bOutPutRegStatus
;
}
public
class
pcx78C
{
public
byte
[]
byModbusID
;
public
psx78C
[]
sX78cRegStatusStruct
=
new
psx78C
[
ModualPoll
.
byX78cNumber
];
public
psxModualAlarm
[]
sX78cAlarmStruct
=
new
psxModualAlarm
[
ModualPoll
.
byX78cNumber
];
public
pcx78C
(
byte
[]
InitIDlist
)
{
this
.
byModbusID
=
InitIDlist
;
for
(
byte
i
=
0
;
i
<
ModualPoll
.
byX78cNumber
;
i
++)
{
this
.
sX78cRegStatusStruct
[
i
].
bInputRegStatus
=
new
bool
[
ModualPoll
.
byX78cInputRegNumber
];
this
.
sX78cRegStatusStruct
[
i
].
bOutPutRegStatus
=
new
bool
[
ModualPoll
.
byX78cOutputRegNumber
];
this
.
sX78cAlarmStruct
[
i
].
usBeforeAlarmCode
=
new
ushort
[
ModualPoll
.
byX78cInputRegNumber
+
ModualPoll
.
byX78cOutputRegNumber
];
this
.
sX78cAlarmStruct
[
i
].
usNowAlarmCode
=
new
ushort
[
ModualPoll
.
byX78cInputRegNumber
+
ModualPoll
.
byX78cOutputRegNumber
];
}
}
}
public
struct
psx66C
{
public
bool
[]
bRegRelayStatus
;
}
public
class
pcx66C
{
public
byte
[]
byModbusID
;
public
psx66C
[]
sX66cRegStatusStruct
=
new
psx66C
[
ModualPoll
.
byX66cNumber
];
public
psxModualAlarm
[]
sX66cAlarmStruct
=
new
psxModualAlarm
[
ModualPoll
.
byX66cNumber
];
public
pcx66C
(
byte
[]
InitIDlist
)
{
this
.
byModbusID
=
InitIDlist
;
for
(
byte
i
=
0
;
i
<
ModualPoll
.
byX66cNumber
;
i
++)
{
this
.
sX66cRegStatusStruct
[
i
].
bRegRelayStatus
=
new
bool
[
ModualPoll
.
byX66cRelayRegNumber
];
this
.
sX66cAlarmStruct
[
i
].
usBeforeAlarmCode
=
new
ushort
[
ModualPoll
.
byX66cRelayRegNumber
];
this
.
sX66cAlarmStruct
[
i
].
usNowAlarmCode
=
new
ushort
[
ModualPoll
.
byX66cRelayRegNumber
];
}
}
}
}
}
ModbusDemo/application/ModbusToPool.cs
View file @
be6916d5
This diff is collapsed.
Click to expand it.
ModbusDemo/application/Pond.cs
View file @
be6916d5
...
@@ -77,26 +77,26 @@ namespace ModbusDemo.application
...
@@ -77,26 +77,26 @@ namespace ModbusDemo.application
// }
// }
//}
//}
public
class
pcPump
//
public class pcPump
{
//
{
public
double
dPumpCurrent
;
//
public double dPumpCurrent;
public
double
dPumpVoltage
;
//
public double dPumpVoltage;
public
bool
bPumpStatus
;
//
public bool bPumpStatus;
public
bool
bPumpHasOpen
;
//
public bool bPumpHasOpen;
public
void
vOpen_Pump
()
//
public void vOpen_Pump()
{
//
{
}
//
}
public
void
vClose_Pump
()
//
public void vClose_Pump()
{
//
{
}
//
}
public
void
vGet_Pump_Status
()
//
public void vGet_Pump_Status()
{
//
{
}
//
}
}
//
}
public
class
pcTemperatureData
public
class
pcTemperatureData
...
...
ModbusDemo/application/PoolModbusSet.cs
View file @
be6916d5
This diff is collapsed.
Click to expand it.
ModbusDemo/windows/Form1.Designer.cs
View file @
be6916d5
...
@@ -59,6 +59,8 @@
...
@@ -59,6 +59,8 @@
this
.
label4
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
label4
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
button2
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
button2
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
SubscribeBut
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
SubscribeBut
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
label5
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
label6
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
updateops
.
SuspendLayout
();
this
.
updateops
.
SuspendLayout
();
this
.
SuspendLayout
();
this
.
SuspendLayout
();
//
//
...
@@ -323,7 +325,7 @@
...
@@ -323,7 +325,7 @@
//
//
this
.
label2
.
AutoSize
=
true
;
this
.
label2
.
AutoSize
=
true
;
this
.
label2
.
Font
=
new
System
.
Drawing
.
Font
(
"宋体"
,
12F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
label2
.
Font
=
new
System
.
Drawing
.
Font
(
"宋体"
,
12F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
label2
.
Location
=
new
System
.
Drawing
.
Point
(
44
,
4
92
);
this
.
label2
.
Location
=
new
System
.
Drawing
.
Point
(
44
,
4
87
);
this
.
label2
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
0
,
4
,
0
);
this
.
label2
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
0
,
4
,
0
);
this
.
label2
.
Name
=
"label2"
;
this
.
label2
.
Name
=
"label2"
;
this
.
label2
.
Size
=
new
System
.
Drawing
.
Size
(
69
,
20
);
this
.
label2
.
Size
=
new
System
.
Drawing
.
Size
(
69
,
20
);
...
@@ -343,7 +345,7 @@
...
@@ -343,7 +345,7 @@
// label4
// label4
//
//
this
.
label4
.
AutoSize
=
true
;
this
.
label4
.
AutoSize
=
true
;
this
.
label4
.
Location
=
new
System
.
Drawing
.
Point
(
108
,
49
8
);
this
.
label4
.
Location
=
new
System
.
Drawing
.
Point
(
108
,
49
2
);
this
.
label4
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
0
,
4
,
0
);
this
.
label4
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
4
,
0
,
4
,
0
);
this
.
label4
.
Name
=
"label4"
;
this
.
label4
.
Name
=
"label4"
;
this
.
label4
.
Size
=
new
System
.
Drawing
.
Size
(
55
,
15
);
this
.
label4
.
Size
=
new
System
.
Drawing
.
Size
(
55
,
15
);
...
@@ -372,11 +374,31 @@
...
@@ -372,11 +374,31 @@
this
.
SubscribeBut
.
UseVisualStyleBackColor
=
true
;
this
.
SubscribeBut
.
UseVisualStyleBackColor
=
true
;
this
.
SubscribeBut
.
Click
+=
new
System
.
EventHandler
(
this
.
SubscribeBut_Click
);
this
.
SubscribeBut
.
Click
+=
new
System
.
EventHandler
(
this
.
SubscribeBut_Click
);
//
//
// label5
//
this
.
label5
.
AutoSize
=
true
;
this
.
label5
.
Location
=
new
System
.
Drawing
.
Point
(
111
,
528
);
this
.
label5
.
Name
=
"label5"
;
this
.
label5
.
Size
=
new
System
.
Drawing
.
Size
(
55
,
15
);
this
.
label5
.
TabIndex
=
99
;
this
.
label5
.
Text
=
"label5"
;
//
// label6
//
this
.
label6
.
AutoSize
=
true
;
this
.
label6
.
Location
=
new
System
.
Drawing
.
Point
(
23
,
528
);
this
.
label6
.
Name
=
"label6"
;
this
.
label6
.
Size
=
new
System
.
Drawing
.
Size
(
82
,
15
);
this
.
label6
.
TabIndex
=
100
;
this
.
label6
.
Text
=
"超时次数:"
;
//
// Form1
// Form1
//
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
8F
,
15F
);
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
8F
,
15F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1184
,
672
);
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1184
,
672
);
this
.
Controls
.
Add
(
this
.
label6
);
this
.
Controls
.
Add
(
this
.
label5
);
this
.
Controls
.
Add
(
this
.
SubscribeBut
);
this
.
Controls
.
Add
(
this
.
SubscribeBut
);
this
.
Controls
.
Add
(
this
.
button2
);
this
.
Controls
.
Add
(
this
.
button2
);
this
.
Controls
.
Add
(
this
.
label4
);
this
.
Controls
.
Add
(
this
.
label4
);
...
@@ -441,5 +463,7 @@
...
@@ -441,5 +463,7 @@
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
Button
button2
;
private
System
.
Windows
.
Forms
.
Button
button2
;
private
System
.
Windows
.
Forms
.
Button
SubscribeBut
;
private
System
.
Windows
.
Forms
.
Button
SubscribeBut
;
private
System
.
Windows
.
Forms
.
Label
label5
;
private
System
.
Windows
.
Forms
.
Label
label6
;
}
}
}
}
\ No newline at end of file
ModbusDemo/windows/Form1.cs
View file @
be6916d5
This diff is collapsed.
Click to expand it.
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