Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
JmpZbChannel
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
zxw
JmpZbChannel
Commits
95285e79
Commit
95285e79
authored
Sep 22, 2022
by
zonevg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mqtt 货架展示屏
parent
c1711ef1
全部展开
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
276 行增加
和
11 行删除
+276
-11
LocalConfig.cs
JmpCommon/Model/LocalConfig.cs
+2
-0
FrmConfig.Designer.cs
JmpServiceMgr/FrmConfig.Designer.cs
+0
-0
FrmConfig.cs
JmpServiceMgr/FrmConfig.cs
+42
-9
FrmMgr.cs
JmpServiceMgr/FrmMgr.cs
+10
-1
MQTTServer.cs
JmpServiceMgr/Helper/MQTTServer.cs
+193
-0
RFIDReaderHelper.cs
JmpServiceMgr/Helper/RFIDReaderHelper.cs
+21
-0
JmpServiceMgr.csproj
JmpServiceMgr/JmpServiceMgr.csproj
+3
-1
app.config
JmpServiceMgr/app.config
+5
-0
没有找到文件。
JmpCommon/Model/LocalConfig.cs
View file @
95285e79
...
...
@@ -63,6 +63,7 @@ namespace JmpCommon
MQTTPassword
=
"junmp123"
;
IsPushShelfPrint
=
false
;
PushShelfPrintType
=
0
;
//默认com
PushShelfPrintCom
=
""
;
}
...
...
@@ -102,6 +103,7 @@ namespace JmpCommon
public
string
MQTTPassword
{
get
;
set
;
}
public
bool
IsPushShelfPrint
{
get
;
set
;
}
public
int
PushShelfPrintType
{
get
;
set
;
}
public
string
PushShelfPrintCom
{
get
;
set
;
}
}
}
JmpServiceMgr/FrmConfig.Designer.cs
View file @
95285e79
差异被折叠。
点击展开。
JmpServiceMgr/FrmConfig.cs
View file @
95285e79
...
...
@@ -175,9 +175,12 @@ namespace JmpServiceMgr
tb_mqttPort
.
Text
=
MyCache
.
SysConfig
.
MQTTPort
.
ToString
();
chk_pushShelfPrint
.
Checked
=
MyCache
.
SysConfig
.
IsPushShelfPrint
;
cbb_shelfPrintType
.
SelectedIndex
=
MyCache
.
SysConfig
.
PushShelfPrintType
;
if
(
chk_pushShelfPrint
.
Checked
)
{
cbb_shelfPrintCom
.
Visible
=
true
;
if
(
cbb_shelfPrintType
.
SelectedIndex
==
0
)
{
cbb_shelfPrintCom
.
Items
.
Clear
();
cbb_shelfPrintCom
.
Items
.
AddRange
(
SerialPort
.
GetPortNames
());
if
(
cbb_shelfPrintCom
.
Items
.
Count
>
0
)
...
...
@@ -195,9 +198,17 @@ namespace JmpServiceMgr
}
else
{
cbb_shelfPrintCom
.
Visible
=
false
;
lb_shelfPrintCom
.
Enabled
=
false
;
cbb_shelfPrintCom
.
Enabled
=
false
;
}
}
else
{
lb_shelfPrintType
.
Enabled
=
false
;
cbb_shelfPrintType
.
Enabled
=
false
;
lb_shelfPrintCom
.
Enabled
=
false
;
cbb_shelfPrintCom
.
Enabled
=
false
;
}
}
private
void
btnColse_Click
(
object
sender
,
EventArgs
e
)
{
...
...
@@ -318,8 +329,9 @@ namespace JmpServiceMgr
MyCache
.
SysConfig
.
MQTTPort
=
Convert
.
ToInt32
(
tb_mqttPort
.
Text
);
MyCache
.
SysConfig
.
IsPushShelfPrint
=
chk_pushShelfPrint
.
Checked
;
MyCache
.
SysConfig
.
PushShelfPrintCom
=
cbb_shelfPrintCom
.
Text
;
if
(
chk_pushShelfPrint
.
Checked
)
MyCache
.
SysConfig
.
PushShelfPrintType
=
cbb_shelfPrintType
.
SelectedIndex
;
if
(
chk_pushShelfPrint
.
Checked
&&
cbb_shelfPrintType
.
SelectedIndex
==
0
)
{
MyCache
.
SysConfig
.
PushShelfPrintCom
=
cbb_shelfPrintCom
.
Text
;
}
...
...
@@ -365,7 +377,29 @@ namespace JmpServiceMgr
{
if
(
box
.
Checked
)
{
cbb_shelfPrintCom
.
Visible
=
true
;
lb_shelfPrintType
.
Enabled
=
true
;
cbb_shelfPrintType
.
Enabled
=
true
;
cbb_shelfPrintType_SelectedIndexChanged
(
null
,
null
);
}
else
{
lb_shelfPrintType
.
Enabled
=
false
;
cbb_shelfPrintType
.
Enabled
=
false
;
lb_shelfPrintCom
.
Enabled
=
false
;
cbb_shelfPrintCom
.
Enabled
=
false
;
}
}
}
private
void
cbb_shelfPrintType_SelectedIndexChanged
(
object
sender
,
EventArgs
e
)
{
if
(
cbb_shelfPrintType
.
SelectedIndex
==
0
)
{
lb_shelfPrintCom
.
Enabled
=
true
;
cbb_shelfPrintCom
.
Enabled
=
true
;
cbb_shelfPrintCom
.
Items
.
Clear
();
cbb_shelfPrintCom
.
Items
.
AddRange
(
SerialPort
.
GetPortNames
());
if
(
cbb_shelfPrintCom
.
Items
.
Count
>
0
)
...
...
@@ -383,10 +417,9 @@ namespace JmpServiceMgr
}
else
{
cbb_shelfPrintCom
.
Visible
=
false
;
}
lb_shelfPrintCom
.
Enabled
=
false
;
cbb_shelfPrintCom
.
Enabled
=
false
;
}
}
}
}
JmpServiceMgr/FrmMgr.cs
View file @
95285e79
...
...
@@ -56,6 +56,7 @@ namespace JmpServiceMgr
public
List
<
RFIDReaderHelper
>
ReaderHelperList
;
public
List
<
HikFaceHelper
>
HikFaceHelperList
;
public
MQTTHelper
MqttHelper
;
public
MQTTServer
MqttServer
;
public
SerialPortHelper
SerialPortHelper
;
private
CancellationTokenSource
CTol
;
...
...
@@ -293,10 +294,18 @@ namespace JmpServiceMgr
MqttHelper
.
InitialMQTT
();
if
(
MyCache
.
SysConfig
.
IsPushShelfPrint
)
{
//启动
if
(
MyCache
.
SysConfig
.
PushShelfPrintType
==
0
)
{
//com
SerialPortHelper
=
new
SerialPortHelper
(
this
,
CTol
);
SerialPortHelper
.
InitialSerialPort
();
}
else
{
//启动mqtt服务端推送出入库信息
MqttServer
=
new
MQTTServer
();
}
}
HikFaceHelperList
=
new
List
<
HikFaceHelper
>();
foreach
(
var
config
in
MyCache
.
ChannelCfg
.
faceConfig
)
...
...
JmpServiceMgr/Helper/MQTTServer.cs
0 → 100644
View file @
95285e79
using
JmpCommon
;
using
MQTTnet
;
using
MQTTnet.Client
;
using
MQTTnet.Client.Connecting
;
using
MQTTnet.Client.Disconnecting
;
using
MQTTnet.Client.Options
;
using
MQTTnet.Client.Receiving
;
using
MQTTnet.Protocol
;
using
System
;
using
System.Text
;
using
System.Threading
;
using
Newtonsoft.Json.Linq
;
using
MQTTnet.Server
;
using
System.Configuration
;
namespace
JmpServiceMgr.Helper
{
public
class
MQTTServer
:
IDisposable
{
public
MqttServer
mqttServer
{
get
;
set
;
}
public
MQTTServer
()
{
StartMqttServer
();
}
public
async
void
StartMqttServer
()
{
try
{
if
(
mqttServer
==
null
)
{
var
optionsBuilder
=
new
MqttServerOptionsBuilder
()
.
WithDefaultEndpoint
()
.
WithDefaultEndpointPort
(
int
.
Parse
(
ConfigurationManager
.
AppSettings
[
"MQTTPort"
]))
.
WithConnectionValidator
(
c
=>
{
var
currentUser
=
ConfigurationManager
.
AppSettings
[
"UserName"
];
var
currentPWD
=
ConfigurationManager
.
AppSettings
[
"Password"
];
if
(
string
.
IsNullOrEmpty
(
currentUser
)
||
string
.
IsNullOrEmpty
(
currentPWD
))
{
c
.
ReasonCode
=
MqttConnectReasonCode
.
BadUserNameOrPassword
;
return
;
}
if
(
c
.
Username
!=
currentUser
)
{
c
.
ReasonCode
=
MqttConnectReasonCode
.
BadUserNameOrPassword
;
return
;
}
if
(
c
.
Password
!=
currentPWD
)
{
c
.
ReasonCode
=
MqttConnectReasonCode
.
BadUserNameOrPassword
;
return
;
}
c
.
ReasonCode
=
MqttConnectReasonCode
.
Success
;
})
.
WithSubscriptionInterceptor
(
c
=>
{
c
.
AcceptSubscription
=
true
;
})
.
WithApplicationMessageInterceptor
(
c
=>
{
c
.
AcceptPublish
=
true
;
});
mqttServer
=
new
MqttFactory
().
CreateMqttServer
()
as
MqttServer
;
mqttServer
.
StartedHandler
=
new
MqttServerStartedHandlerDelegate
(
OnMqttServerStarted
);
mqttServer
.
StoppedHandler
=
new
MqttServerStoppedHandlerDelegate
(
OnMqttServerStopped
);
mqttServer
.
ClientConnectedHandler
=
new
MqttServerClientConnectedHandlerDelegate
(
OnMqttServerClientConnected
);
mqttServer
.
ClientDisconnectedHandler
=
new
MqttServerClientDisconnectedHandlerDelegate
(
OnMqttServerClientDisconnected
);
mqttServer
.
ClientSubscribedTopicHandler
=
new
MqttServerClientSubscribedTopicHandlerDelegate
(
OnMqttServerClientSubscribedTopic
);
mqttServer
.
ClientUnsubscribedTopicHandler
=
new
MqttServerClientUnsubscribedTopicHandlerDelegate
(
OnMqttServerClientUnsubscribedTopic
);
mqttServer
.
ApplicationMessageReceivedHandler
=
new
MqttApplicationMessageReceivedHandlerDelegate
(
OnMqttServer_ApplicationMessageReceived
);
await
mqttServer
.
StartAsync
(
optionsBuilder
.
Build
());
//lbxMonitor.BeginInvoke(_updateMonitorAction,
// Logger.TraceLog(Logger.Level.Info, "MQTT Server is started."));
}
}
catch
(
Exception
ex
)
{
//lbxMonitor.BeginInvoke(_updateMonitorAction,
// Logger.TraceLog(Logger.Level.Fatal, $"MQTT Server start fail.>{ex.Message}"));
}
}
public
async
void
StopMqttServer
()
{
if
(
mqttServer
==
null
)
return
;
try
{
await
mqttServer
?.
StopAsync
();
mqttServer
=
null
;
//lbxMonitor.BeginInvoke(_updateMonitorAction,
// Logger.TraceLog(Logger.Level.Info, "MQTT Server is stopped."));
}
catch
(
Exception
ex
)
{
//lbxMonitor.BeginInvoke(_updateMonitorAction,
// Logger.TraceLog(Logger.Level.Fatal, $"MQTT Server stop fail.>{ex.Message}"));
}
}
public
async
void
ServerPublishMqttTopic
(
string
topic
,
string
payload
)
{
var
message
=
new
MqttApplicationMessage
()
{
Topic
=
topic
,
Payload
=
Encoding
.
UTF8
.
GetBytes
(
payload
)
};
await
mqttServer
.
PublishAsync
(
message
);
//lbxMonitor.BeginInvoke(_updateMonitorAction,
// Logger.TraceLog(Logger.Level.Info, string.Format("MQTT Broker发布主题[{0}]成功!", topic)));
}
public
void
OnMqttServerStarted
(
EventArgs
e
)
{
//Console.WriteLine("MQTT服务启动完成!");
}
public
void
OnMqttServerStopped
(
EventArgs
e
)
{
//Console.WriteLine("MQTT服务停止完成!");
}
public
void
OnMqttServerClientConnected
(
MqttServerClientConnectedEventArgs
e
)
{
//Console.WriteLine($"客户端[{e.ClientId}]已连接");
}
public
void
OnMqttServerClientDisconnected
(
MqttServerClientDisconnectedEventArgs
e
)
{
//Console.WriteLine($"客户端[{e.ClientId}]已断开连接!");
}
public
void
OnMqttServerClientSubscribedTopic
(
MqttServerClientSubscribedTopicEventArgs
e
)
{
//Console.WriteLine($"客户端[{e.ClientId}]已成功订阅主题[{e.TopicFilter}]!");
}
public
void
OnMqttServerClientUnsubscribedTopic
(
MqttServerClientUnsubscribedTopicEventArgs
e
)
{
//Console.WriteLine($"客户端[{e.ClientId}]已成功取消订阅主题[{e.TopicFilter}]!");
}
public
void
OnMqttServer_ApplicationMessageReceived
(
MqttApplicationMessageReceivedEventArgs
e
)
{
try
{
if
(
string
.
IsNullOrEmpty
(
e
.
ClientId
))
{
return
;
}
var
DeviceNo
=
e
.
ClientId
;
var
Topic
=
e
.
ApplicationMessage
.
Topic
;
var
Payload
=
Encoding
.
UTF8
.
GetString
(
e
.
ApplicationMessage
.
Payload
);
if
(
Payload
.
Length
>
2
&&
Payload
.
Substring
(
0
,
2
)
==
"/C"
)
//控制消息
{
var
data
=
Payload
.
Split
(
'|'
);
if
(
data
.
Length
==
3
)
{
Topic
=
data
[
1
];
var
jObj
=
JObject
.
Parse
(
data
[
2
]);
if
(
Topic
==
"ShelfGetWarehouse"
)
{
ServerPublishMqttTopic
(
DeviceNo
,
$"/C|ResponseShelfGetWarehouse|
{{
\
"warehouseId\":\"{MyCache.ChannelCfg.warehouseId}\"}}"
);
}
}
}
//Console.WriteLine($"客户端[{e.ClientId}]>> 主题:{e.ApplicationMessage.Topic} 负荷:{Encoding.UTF8.GetString(e.ApplicationMessage.Payload)} Qos:{e.ApplicationMessage.QualityOfServiceLevel} 保留:{e.ApplicationMessage.Retain}");
}
catch
(
Exception
exception
)
{
//catch
}
}
public
void
Dispose
()
{
StopMqttServer
();
}
}
}
JmpServiceMgr/Helper/RFIDReaderHelper.cs
View file @
95285e79
...
...
@@ -566,7 +566,28 @@ namespace JmpServiceMgr.Helper
{
Task
.
Run
(()
=>
{
if
(
MyCache
.
SysConfig
.
PushShelfPrintType
==
0
)
{
//com
_form
.
SerialPortHelper
.
CreateOrderPushData
(
pushResultList
);
}
else
{
//mqtt
foreach
(
var
client
in
_form
.
MqttServer
.
mqttServer
.
GetClientStatusAsync
().
Result
)
{
_form
.
MqttServer
.
ServerPublishMqttTopic
(
client
.
ClientId
,
$"/C|ChannelIn|"
+
JsonConvert
.
SerializeObject
(
pushResultList
.
Where
(
x
=>
x
.
currentState
==
0
)
.
GroupBy
(
x
=>
new
{
x
.
name
,
x
.
Size
})
.
Select
(
x
=>
new
{
name
=
x
.
Key
.
name
,
shelfAddress
=
x
.
FirstOrDefault
()?.
shelfAddress
,
Size
=
x
.
Key
.
Size
})));
}
}
});
}
}
...
...
JmpServiceMgr/JmpServiceMgr.csproj
View file @
95285e79
...
...
@@ -101,6 +101,7 @@
<HintPath>..\Lib\SReaderAPI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.ServiceProcess" />
...
...
@@ -138,6 +139,7 @@
<Compile Include="Helper\CameraHelper.cs" />
<Compile Include="Helper\Model\ShelfMessageStatus.cs" />
<Compile Include="Helper\Model\TagReport.cs" />
<Compile Include="Helper\MQTTServer.cs" />
<Compile Include="Helper\SerialPortHelper.cs" />
<Compile Include="Helper\Reader\Solid401RFIDReader.cs" />
<Compile Include="Helper\MQTTHelper.cs" />
...
...
@@ -174,7 +176,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<
EmbeddedResourc
e Include="app.config" />
<
Non
e Include="app.config" />
<EmbeddedResource Include="RfidConfig.resx">
<DependentUpon>RfidConfig.cs</DependentUpon>
</EmbeddedResource>
...
...
JmpServiceMgr/app.config
View file @
95285e79
...
...
@@ -3,4 +3,9 @@
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.6.1"
/>
</
startup
>
<
appSettings
>
<
add
key
=
"MQTTPort"
value
=
"17777"
/>
<
add
key
=
"UserName"
value
=
"test"
/>
<
add
key
=
"Password"
value
=
"junmp123"
/>
</
appSettings
>
</
configuration
>
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论