Ver código fonte

API数据获取

master
pry 2 anos atrás
pai
commit
4c6f00a254
12 arquivos alterados com 637 adições e 58 exclusões
  1. +111
    -23
      HBLConsole.Business/APIHelper.cs
  2. +52
    -2
      HBLConsole.Business/MORKS.cs
  3. +1
    -1
      HBLConsole.Communication/HBLConsole.Communication.csproj
  4. +373
    -4
      HBLConsole.Communication/ModbusTcpHelper.cs
  5. +34
    -18
      HBLConsole.GVL/InternetInfo.cs
  6. +44
    -0
      HBLConsole.GVL/MORKS.cs
  7. +0
    -1
      HBLConsole.MainConsole/HeartbeatReport.cs
  8. +14
    -3
      HBLConsole.MainConsole/Main.cs
  9. +0
    -1
      HBLConsole.Service/SystemHelper.cs
  10. +2
    -2
      HBLConsole/App.config
  11. +1
    -3
      HBLConsole/App.xaml.cs
  12. +5
    -0
      HBLConsole/HBLConsole.csproj

+ 111
- 23
HBLConsole.Business/APIHelper.cs Ver arquivo

@@ -8,6 +8,10 @@ using System.Text;
using System.Threading.Tasks;
using BPA.Utility;
using HBLConsole.GVL;
using BPA.Message;
using System.Web;
using Newtonsoft.Json;
using HBLConsole.Service;

namespace HBLConsole.Business
{
@@ -18,36 +22,120 @@ namespace HBLConsole.Business
public static APIHelper GetInstance => _Instance ?? (_Instance = new APIHelper());
private APIHelper() { }

public void OrderStatusChange(string suborderId, int orderStatus)
/// <summary>
/// 获取物料信息
/// </summary>
/// <param name="ClientId"></param>
/// <returns></returns>
public OrderMaterialDelivery GetBatchingInfo(int ClientId)
{
var m = $"[/api/RobotOrder]_[{DateTime.Now.Ticks}]".AESEncrypt();
WebApiHelper.GetInstance().HttpPost(InternetInfo.GetInstance.OrderStatusChange, "");
string result = string.Empty;
try
{
var jsondata = new { ClientId };
string header = $"[{InternetInfo.GetInstance.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt();
string url = $"{InternetInfo.GetInstance.ApiAddress}{InternetInfo.GetInstance.StockServer}/GetItemInfo";
result = HttpRequest(url, header, jsondata, RequestType.POST);
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
}
return JsonConvert.DeserializeObject<OrderMaterialDelivery>(result);
}

public void GetBatchingInfo()
/// <summary>
/// 更改订单状态
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public OrderStatusChangeRsp OrderStatusChange(OrderStatusChange orderStatusChange)
{
string result = string.Empty;
try
{
string header = $"[{InternetInfo.GetInstance.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]".AESEncrypt();
string url = $"{InternetInfo.GetInstance.ApiAddress}{InternetInfo.GetInstance.OrderServer}/order/robotstatuschange";
result = HttpRequest(url, header, orderStatusChange, RequestType.POST);
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
}
return JsonConvert.DeserializeObject<OrderStatusChangeRsp>(result);
}


public static string PostData(string url, string data, string head)
{
byte[] b = Encoding.UTF8.GetBytes(data);//把字符串转换为二进制
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Proxy = null;
request.ContentType = "application/json";
request.Method = "POST"; //设置请求方法
request.ContentLength = b.Length; //设置长度
request.Headers["Authorize"] = head;
Stream postStream = request.GetRequestStream(); //requst流
postStream.Write(b, 0, b.Length); //写入POST数据,二进制类型的
postStream.Close(); //关闭
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //获取response
Stream stream = response.GetResponseStream(); // 得到response响应流
StreamReader sr = new StreamReader(stream);
string str = sr.ReadToEnd(); //读取流

sr.Close();
stream.Close();
return str;
}

//string serviceAddress = "http://1.14.74.54:7001/api/Advertisement/htmlurl?storeId=3b007e32-f1cc-4021-b4e0-f4764fa90f12";
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
//request.Method = "GET";
//request.ContentType = "text/html;charset=UTF-8";
//HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Stream myResponseStream = response.GetResponseStream();
//StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
//string retString = myStreamReader.ReadToEnd();
//myStreamReader.Close();
//myResponseStream.Close();
////Response.Write(retString);
//JObject obj = JObject.Parse(retString);
//string Data1 = obj["data"].ToString();
//string Data = string.Empty;
//if (Data1.Length > 0)
// Data = obj["data"]["data"].ToString();//获取连接
//GVL_VAR.GetInstance.SorbetesAddress = Data;
//if (SorbetesAddressNoti != null) SorbetesAddressNoti(Data);
//MessageLogOut.GetInstance.Show($"广告连接:={Data}");
public static string GetData(string url, string head)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Accept = "text/html, application/xhtml+xml, */*";
request.ContentType = "application/json";
request.Headers["Authorize"] = head;
byte[] buffer = Encoding.UTF8.GetBytes(head);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return myStreamReader.ReadToEnd();
}
}

