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
5c95addb
Commit
5c95addb
authored
Jun 20, 2019
by
shaxuezheng
Browse files
Options
Browse Files
Download
Plain Diff
merge origin
parents
96689972
468680e9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
45 deletions
+80
-45
ModualAlarm.cs
ModbusDemo/Common/ModualAlarm.cs
+10
-7
Form1.cs
ModbusDemo/windows/Form1.cs
+70
-38
No files found.
ModbusDemo/Common/ModualAlarm.cs
View file @
5c95addb
...
...
@@ -48,6 +48,8 @@ namespace ModbusDemo.Common
}
public
static
async
Task
vPublishAlarmPackageJson
(
IMqttClient
mqttClient
)
{
if
(
mqttClient
.
IsConnected
==
true
)
{
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
Form1
.
sAlarmTopic
)
...
...
@@ -57,6 +59,7 @@ namespace ModbusDemo.Common
.
Build
();
await
mqttClient
.
PublishAsync
(
message
);
}
}
public
static
void
vSet_Modual_Alarm
(
byte
byModbusID
,
ushort
usAlarmCodde
,
bool
bSetAlarm
,
byte
byCommFailTimes
,
params
string
[]
strChannalList
)
{
for
(
int
i
=
0
;
i
<
ModualPoll
.
byX14pNumber
;
i
++)
...
...
ModbusDemo/windows/Form1.cs
View file @
5c95addb
...
...
@@ -114,7 +114,6 @@ namespace ModbusDemo
{
while
(
m_Isbgw0_CanContinueRun
)
{
int
_n
=
2
;
this
.
Invoke
(
new
Action
(()
=>
{
}));
...
...
@@ -143,6 +142,8 @@ namespace ModbusDemo
private
Thread
MqttReceiveThread
;
public
List
<
string
>
ListHandle
=
new
List
<
string
>();
private
async
Task
Publish
()
{
if
(
mqttClient
.
IsConnected
==
true
)
{
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
mqttTopic
)
...
...
@@ -155,7 +156,10 @@ namespace ModbusDemo
await
mqttClient
.
PublishAsync
(
message
);
}
}
}
private
void
vControlResponseBack
()
{
if
(
mqttClient
.
IsConnected
==
true
)
{
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
mqttBackTopic
)
...
...
@@ -165,8 +169,11 @@ namespace ModbusDemo
.
Build
();
mqttClient
.
PublishAsync
(
message
);
}
}
private
async
Task
vCfgResponseBack
(
string
data
)
{
if
(
mqttClient
.
IsConnected
==
true
)
{
var
message
=
new
MqttApplicationMessageBuilder
()
.
WithTopic
(
mqttCfgResTopic
)
...
...
@@ -176,6 +183,7 @@ namespace ModbusDemo
.
Build
();
await
mqttClient
.
PublishAsync
(
message
);
}
}
private
async
Task
Subscribe
()
{
if
(!
mqttClient
.
IsConnected
)
...
...
@@ -354,7 +362,6 @@ namespace ModbusDemo
}
})));
}
private
void
vMqtt_Receive_Handle
()
{
while
(
true
)
...
...
@@ -373,8 +380,8 @@ namespace ModbusDemo
#
region
modbus
线程
private
static
bool
bSetDataIsRunning
=
false
;
private
Thread
ModbusPollThread
;
private
void
vModbusPoll
()
{
while
(
true
)
...
...
@@ -389,7 +396,7 @@ namespace ModbusDemo
private
void
Sendout
()
{
Control
.
CheckForIllegalCrossThreadCalls
=
false
;
MQTTTimer
.
Interval
=
20000
;
//120500
MQTTTimer
.
Interval
=
20000
l
;
//120500
MQTTTimer
.
Enabled
=
true
;
MQTTTimer
.
AutoReset
=
true
;
//设置是执行一次(false)还是一直执行(true);
MQTTTimer
.
Start
();
...
...
@@ -989,6 +996,8 @@ namespace ModbusDemo
{
}
private
void
SubscribeBut_Click
(
object
sender
,
EventArgs
e
)
{
...
...
@@ -1044,12 +1053,25 @@ namespace ModbusDemo
SetMqtt
();
MQTT_thread
=
new
MethodInvoker
(
Sendout
);
MQTT_thread
.
BeginInvoke
(
null
,
null
);
await
Task
.
Run
(
async
()
=>
{
await
ConnectMqttServerAsync
();
});
ModbusComm
.
Modbus
=
ModbusSerialMaster
.
CreateRtu
(
comPort
);
ModbusComm
.
Modbus
.
Transport
.
Retries
=
0
;
ModbusComm
.
Modbus
.
Transport
.
ReadTimeout
=
1000
;
ModbusComm
.
Modbus
.
Transport
.
WriteTimeout
=
1000
;
ModbusComm
.
Modbus
.
Transport
.
WaitToRetryMilliseconds
=
0
;
<<<<<<<
HEAD
//t_AutoControl = new Thread(T_AutoControl);
//t_AutoControl.IsBackground = true;
//t_AutoControl.Start();
=======
//t_AutoControl = new Thread(T_AutoControl)
//{
// IsBackground = true
//};
//t_AutoControl.Start();
modbus_Timer
.
Enabled
=
true
;
btOpenCOM
.
Enabled
=
false
;
...
...
@@ -1108,25 +1130,35 @@ namespace ModbusDemo
ModbusComm
.
Modbus
.
Transport
.
WriteTimeout
=
1000
;
ModbusComm
.
Modbus
.
Transport
.
WaitToRetryMilliseconds
=
0
;
t_AutoControl
=
new
Thread
(
AtuoControl_run
);
t_AutoControl
.
IsBackground
=
true
;
t_AutoControl
.
Start
();
//t_AutoControl = new Thread(T_AutoControl)
//{
// IsBackground = true
//};
//t_AutoControl.Start();
modbus_Timer
.
Enabled
=
true
;
btOpenCOM
.
Enabled
=
false
;
btCloseCOM
.
Enabled
=
true
;
if
(
bCretaThead
==
false
)
{
if
(
bCretaThead
==
false
)
{
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
{
ModbusPollThread
.
Resume
();
}
totxt
.
Log
(
DateTime
.
Now
.
ToString
()
+
" =>Open "
+
comPort
.
PortName
+
" sucessfully!"
);
await
Subscribe
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment