Commit 95285e79 by zonevg

mqtt 货架展示屏

parent c1711ef1
......@@ -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; }
}
}
......@@ -52,6 +52,7 @@ namespace JmpServiceMgr
this.txtDomain = new DevComponents.DotNetBar.Controls.TextBoxX();
this.label10 = new System.Windows.Forms.Label();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.chk_syncCard = new DevComponents.DotNetBar.Controls.CheckBoxX();
this.cbb_shelfPrintCom = new System.Windows.Forms.ComboBox();
this.chk_pushShelfPrint = new DevComponents.DotNetBar.Controls.CheckBoxX();
this.chk_changeWarehouse = new DevComponents.DotNetBar.Controls.CheckBoxX();
......@@ -69,7 +70,9 @@ namespace JmpServiceMgr
this.superTabItem2 = new DevComponents.DotNetBar.SuperTabItem();
this.superTabControlPanel1 = new DevComponents.DotNetBar.SuperTabControlPanel();
this.superTabItem1 = new DevComponents.DotNetBar.SuperTabItem();
this.chk_syncCard = new DevComponents.DotNetBar.Controls.CheckBoxX();
this.cbb_shelfPrintType = new System.Windows.Forms.ComboBox();
this.lb_shelfPrintCom = new System.Windows.Forms.Label();
this.lb_shelfPrintType = new System.Windows.Forms.Label();
this.groupBox4.SuspendLayout();
this.groupBox5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.superTabControl1)).BeginInit();
......@@ -80,7 +83,7 @@ namespace JmpServiceMgr
//
this.btnSave.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
this.btnSave.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.btnSave.Location = new System.Drawing.Point(464, 701);
this.btnSave.Location = new System.Drawing.Point(460, 729);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(96, 40);
this.btnSave.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
......@@ -92,7 +95,7 @@ namespace JmpServiceMgr
//
this.btnColse.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
this.btnColse.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.btnColse.Location = new System.Drawing.Point(592, 701);
this.btnColse.Location = new System.Drawing.Point(588, 729);
this.btnColse.Name = "btnColse";
this.btnColse.Size = new System.Drawing.Size(96, 40);
this.btnColse.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
......@@ -108,7 +111,7 @@ namespace JmpServiceMgr
//
this.labelX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
this.labelX1.ForeColor = System.Drawing.Color.Black;
this.labelX1.Location = new System.Drawing.Point(11, 692);
this.labelX1.Location = new System.Drawing.Point(7, 720);
this.labelX1.Name = "labelX1";
this.labelX1.Size = new System.Drawing.Size(445, 23);
this.labelX1.TabIndex = 7;
......@@ -136,7 +139,7 @@ namespace JmpServiceMgr
this.groupBox4.ForeColor = System.Drawing.Color.Black;
this.groupBox4.Location = new System.Drawing.Point(12, 340);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(387, 346);
this.groupBox4.Size = new System.Drawing.Size(387, 374);
this.groupBox4.TabIndex = 8;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "接口配置";
......@@ -154,7 +157,7 @@ namespace JmpServiceMgr
this.tb_mqttPort.Location = new System.Drawing.Point(303, 275);
this.tb_mqttPort.Name = "tb_mqttPort";
this.tb_mqttPort.PreventEnterBeep = true;
this.tb_mqttPort.Size = new System.Drawing.Size(56, 28);
this.tb_mqttPort.Size = new System.Drawing.Size(56, 24);
this.tb_mqttPort.TabIndex = 29;
//
// label3
......@@ -164,7 +167,7 @@ namespace JmpServiceMgr
this.label3.ForeColor = System.Drawing.Color.Black;
this.label3.Location = new System.Drawing.Point(245, 277);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(66, 19);
this.label3.Size = new System.Drawing.Size(52, 15);
this.label3.TabIndex = 28;
this.label3.Text = "端口:";
//
......@@ -181,7 +184,7 @@ namespace JmpServiceMgr
this.tb_mqttIp.Location = new System.Drawing.Point(110, 275);
this.tb_mqttIp.Name = "tb_mqttIp";
this.tb_mqttIp.PreventEnterBeep = true;
this.tb_mqttIp.Size = new System.Drawing.Size(129, 28);
this.tb_mqttIp.Size = new System.Drawing.Size(129, 24);
this.tb_mqttIp.TabIndex = 27;
//
// label2
......@@ -191,7 +194,7 @@ namespace JmpServiceMgr
this.label2.ForeColor = System.Drawing.Color.Black;
this.label2.Location = new System.Drawing.Point(34, 277);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 19);
this.label2.Size = new System.Drawing.Size(70, 15);
this.label2.TabIndex = 26;
this.label2.Text = "MQTTIP:";
//
......@@ -202,7 +205,7 @@ namespace JmpServiceMgr
this.cbb_textUser.FormattingEnabled = true;
this.cbb_textUser.Location = new System.Drawing.Point(136, 242);
this.cbb_textUser.Name = "cbb_textUser";
this.cbb_textUser.Size = new System.Drawing.Size(222, 26);
this.cbb_textUser.Size = new System.Drawing.Size(222, 23);
this.cbb_textUser.TabIndex = 25;
//
// label1
......@@ -212,7 +215,7 @@ namespace JmpServiceMgr
this.label1.ForeColor = System.Drawing.Color.Black;
this.label1.Location = new System.Drawing.Point(18, 245);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(142, 19);
this.label1.Size = new System.Drawing.Size(112, 15);
this.label1.TabIndex = 23;
this.label1.Text = "演示模式用户:";
//
......@@ -229,7 +232,7 @@ namespace JmpServiceMgr
this.tb_shelf.Location = new System.Drawing.Point(135, 200);
this.tb_shelf.Name = "tb_shelf";
this.tb_shelf.PreventEnterBeep = true;
this.tb_shelf.Size = new System.Drawing.Size(223, 28);
this.tb_shelf.Size = new System.Drawing.Size(223, 24);
this.tb_shelf.TabIndex = 22;
//
// label13
......@@ -239,7 +242,7 @@ namespace JmpServiceMgr
this.label13.ForeColor = System.Drawing.Color.Black;
this.label13.Location = new System.Drawing.Point(47, 202);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(104, 19);
this.label13.Size = new System.Drawing.Size(82, 15);
this.label13.TabIndex = 21;
this.label13.Text = "货架地址:";
//
......@@ -256,7 +259,7 @@ namespace JmpServiceMgr
this.txt_upload.Location = new System.Drawing.Point(135, 158);
this.txt_upload.Name = "txt_upload";
this.txt_upload.PreventEnterBeep = true;
this.txt_upload.Size = new System.Drawing.Size(223, 28);
this.txt_upload.Size = new System.Drawing.Size(223, 24);
this.txt_upload.TabIndex = 20;
//
// label9
......@@ -266,7 +269,7 @@ namespace JmpServiceMgr
this.label9.ForeColor = System.Drawing.Color.Black;
this.label9.Location = new System.Drawing.Point(47, 160);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(104, 19);
this.label9.Size = new System.Drawing.Size(82, 15);
this.label9.TabIndex = 19;
this.label9.Text = "抓拍上传:";
//
......@@ -283,7 +286,7 @@ namespace JmpServiceMgr
this.txt_secretkey.Location = new System.Drawing.Point(136, 116);
this.txt_secretkey.Name = "txt_secretkey";
this.txt_secretkey.PreventEnterBeep = true;
this.txt_secretkey.Size = new System.Drawing.Size(223, 28);
this.txt_secretkey.Size = new System.Drawing.Size(223, 24);
this.txt_secretkey.TabIndex = 18;
//
// label12
......@@ -293,7 +296,7 @@ namespace JmpServiceMgr
this.label12.ForeColor = System.Drawing.Color.Black;
this.label12.Location = new System.Drawing.Point(59, 119);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(88, 19);
this.label12.Size = new System.Drawing.Size(70, 15);
this.label12.TabIndex = 17;
this.label12.Text = "Secret:";
//
......@@ -310,7 +313,7 @@ namespace JmpServiceMgr
this.txt_appkey.Location = new System.Drawing.Point(135, 74);
this.txt_appkey.Name = "txt_appkey";
this.txt_appkey.PreventEnterBeep = true;
this.txt_appkey.Size = new System.Drawing.Size(223, 28);
this.txt_appkey.Size = new System.Drawing.Size(223, 24);
this.txt_appkey.TabIndex = 16;
//
// label11
......@@ -320,7 +323,7 @@ namespace JmpServiceMgr
this.label11.ForeColor = System.Drawing.Color.Black;
this.label11.Location = new System.Drawing.Point(59, 83);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(88, 19);
this.label11.Size = new System.Drawing.Size(70, 15);
this.label11.TabIndex = 15;
this.label11.Text = "AppKey:";
//
......@@ -337,7 +340,7 @@ namespace JmpServiceMgr
this.txtDomain.Location = new System.Drawing.Point(135, 32);
this.txtDomain.Name = "txtDomain";
this.txtDomain.PreventEnterBeep = true;
this.txtDomain.Size = new System.Drawing.Size(223, 28);
this.txtDomain.Size = new System.Drawing.Size(223, 24);
this.txtDomain.TabIndex = 11;
//
// label10
......@@ -347,13 +350,16 @@ namespace JmpServiceMgr
this.label10.ForeColor = System.Drawing.Color.Black;
this.label10.Location = new System.Drawing.Point(47, 34);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(104, 19);
this.label10.Size = new System.Drawing.Size(82, 15);
this.label10.TabIndex = 10;
this.label10.Text = "网关地址:";
//
// groupBox5
//
this.groupBox5.BackColor = System.Drawing.Color.White;
this.groupBox5.Controls.Add(this.lb_shelfPrintType);
this.groupBox5.Controls.Add(this.lb_shelfPrintCom);
this.groupBox5.Controls.Add(this.cbb_shelfPrintType);
this.groupBox5.Controls.Add(this.chk_syncCard);
this.groupBox5.Controls.Add(this.cbb_shelfPrintCom);
this.groupBox5.Controls.Add(this.chk_pushShelfPrint);
......@@ -369,19 +375,35 @@ namespace JmpServiceMgr
this.groupBox5.ForeColor = System.Drawing.Color.Black;
this.groupBox5.Location = new System.Drawing.Point(405, 340);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(316, 346);
this.groupBox5.Size = new System.Drawing.Size(316, 374);
this.groupBox5.TabIndex = 9;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "其他设置";
//
// chk_syncCard
//
this.chk_syncCard.BackColor = System.Drawing.Color.White;
//
//
//
this.chk_syncCard.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
this.chk_syncCard.ForeColor = System.Drawing.Color.Black;
this.chk_syncCard.Location = new System.Drawing.Point(29, 265);
this.chk_syncCard.Name = "chk_syncCard";
this.chk_syncCard.Size = new System.Drawing.Size(156, 23);
this.chk_syncCard.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.chk_syncCard.TabIndex = 25;
this.chk_syncCard.Text = "启用门禁卡号同步";
//
// cbb_shelfPrintCom
//
this.cbb_shelfPrintCom.BackColor = System.Drawing.Color.White;
this.cbb_shelfPrintCom.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbb_shelfPrintCom.ForeColor = System.Drawing.Color.Black;
this.cbb_shelfPrintCom.FormattingEnabled = true;
this.cbb_shelfPrintCom.Location = new System.Drawing.Point(227, 317);
this.cbb_shelfPrintCom.Location = new System.Drawing.Point(243, 340);
this.cbb_shelfPrintCom.Name = "cbb_shelfPrintCom";
this.cbb_shelfPrintCom.Size = new System.Drawing.Size(56, 26);
this.cbb_shelfPrintCom.Size = new System.Drawing.Size(56, 23);
this.cbb_shelfPrintCom.TabIndex = 24;
//
// chk_pushShelfPrint
......@@ -477,7 +499,7 @@ namespace JmpServiceMgr
"23:00"});
this.cbb_autoUpdate.Location = new System.Drawing.Point(227, 182);
this.cbb_autoUpdate.Name = "cbb_autoUpdate";
this.cbb_autoUpdate.Size = new System.Drawing.Size(56, 26);
this.cbb_autoUpdate.Size = new System.Drawing.Size(56, 23);
this.cbb_autoUpdate.TabIndex = 19;
//
// cb_autoUpdate
......@@ -564,7 +586,7 @@ namespace JmpServiceMgr
//
this.labelX2.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
this.labelX2.ForeColor = System.Drawing.Color.Black;
this.labelX2.Location = new System.Drawing.Point(11, 718);
this.labelX2.Location = new System.Drawing.Point(7, 746);
this.labelX2.Name = "labelX2";
this.labelX2.Size = new System.Drawing.Size(445, 23);
this.labelX2.TabIndex = 10;
......@@ -609,9 +631,9 @@ namespace JmpServiceMgr
// superTabControlPanel2
//
this.superTabControlPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.superTabControlPanel2.Location = new System.Drawing.Point(0, 33);
this.superTabControlPanel2.Location = new System.Drawing.Point(0, 29);
this.superTabControlPanel2.Name = "superTabControlPanel2";
this.superTabControlPanel2.Size = new System.Drawing.Size(710, 299);
this.superTabControlPanel2.Size = new System.Drawing.Size(710, 303);
this.superTabControlPanel2.TabIndex = 0;
this.superTabControlPanel2.TabItem = this.superTabItem2;
//
......@@ -638,26 +660,44 @@ namespace JmpServiceMgr
this.superTabItem1.Name = "superTabItem1";
this.superTabItem1.Text = "superTabItem1";
//
// chk_syncCard
//
this.chk_syncCard.BackColor = System.Drawing.Color.White;
//
//
//
this.chk_syncCard.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
this.chk_syncCard.ForeColor = System.Drawing.Color.Black;
this.chk_syncCard.Location = new System.Drawing.Point(29, 265);
this.chk_syncCard.Name = "chk_syncCard";
this.chk_syncCard.Size = new System.Drawing.Size(156, 23);
this.chk_syncCard.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.chk_syncCard.TabIndex = 25;
this.chk_syncCard.Text = "启用门禁卡号同步";
// cbb_shelfPrintType
//
this.cbb_shelfPrintType.BackColor = System.Drawing.Color.White;
this.cbb_shelfPrintType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbb_shelfPrintType.ForeColor = System.Drawing.Color.Black;
this.cbb_shelfPrintType.FormattingEnabled = true;
this.cbb_shelfPrintType.Items.AddRange(new object[] {
"COM",
"MQTT"});
this.cbb_shelfPrintType.Location = new System.Drawing.Point(107, 340);
this.cbb_shelfPrintType.Name = "cbb_shelfPrintType";
this.cbb_shelfPrintType.Size = new System.Drawing.Size(56, 23);
this.cbb_shelfPrintType.TabIndex = 26;
this.cbb_shelfPrintType.SelectedIndexChanged += new System.EventHandler(this.cbb_shelfPrintType_SelectedIndexChanged);
//
// lb_shelfPrintCom
//
this.lb_shelfPrintCom.AutoSize = true;
this.lb_shelfPrintCom.Location = new System.Drawing.Point(198, 343);
this.lb_shelfPrintCom.Name = "lb_shelfPrintCom";
this.lb_shelfPrintCom.Size = new System.Drawing.Size(39, 15);
this.lb_shelfPrintCom.TabIndex = 27;
this.lb_shelfPrintCom.Text = "COM:";
//
// lb_shelfPrintType
//
this.lb_shelfPrintType.AutoSize = true;
this.lb_shelfPrintType.Location = new System.Drawing.Point(26, 343);
this.lb_shelfPrintType.Name = "lb_shelfPrintType";
this.lb_shelfPrintType.Size = new System.Drawing.Size(75, 15);
this.lb_shelfPrintType.TabIndex = 28;
this.lb_shelfPrintType.Text = "接入类型:";
//
// FrmConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(732, 753);
this.ClientSize = new System.Drawing.Size(734, 781);
this.Controls.Add(this.superTabControl1);
this.Controls.Add(this.labelX2);
this.Controls.Add(this.groupBox5);
......@@ -671,8 +711,8 @@ namespace JmpServiceMgr
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(4);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(750, 800);
this.MinimumSize = new System.Drawing.Size(750, 800);
this.MaximumSize = new System.Drawing.Size(750, 820);
this.MinimumSize = new System.Drawing.Size(750, 820);
this.Name = "FrmConfig";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统参数配置";
......@@ -680,6 +720,7 @@ namespace JmpServiceMgr
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.groupBox5.ResumeLayout(false);
this.groupBox5.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.superTabControl1)).EndInit();
this.superTabControl1.ResumeLayout(false);
this.ResumeLayout(false);
......@@ -726,5 +767,8 @@ namespace JmpServiceMgr
private DevComponents.DotNetBar.Controls.CheckBoxX chk_pushShelfPrint;
private System.Windows.Forms.ComboBox cbb_shelfPrintCom;
private DevComponents.DotNetBar.Controls.CheckBoxX chk_syncCard;
private System.Windows.Forms.Label lb_shelfPrintCom;
private System.Windows.Forms.ComboBox cbb_shelfPrintType;
private System.Windows.Forms.Label lb_shelfPrintType;
}
}
\ No newline at end of file
......@@ -175,29 +175,40 @@ 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;
cbb_shelfPrintCom.Items.Clear();
cbb_shelfPrintCom.Items.AddRange(SerialPort.GetPortNames());
if (cbb_shelfPrintCom.Items.Count > 0)
if (cbb_shelfPrintType.SelectedIndex == 0)
{
if (cbb_shelfPrintCom.Items.Contains(MyCache.SysConfig.PushShelfPrintCom))
{
cbb_shelfPrintCom.SelectedIndex =
cbb_shelfPrintCom.Items.IndexOf(MyCache.SysConfig.PushShelfPrintCom);
}
else
cbb_shelfPrintCom.Items.Clear();
cbb_shelfPrintCom.Items.AddRange(SerialPort.GetPortNames());
if (cbb_shelfPrintCom.Items.Count > 0)
{
cbb_shelfPrintCom.SelectedIndex = cbb_shelfPrintCom.Items.Count - 1;
if (cbb_shelfPrintCom.Items.Contains(MyCache.SysConfig.PushShelfPrintCom))
{
cbb_shelfPrintCom.SelectedIndex =
cbb_shelfPrintCom.Items.IndexOf(MyCache.SysConfig.PushShelfPrintCom);
}
else
{
cbb_shelfPrintCom.SelectedIndex = cbb_shelfPrintCom.Items.Count - 1;
}
}
}
else
{
lb_shelfPrintCom.Enabled = false;
cbb_shelfPrintCom.Enabled = false;
}
}
else
{
cbb_shelfPrintCom.Visible = false;
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,28 +377,49 @@ namespace JmpServiceMgr
{
if (box.Checked)
{
cbb_shelfPrintCom.Visible = true;
cbb_shelfPrintCom.Items.Clear();
cbb_shelfPrintCom.Items.AddRange(SerialPort.GetPortNames());
if (cbb_shelfPrintCom.Items.Count > 0)
{
if (cbb_shelfPrintCom.Items.Contains(MyCache.SysConfig.PushShelfPrintCom))
{
cbb_shelfPrintCom.SelectedIndex =
cbb_shelfPrintCom.Items.IndexOf(MyCache.SysConfig.PushShelfPrintCom);
}
else
{
cbb_shelfPrintCom.SelectedIndex = cbb_shelfPrintCom.Items.Count - 1;
}
}
lb_shelfPrintType.Enabled = true;
cbb_shelfPrintType.Enabled = true;
cbb_shelfPrintType_SelectedIndexChanged(null, null);
}
else
{
cbb_shelfPrintCom.Visible = false;
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)
{
if (cbb_shelfPrintCom.Items.Contains(MyCache.SysConfig.PushShelfPrintCom))
{
cbb_shelfPrintCom.SelectedIndex =
cbb_shelfPrintCom.Items.IndexOf(MyCache.SysConfig.PushShelfPrintCom);
}
else
{
cbb_shelfPrintCom.SelectedIndex = cbb_shelfPrintCom.Items.Count - 1;
}
}
}
else
{
lb_shelfPrintCom.Enabled = false;
cbb_shelfPrintCom.Enabled = false;
}
}
}
}
......@@ -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,9 +294,17 @@ namespace JmpServiceMgr
MqttHelper.InitialMQTT();
if (MyCache.SysConfig.IsPushShelfPrint)
{
//启动
SerialPortHelper = new SerialPortHelper(this, CTol);
SerialPortHelper.InitialSerialPort();
if (MyCache.SysConfig.PushShelfPrintType == 0)
{
//com
SerialPortHelper = new SerialPortHelper(this, CTol);
SerialPortHelper.InitialSerialPort();
}
else
{
//启动mqtt服务端推送出入库信息
MqttServer = new MQTTServer();
}
}
HikFaceHelperList = new List<HikFaceHelper>();
......
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();
}
}
}
......@@ -454,7 +454,7 @@ namespace JmpServiceMgr.Helper
}
//移除装备包
request.RFIDList.RemoveAll(x => bagEpcList.Contains(x.RFID));
if (bagEpcList.Count > 0)
{
//装备包获取件标信息
......@@ -566,7 +566,28 @@ namespace JmpServiceMgr.Helper
{
Task.Run(() =>
{
_form.SerialPortHelper.CreateOrderPushData(pushResultList);
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
})));
}
}
});
}
}
......
......@@ -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>
<EmbeddedResource Include="app.config" />
<None Include="app.config" />
<EmbeddedResource Include="RfidConfig.resx">
<DependentUpon>RfidConfig.cs</DependentUpon>
</EmbeddedResource>
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论