public string HttpRequest(string url, string head, object data, RequestType requestType)
{
if (requestType == RequestType.POST)
{
return PostData(url, JsonConvert.SerializeObject(data), head);
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append("?");
foreach (System.Reflection.PropertyInfo p in data.GetType().GetProperties())
{
if (sb.ToString().Last() != '?')
{
sb.Append("&");
}
sb.Append(p.Name);
sb.Append("=");
sb.Append(p.GetValue(data));
}
return GetData(url + sb.ToString(), head);
}
}

}

public enum RequestType
{
POST,
PUT,
DELETE,
GET
}
}

+ 52
- 2
HBLConsole.Business/MORKS.cs Ver arquivo

@@ -1,19 +1,69 @@
using System;
using HBLConsole.Communication;
using HBLConsole.Model;
using HBLConsole.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HBLConsole.GVL;
using BPA.Message;

namespace HBLConsole.Business
{
public class MORKS
{

private volatile static MORKS _Instance;
public static MORKS GetInstance => _Instance ?? (_Instance = new MORKS());
private MORKS() { }



/// <summary>
/// 写入配方数据到 PLC
/// </summary>
private void WriteRecipeBoms()
{
List<ushort> recipeBoms = new List<ushort>();
foreach (var item in Json<BatchingInfoPar>.GetInstance.Base.recipeBoms.RecipeIds)
{
foreach (var rec in item.Recipes)
{
recipeBoms.Add((ushort)rec);
}
}
if (ModbusTcpHelper.GetInstance.Write(1100, WriteType.HoldingRegisters, recipeBoms.ToArray()))
{
MessageLog.GetInstance.Show("成功写入配方数据");
}
}

public void Init()
{
//Modbus TCP连接成功
ActionManagerment.GetInstance.Register(new Action(() =>
{
WriteRecipeBoms();
}), "ConnectOk");

//获取物料信息
Json<BatchingInfoPar>.GetInstance.Base.orderMaterialDelivery = APIHelper.GetInstance.GetBatchingInfo(InternetInfo.GetInstance.ClientId);
Json<BatchingInfoPar>.GetInstance.Base.orderMaterialDelivery.BatchingInfo.Sort((a, b) => a.BatchingLoc.CompareTo(b.BatchingLoc));
MessageLog.GetInstance.Show("【物料信息】");
Json<BatchingInfoPar>.GetInstance.Base.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
{
MessageLog.GetInstance.Show($"{x.BatchingLoc}号位置:{x.BatchingCount}");
});


//Modbus Tcp 连接
ModbusTcpHelper.GetInstance.ModbusTcpConnect("127.0.0.1");
}






}
}

+ 1
- 1
HBLConsole.Communication/HBLConsole.Communication.csproj Ver arquivo

@@ -6,8 +6,8 @@

<ItemGroup>
<PackageReference Include="M2Mqtt" Version="4.3.0" />
<PackageReference Include="ModbusTcp" Version="1.0.4" />
<PackageReference Include="MQTTnet" Version="3.1.2" />
<PackageReference Include="NModbus" Version="3.0.72" />
</ItemGroup>

<ItemGroup>


+ 373
- 4
HBLConsole.Communication/ModbusTcpHelper.cs Ver arquivo

@@ -1,9 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using ModbusTcp;
using NModbus;
using HBLConsole.Service;
using System.Threading;
using HBLConsole.Model;


namespace HBLConsole.Communication
{
@@ -14,13 +19,377 @@ namespace HBLConsole.Communication
public static ModbusTcpHelper GetInstance => _Instance ?? (_Instance = new ModbusTcpHelper());
private ModbusTcpHelper() { }

ModbusClient modbusClient;
private ModbusFactory modbusFactory;
private IModbusMaster master;
private TcpClient tcpClient;
private string IPAdress;
private int Port;

//public Action ConnectOk { get; set; }

/// <summary>
/// 判断是否连接成功
/// </summary>
public bool Connected => tcpClient == null ? false : tcpClient.Connected;

/// <summary>
/// ModbusTcp 连接设备
/// </summary>
/// <param name="ip">ip 地址</param>
/// <param name="port">端口号,默认502</param>
public void ModbusTcpConnect(string ip, int port = 502)
{
IPAdress = ip;
Port = port;
modbusFactory = new ModbusFactory();
Connect();
master.Transport.ReadTimeout = 2000;//读取超时时间
master.Transport.WriteTimeout = 2000;//写入超时时间
master.Transport.Retries = 10;//重试次数

ActionManagerment.GetInstance.Send("ConnectOk");
}

private void Connect()
{
while (!Connected)
{
try
{
tcpClient = new TcpClient(IPAdress, Port);
master = modbusFactory.CreateMaster(tcpClient);
}
catch (Exception ex)
{
MessageLog.GetInstance.Show($"ModbusTcp 连接失败,IP = {IPAdress},Port = {Port}");
MessageLog.GetInstance.Show(ex.ToString());
Thread.Sleep(30000);
}
}
MessageLog.GetInstance.Show("ModbusTcp 连接成功!");
}

public object Read(ushort startAddress, ReadType readType, ushort num = 1, byte slaveAddress = 1)
{
object result = new object();
if (tcpClient == null) return result;
if (num <= 0) return result;
try
{
switch (readType)
{
case ReadType.Coils:
result = master.ReadCoils(slaveAddress, startAddress, num);
break;
case ReadType.Inputs:
result = master.ReadInputs(slaveAddress, startAddress, num);
break;
case ReadType.HoldingRegisters:
result = master.ReadHoldingRegisters(slaveAddress, startAddress, num);
break;
case ReadType.InputRegisters:
result = master.ReadInputRegisters(slaveAddress, startAddress, num);
break;
default:
break;
}
if (result == null) return new object();
if (result is bool[] bools)
{
if (bools.Length == 1)
return bools[0];
else
return bools;
}
if (result is ushort[] ushorts)
{
if (ushorts.Length == 1)
return ushorts[0];
else
return ushorts;
}
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
tcpClient = null;
Connect();
}
return result;
}

public bool Write(ushort startAddress, WriteType writeType, object InputValue, byte slaveAddress = 1)
{
bool result = false;
if (tcpClient == null) return result;
if (!(InputValue is bool || InputValue is bool[] || InputValue is ushort || InputValue is ushort[])) return result;
try
{
switch (writeType)
{
case WriteType.Coils:
if (InputValue is bool boolValue)
master.WriteSingleCoil(slaveAddress, startAddress, boolValue);

if (InputValue is bool[] boolsValue)
master.WriteMultipleCoils(slaveAddress, startAddress, boolsValue);
break;
case WriteType.HoldingRegisters:
if (InputValue is ushort ushortValue)
master.WriteSingleRegister(slaveAddress, startAddress, ushortValue);

if (InputValue is ushort[] ushortsValue)
{
if (ushortsValue.Length > 123)
{
List<ushort[]> ushortLists = new List<ushort[]>();
for (int i = 0; i < ushortsValue.Length / 123; i++)
{
ushortLists.Add(ushortsValue.Skip(0).Take(123).ToArray());
}
int y = ushortsValue.Length % 123;

public void Connect(string ip, int port)
if (y > 0)
{
ushortLists.Add(ushortsValue.Skip(ushortsValue.Length - y).Take(y).ToArray());
}
foreach (var item in ushortLists)
{
master.WriteMultipleRegisters(slaveAddress, startAddress, item);
startAddress += (ushort)item.Length;
}
}
else
{
master.WriteMultipleRegisters(slaveAddress, startAddress, ushortsValue);
}

}

break;
default:
break;
}
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
tcpClient = null;
Connect();
}
return true;
}


#region 批量数据读取
/// <summary>
/// 读取多个线圈
/// </summary>
/// <param name="startAddress"></param>
/// <param name="num"></param>
/// <param name="slaveAddress"></param>
/// <returns></returns>
public bool[] ReadCoils(ushort startAddress, ushort num, byte slaveAddress = 1)
{
modbusClient = new ModbusClient(ip, port);
return master.ReadCoils(slaveAddress, startAddress, num);
}

/// <summary>
/// 读取多个输入线圈
/// </summary>
/// <param name="startAddress"></param>
/// <param name="num"></param>
/// <param name="slaveAddress"></param>
/// <returns></returns>
public bool[] ReadInputs(ushort startAddress, ushort num, byte slaveAddress = 1)
{
return master.ReadInputs(slaveAddress, startAddress, num);
}

/// <summary>
/// 读取多个保持寄存器
/// </summary>
/// <param name="startAddress"></param>
/// <param name="num"></param>
/// <param name="slaveAddress"></param>
/// <returns></returns>
public ushort[] ReadHoldingRegisters(ushort startAddress, ushort num, byte slaveAddress = 1)
{
return master.ReadHoldingRegisters(slaveAddress, startAddress, num);
}

/// <summary>
/// 读取多个输入寄存器
/// </summary>
/// <param name="startAddress"></param>
/// <param name="num"></param>
/// <param name="slaveAddress"></param>
/// <returns></returns>
public ushort[] ReadInputRegisters(ushort startAddress, ushort num, byte slaveAddress = 1)
{
return master.ReadInputRegisters(slaveAddress, startAddress, num);
}
#endregion

#region 批量数据写入
/// <summary>
/// 写入多个线圈
/// </summary>
/// <param name="startAddress"></param>
/// <param name="value"></param>
/// <param name="slaveAddress"></param>
public void WriteMultipleCoils(ushort startAddress, bool[] value, byte slaveAddress = 1)
{
master.WriteMultipleCoils(slaveAddress, startAddress, value);
}

/// <summary>
/// 写入多个寄存器
/// </summary>
/// <param name="startAddress"></param>
/// <param name="value"></param>
/// <param name="slaveAddress"></param>
public void WriteMultipleRegisters(ushort startAddress, ushort[] value, byte slaveAddress = 1)
{
master.WriteMultipleRegisters(slaveAddress, startAddress, value);
}
#endregion

#region 单个数据读取
/// <summary>
/// 读取单个线圈
/// </summary>
/// <param name="startAddress"></param>
/// <param name="slaveAddress"></param>
/// <returns></returns>
public bool ReadCoils(ushort startAddress, byte slaveAddress = 1)
{
var result = master.ReadCoils(slaveAddress, startAddress, 1);
if (result == null) return false;
if (result.Length == 1) return result[0];
return false;
//return master.ReadCoils(slaveAddress, startAddress, 1)[0];
}

/// <summary>
/// 读取单个输入线圈
/// </summary>
/// <param name="startAddress"></param>
/// <param name="slaveAddress"></param>
/// <returns></returns>
public bool ReadInputs(ushort startAddress, byte slaveAddress = 1)
{
var result = master.ReadInputs(slaveAddress, startAddress, 1);
if (result == null) return false;
if (result.Length == 1) return result[0];
return false;
//return master.ReadInputs(slaveAddress, startAddress, 1)[0];
}

/// <summary>
/// 读取单个保持寄存器
/// </summary>
/// <param name="startAddress"></param>
/// <param name="slaveAddress"></param>
/// <returns></returns>
public ushort ReadHoldingRegisters(ushort startAddress, byte slaveAddress = 1)
{
if (tcpClient == null) return 0;
ushort[] result = null;
try
{
result = master.ReadHoldingRegisters(slaveAddress, startAddress, 1);
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
tcpClient = null;
Connect();
}

if (result == null) return 0;
if (result.Length == 1) return result[0];
return 0;
//return master.ReadHoldingRegisters(slaveAddress, startAddress, 1)[0];
}

/// <summary>
/// 读取单个输入寄存器
/// </summary>
/// <param name="startAddress"></param>
/// <param name="slaveAddress"></param>
/// <returns></returns>
public ushort ReadInputRegisters(ushort startAddress, byte slaveAddress = 1)
{
var result = master.ReadInputRegisters(slaveAddress, startAddress, 1);
if (result == null) return 0;
if (result.Length == 1) return result[0];
return 0;
//return master.ReadInputRegisters(slaveAddress, startAddress, 1)[0];
}
#endregion

#region 单个数据写入
/// <summary>
/// 写入单个线圈
/// </summary>
/// <param name="startAddress"></param>
/// <param name="value"></param>
/// <param name="slaveAddress"></param>
public void WriteSingleCoil(ushort startAddress, bool value, byte slaveAddress = 1)
{
master.WriteSingleCoil(slaveAddress, startAddress, value);
}

/// <summary>
/// 写入单个寄存器
/// </summary>
/// <param name="startAddress"></param>
/// <param name="value"></param>
/// <param name="slaveAddress"></param>
public void WriteSingleRegister(ushort startAddress, ushort value, byte slaveAddress = 1)
{
master.WriteSingleRegister(slaveAddress, startAddress, value);
}
#endregion





}


public enum ReadType
{
/// <summary>
/// 读线圈
/// </summary>
Coils,
/// <summary>
/// 读输入线圈
/// </summary>
Inputs,
/// <summary>
/// 读保持寄存器
/// </summary>
HoldingRegisters,
/// <summary>
/// 读输入寄存器
/// </summary>
InputRegisters,
}

public enum WriteType
{
/// <summary>
/// 写线圈
/// </summary>
Coils,
/// <summary>
/// 写保持寄存器
/// </summary>
HoldingRegisters,
}

}

+ 34
- 18
HBLConsole.GVL/InternetInfo.cs Ver arquivo

@@ -33,28 +33,30 @@ namespace HBLConsole.GVL

ConsulAddress = System.Configuration.ConfigurationManager.AppSettings["ConsulAddress"];
ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]);
try
{
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/basic.json", false, 5_000);
IConfiguration config = configurationBuilder.Build();
MqttUserName = config["MQTT:TcpAccount"];
MqttPassword = config["MQTT:TcpPwd"];
MqttAddress = config["MQTT:MqttAddress"];
MqttPort = int.Parse(config["MQTT:MqttPort"]);
OrderStatusChange = config["API:robotstatuschange"];
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());

while (StockServer == null)
{
try
{
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/basic.json", false, 5_000);
IConfiguration config = configurationBuilder.Build();
MqttUserName = config["MQTT:TcpAccount"];
MqttPassword = config["MQTT:TcpPwd"];
MqttAddress = config["MQTT:IP"];
MqttPort = int.Parse(config["MQTT:Client"]);
ApiAddress = config["GateWay:BaseURL"];
OrderServer = config["GateWay:Order"];
StockServer = config["GateWay:Stock"];
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
Thread.Sleep(30000);
}
}

}

/// <summary>
/// 订单状态更改接口地址
/// </summary>
public string OrderStatusChange { get; set; }


/// <summary>
/// Consul 地址
@@ -100,6 +102,20 @@ namespace HBLConsole.GVL

#region API地址

/// <summary>
/// Api 网关地址
/// </summary>
public string ApiAddress { get; set; }

/// <summary>
/// 订单服务
/// </summary>
public string OrderServer { get; set; }

/// <summary>
/// 库存服务
/// </summary>
public string StockServer { get; set; }
#endregion

}


+ 44
- 0
HBLConsole.GVL/MORKS.cs Ver arquivo

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.GVL
{
/// <summary>
/// MORKS 设备数据
/// </summary>
public class MORKS
{
/// <summary>
/// 初始化完成
/// </summary>
public bool InitComplete { get; set; }

/// <summary>
/// 机器人取面
/// </summary>
public bool RobotTakeNoodle { get; set; }

/// <summary>
/// 机器人出餐
/// </summary>
public bool RobotOutMeal { get; set; }

/// <summary>
/// 移动转台
/// </summary>
public bool MoveTurntable { get; set; }

/// <summary>
/// 煮面炉状态
/// </summary>
public bool[] NoodleCookerStatus { get; set; } = new bool[6] { false, false, false, false, false, false };

/// <summary>
/// 取完空闲
/// </summary>
public bool TakeBowlIdle { get; set; }
}
}

+ 0
- 1
HBLConsole.MainConsole/HeartbeatReport.cs Ver arquivo

@@ -14,7 +14,6 @@ using HBLConsole.GVL;
using BPA.Message;
using HBLConsole.Communication;
using BPA.Message.Enum;
using BPA.Models.Robot;
//using Communication.MQTT;
//using BPA.Message.Kafka;
//using Model.Enums;


+ 14
- 3
HBLConsole.MainConsole/Main.cs Ver arquivo

@@ -24,11 +24,13 @@ namespace HBLConsole.MainConsole
public void DataInit()
{
Json<MorkOrderPushPar>.GetInstance.Read();
Json<BatchingInfoPar>.GetInstance.Read();
}

public void DataSave()
{
Json<MorkOrderPushPar>.GetInstance.Save();
Json<BatchingInfoPar>.GetInstance.Save();
}

public void BusinessInit()
@@ -38,25 +40,34 @@ namespace HBLConsole.MainConsole
Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.GetInstance.DeviceType, InternetInfo.GetInstance.ClientId));
ThreadManagerment.GetInstance.Start(new Action(() =>
{
InternetInfo.GetInstance.Init();
InternetInfo.GetInstance.Init();//从 consul 获取配置数据

MORKS.GetInstance.Init();//设备初始化

//MQTT 连接成功
MqttHelper.GetInstance.ConnectOk = new Action(() =>
{
MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());
HeartbeatReport.GetInstance.Init();
MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅
HeartbeatReport.GetInstance.Init();//心跳上报
//接收MQTT消息
MqttHelper.GetInstance.MqttReceive = new Action<MQTTnet.MqttApplicationMessageReceivedEventArgs>((receivce) =>
{
ServerData.GetInstance.ReceiveData(Encoding.UTF8.GetString(receivce.ApplicationMessage.Payload));
});
});

//MQTT 重连成功
MqttHelper.GetInstance.Reconnection = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray()); });

//MQTT 连接
MqttHelper.GetInstance.MqttInitAsync(InternetInfo.GetInstance.MqttUserName,
InternetInfo.GetInstance.MqttPassword,
InternetInfo.GetInstance.MqttAddress,
InternetInfo.GetInstance.MqttPort,
DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));



}), "业务逻辑初始化");
}



+ 0
- 1
HBLConsole.Service/SystemHelper.cs Ver arquivo

@@ -6,7 +6,6 @@ using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Windows.Forms;

namespace HBLConsole.Server
{


+ 2
- 2
HBLConsole/App.config Ver arquivo

@@ -4,14 +4,14 @@
<!--通用配置-->

<!--测试服务 Consul 地址-->
<add key="ConsulAddress" value="http://114.117.161.250:8500" />
<add key="ConsulAddress" value="http://114.117.161.250:9011" />

<!--正式服务 Consul 地址-->
<!--<add key="ConsulAddress" value="http://162.14.105.138:9005" />-->

<!--客户端ID-->
<!--MorkD = 2,MorkS 且时且多 = 8,MorkS 珠海 = 9,冰淇淋 = 4,咖啡机 = 13-->
<add key="ClientId" value="9"/>
<add key="ClientId" value="8"/>


</appSettings>

+ 1
- 3
HBLConsole/App.xaml.cs Ver arquivo

@@ -25,11 +25,9 @@ namespace HBLConsole
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
//listDialogView = new ListDialogView();
//listDialogView.ShowDialog();
SystemHelper.GetInstance.AutoStart(false);
SystemHelper.GetInstance.CreateDesktopShortcut();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
//InitService.GetInstance.Register();
MainConsole.Main.GetInstance.DataInit();
mainView.Show();
if (Json<MorkOrderPushPar>.GetInstance.Base.morkOrderPushes.Count > 0)


+ 5
- 0
HBLConsole/HBLConsole.csproj Ver arquivo

@@ -5,6 +5,7 @@
<TargetFramework>net5.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\Images\hbl.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
@@ -99,6 +100,10 @@
</COMReference>
</ItemGroup>

<ItemGroup>
<Content Include="Resources\Images\hbl.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.14" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />


Carregando…
Cancelar
Salvar