feat - MES交互完善,CFX通讯待命,修改烤箱数据链接BUG,添加更多日志显示配置

master
SoulStar 3 months ago
parent 7f67a8c232
commit 8de7cbb4d9

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -19,6 +20,7 @@ namespace Sln.Iot.Business
private RFID06Business _rfid06;
private ErrorAnalyseBusiness _errorAnalyse;
private RecipeBusiness _recipeBusiness;
private MesReportBusiness _mesReportBusiness;
public BusinessStart()
{
_rfid01 = new RFID01Business();
@ -29,7 +31,7 @@ namespace Sln.Iot.Business
_rfid06 = new RFID06Business();
_errorAnalyse = new ErrorAnalyseBusiness();
_recipeBusiness = new RecipeBusiness();
_mesReportBusiness = new MesReportBusiness();
}
}
}

@ -1,21 +1,22 @@
using System;
using Amqp;
using CFX;
using CFX.ResourcePerformance;
using CFX.Structures;
using HslCommunication;
using Sln.Iot.Business.Entity;
using Sln.Iot.CFX.CFXConnect;
using Sln.Iot.CFX.Event;
using Sln.Iot.Config;
using Sln.Iot.PLC;
using Sln.Iot.Repository.dao;
using Sln.Iot.Repository.service;
using Sln.Iot.Serilog;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sln.Iot.PLC;
using HslCommunication;
using System.Collections;
using Sln.Iot.Business.Entity;
using Sln.Iot.Repository.service;
using Sln.Iot.Repository.dao;
using Sln.Iot.CFX.CFXConnect;
using CFX.ResourcePerformance;
using Sln.Iot.CFX.Event;
using CFX;
using CFX.Structures;
using Sln.Iot.Serilog;
using Amqp;
using TouchSocket.Core;
namespace Sln.Iot.Business
@ -26,6 +27,7 @@ namespace Sln.Iot.Business
private readonly PLCConnect _plc = PLCConnect.Instance;
private readonly SerilogHelper _log = SerilogHelper.Instance;
private readonly AppConfig _appConfig = AppConfigSetting.Load();
private readonly ErrorService errorService = ErrorService.Instance;
private readonly TrayBindingService trayBindingService = TrayBindingService.Instance;
@ -39,7 +41,7 @@ namespace Sln.Iot.Business
public ErrorAnalyseBusiness()
{
_timer = new Timer(TimerCallback, null, 0, 2000);
_timer = new Timer(TimerCallback, null, 0, 3000);
}
/// <summary>
@ -120,7 +122,8 @@ namespace Sln.Iot.Business
Guid logGuid = Guid.NewGuid();
errorService.InsertVacuum1Error(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
connect1.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage + "-Vacuum1", transID)));
_log.Info($"真空箱1报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
if (_appConfig.IsAlarmLog)
_log.Info($"真空箱1报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
}
}
else
@ -132,7 +135,8 @@ namespace Sln.Iot.Business
string delGuid = errorService.DeleteVacuum1Error(errorMessage.ENAlarmMessage);
Guid.TryParse(delGuid, out Guid guidRes);
connect1.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
_log.Info($"真空箱1报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
if (_appConfig.IsAlarmLog)
_log.Info($"真空箱1报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
}
}
}
@ -158,7 +162,8 @@ namespace Sln.Iot.Business
Guid logGuid = Guid.NewGuid();
errorService.InsertVacuum2Error(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
connect1.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage + "-Vacuum2", transID)));
_log.Info($"真空箱2报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
if (_appConfig.IsAlarmLog)
_log.Info($"真空箱2报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
}
}
else
@ -170,7 +175,8 @@ namespace Sln.Iot.Business
string delGuid = errorService.DeleteVacuum2Error(errorMessage.ENAlarmMessage);
Guid.TryParse(delGuid, out Guid guidRes);
connect1.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
_log.Info($"真空箱2报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
if (_appConfig.IsAlarmLog)
_log.Info($"真空箱2报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
}
}
}
@ -196,7 +202,8 @@ namespace Sln.Iot.Business
Guid logGuid = Guid.NewGuid();
errorService.InsertLiftError(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
connect2.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage, transID)));
_log.Info($"提升机报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
if (_appConfig.IsAlarmLog)
_log.Info($"提升机报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
}
}
else
@ -208,7 +215,8 @@ namespace Sln.Iot.Business
string delGuid = errorService.DeleteliftError(errorMessage.ENAlarmMessage);
Guid.TryParse(delGuid, out Guid guidRes);
connect2.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
_log.Info($"提升机报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
if (_appConfig.IsAlarmLog)
_log.Info($"提升机报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
}
}
}
@ -234,7 +242,8 @@ namespace Sln.Iot.Business
Guid logGuid = Guid.NewGuid();
errorService.InsertOvenError(logGuid.ToString(), errorMessage.ENAlarmMessage, errorMessage.CNAlarmMessage, errorMessage.ErrorCode);
connect3.PublishEvent(new CFXEnvelope(faultOccurredEvent.Handle(errorMessage.ErrorCode, LevelTrans(errorMessage.AlarmDegarde), logGuid, errorMessage.ENAlarmMessage, transID)));
_log.Info($"烤箱报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
if (_appConfig.IsAlarmLog)
_log.Info($"烤箱报警发生 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
}
}
else
@ -246,7 +255,8 @@ namespace Sln.Iot.Business
string delGuid = errorService.DeleteOvenError(errorMessage.ENAlarmMessage);
Guid.TryParse(delGuid, out Guid guidRes);
connect3.PublishEvent(new CFXEnvelope(faultClearedEvent.Handle(guidRes)));
_log.Info($"烤箱报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
if (_appConfig.IsAlarmLog)
_log.Info($"烤箱报警消除 内容:{errorMessage.CNAlarmMessage} 级别:{errorMessage.AlarmDegarde.GetDescription()}");
}
}
}

@ -1,4 +1,12 @@
using Microsoft.AspNetCore.Http;
using CFX;
using CFX.Structures;
using Microsoft.AspNetCore.Http;
using Sln.Iot.Business.Entity;
using Sln.Iot.CFX.CFXConnect;
using Sln.Iot.CFX.Event;
using Sln.Iot.Common;
using Sln.Iot.Config;
using Sln.Iot.Model.Entity;
using Sln.Iot.PLC;
using Sln.Iot.Serilog;
using Sln.Iot.Socket;
@ -16,58 +24,123 @@ namespace Sln.Iot.Business
private Timer _timer;
private readonly SerilogHelper _log = SerilogHelper.Instance;
private readonly DeltaHttpClient _deltaHttpClient = DeltaHttpClient.Instance;
private readonly AppConfig _appConfig = AppConfigSetting.Load();
private readonly PLCConnect _plc = PLCConnect.Instance;
public string InterfaceID;
public string Status = "0";
public string StatusCode = "0";
public int PassQuantity = 0;
public int FailQuantity = 0;
public string ErrorCount = "0";
public string ErrorTime = "0";
public double CycleTime = 0;
public double RunningTime = 0;
public double WaitingTime = 0;
public int InputQuantity = 0;
public string Barcode = "0";
public int Cya = 0;
CFXConnect1 _cfxHelper = CFXConnect1.Instance;
CFXConnect2 _cfxHelper2 = CFXConnect2.Instance;
CFXConnect3 _cfxHelper3 = CFXConnect3.Instance;
CFXConnect4 _cfxHelper4 = CFXConnect4.Instance;
StationParametersModifiedEvent stationParametersModifiedEvent = new StationParametersModifiedEvent();
public MesReportBusiness()
{
_deltaHttpClient.Init();
_timer = new Timer(TimerCallback, null, 0, 1000*15);
_timer = new Timer(TimerCallback, null, 0, 1000 * 15);
}
public void TimerCallback(object? state)
{
_deltaHttpClient.PostRequestSend(tranter());
ErrorGet(1);
_deltaHttpClient.PostRequestSend(tranter(GlobalVar.Connect1Entity));
ErrorGet(2);
_deltaHttpClient.PostRequestSend(tranter(GlobalVar.Connect2Entity));
ErrorGet(3);
_deltaHttpClient.PostRequestSend(tranter(GlobalVar.Connect3Entity));
ErrorGet(4);
_deltaHttpClient.PostRequestSend(tranter(GlobalVar.Connect4Entity));
_cfxHelper.PublishEvent(new CFXEnvelope(stationParametersModifiedEvent.Handle(ParameterSet(GlobalVar.Connect1Entity.InterfaceID,
"制程设备",
GlobalVar.Connect1Entity.Status,
GlobalVar.Connect1Entity.Status,
GlobalVar.Connect1Entity.StatusCode,
GlobalVar.Connect1Entity.PassQuantity.ToString(),
GlobalVar.Connect1Entity.FailQuantity.ToString(),
GlobalVar.Connect1Entity.CycleTime.ToString(),
GlobalVar.Connect1Entity.RunningTime.ToString(),
GlobalVar.Connect1Entity.WaitingTime.ToString(),
"1",
GlobalVar.Connect1Entity.InputQuantity.ToString(),
GlobalVar.Connect1Entity.ErrorCount.ToString(),
GlobalVar.Connect1Entity.ErrorTime.ToString()
))));
_cfxHelper2.PublishEvent(new CFXEnvelope(stationParametersModifiedEvent.Handle(ParameterSet(GlobalVar.Connect2Entity.InterfaceID,
"制程设备",
GlobalVar.Connect2Entity.Status,
GlobalVar.Connect2Entity.Status,
GlobalVar.Connect2Entity.StatusCode,
GlobalVar.Connect2Entity.PassQuantity.ToString(),
GlobalVar.Connect2Entity.FailQuantity.ToString(),
GlobalVar.Connect2Entity.CycleTime.ToString(),
GlobalVar.Connect2Entity.RunningTime.ToString(),
GlobalVar.Connect2Entity.WaitingTime.ToString(),
"1",
GlobalVar.Connect2Entity.InputQuantity.ToString(),
GlobalVar.Connect2Entity.ErrorCount.ToString(),
GlobalVar.Connect2Entity.ErrorTime.ToString()
))));
_cfxHelper3.PublishEvent(new CFXEnvelope(stationParametersModifiedEvent.Handle(ParameterSet(GlobalVar.Connect3Entity.InterfaceID,
"制程设备",
GlobalVar.Connect3Entity.Status,
GlobalVar.Connect3Entity.Status,
GlobalVar.Connect3Entity.StatusCode,
GlobalVar.Connect3Entity.PassQuantity.ToString(),
GlobalVar.Connect3Entity.FailQuantity.ToString(),
GlobalVar.Connect3Entity.CycleTime.ToString(),
GlobalVar.Connect3Entity.RunningTime.ToString(),
GlobalVar.Connect3Entity.WaitingTime.ToString(),
"1",
GlobalVar.Connect3Entity.InputQuantity.ToString(),
GlobalVar.Connect3Entity.ErrorCount.ToString(),
GlobalVar.Connect3Entity.ErrorTime.ToString()
))));
_cfxHelper4.PublishEvent(new CFXEnvelope(stationParametersModifiedEvent.Handle(ParameterSet(GlobalVar.Connect4Entity.InterfaceID,
"制程设备",
GlobalVar.Connect4Entity.Status,
GlobalVar.Connect4Entity.Status,
GlobalVar.Connect4Entity.StatusCode,
GlobalVar.Connect4Entity.PassQuantity.ToString(),
GlobalVar.Connect4Entity.FailQuantity.ToString(),
GlobalVar.Connect4Entity.CycleTime.ToString(),
GlobalVar.Connect4Entity.RunningTime.ToString(),
GlobalVar.Connect4Entity.WaitingTime.ToString(),
"1",
GlobalVar.Connect4Entity.InputQuantity.ToString(),
GlobalVar.Connect4Entity.ErrorCount.ToString(),
GlobalVar.Connect4Entity.ErrorTime.ToString()
))));
}
private string tranter()
private string tranter(MesReportEntity entity)
{
entity.CycleTime = _appConfig.CycleTime;
entity.RunningTime = (int)(DateTime.Now - GlobalVar.OpenTime).TotalSeconds;
#region 傳送字的資料
string strSendData;
strSendData = "[{";
// strSendData += "\"factory\":\"" + "DG5" + "\",";
strSendData += "\"interfaceID\":\"" + InterfaceID + "\",";
strSendData += "\"interfaceID\":\"" + entity.InterfaceID + "\",";
// strSendData += "\"EquipType\":" + EquipType + ",";
strSendData += "\"status\":" + Status + ",";
strSendData += "\"statusCode\":\"" + StatusCode + "\",";
strSendData += "\"passQty\":" + PassQuantity + ",";
strSendData += "\"failQty\":" + FailQuantity + ",";
strSendData += "\"errorCnt\":" + ErrorCount + ",";
strSendData += "\"errorTimes\":" + ErrorTime + ",";
strSendData += "\"cycleTime\":" + CycleTime + ",";
strSendData += "\"runningTime\":" + RunningTime + ",";
strSendData += "\"waitingTime\":" + WaitingTime + ",";
strSendData += "\"status\":" + entity.Status + ",";
strSendData += "\"statusCode\":\"" + entity.StatusCode + "\",";
strSendData += "\"passQty\":" + entity.PassQuantity + ",";
strSendData += "\"failQty\":" + entity.FailQuantity + ",";
strSendData += "\"errorCnt\":" + entity.ErrorCount + ",";
strSendData += "\"errorTimes\":" + entity.ErrorTime + ",";
strSendData += "\"cycleTime\":" + entity.CycleTime + ",";
strSendData += "\"runningTime\":" + entity.RunningTime + ",";
strSendData += "\"waitingTime\":" + entity.WaitingTime + ",";
// strSendData += "\"selfCheck\":" + (SELFCHECK ? "1" : "0") + ",";
strSendData += "\"selfCheck\":" + "1" + ",";
strSendData += "\"inputQty\":" + InputQuantity + ",";
strSendData += "\"barcode\":\"" + Barcode + "\",";
strSendData += "\"model\":\"" + Cya + "\",";
strSendData += "\"inputQty\":" + entity.InputQuantity + ",";
strSendData += "\"barcode\":\"" + entity.Barcode + "\",";
strSendData += "\"model\":\"" + entity.Cya + "\",";
//端子壽命
strSendData += "\"paramList\":[";
// strSendData += "{\"paramCode\":\"" + Key1 + "\",";
// strSendData += "\"paramValue\":\"" + Value1 + "\"},";
@ -80,11 +153,307 @@ namespace Sln.Iot.Business
strSendData += "]";
strSendData += "}]";
_cfxHelper.PublishEvent(new CFXEnvelope(stationParametersModifiedEvent.Handle(ParameterSet(entity.InterfaceID,
"制程设备",
entity.Status,
entity.Status,
entity.StatusCode,
entity.PassQuantity.ToString(),
entity.FailQuantity.ToString(),
entity.CycleTime.ToString(),
entity.RunningTime.ToString(),
entity.WaitingTime.ToString(),
"1",
entity.InputQuantity.ToString(),
entity.ErrorCount.ToString(),
entity.ErrorTime.ToString()
))));
#endregion
return strSendData;
}
/// <summary>
/// 设备状态获取
/// </summary>
/// <returns></returns>
private void ErrorGet(int deviceNo)
{
string status = "0";
string statusCode = "0";
if (deviceNo == 1)
{
var r1 = _plc.ReadInt16(_plc.DeltaInstance1, "D15176");
var r2 = _plc.ReadInt16(_plc.DeltaInstance2, "D15176");
if (r1.IsSuccess && r2.IsSuccess)
{
if (r1.Content == 0 && r2.Content == 0)
{
GlobalVar.Connect1Entity.StatusCode = "0";
GlobalVar.Connect1Entity.Status = StatusJudge(0).ToString();
}
else if (r1.Content != 0)
{
GlobalVar.Connect1Entity.StatusCode = r1.Content.ToString();
GlobalVar.Connect1Entity.Status = StatusJudge(r1.Content).ToString();
}
else if (r2.Content != 0)
{
GlobalVar.Connect1Entity.StatusCode = r2.Content.ToString();
GlobalVar.Connect1Entity.Status = StatusJudge(r2.Content).ToString();
}
if (GlobalVar.Connect1Entity.Status == "1")
{
if (GlobalVar.Connect1Entity.IsError == false)
{
GlobalVar.Connect1Entity.ErrorCount++;
GlobalVar.Connect1Entity.LastErrorTime = DateTime.Now;
GlobalVar.Connect1Entity.IsError = true;
}
else
{
GlobalVar.Connect1Entity.ErrorTime = (int)(DateTime.Now - GlobalVar.Connect1Entity.LastErrorTime).TotalSeconds;
}
}
else
{
if (GlobalVar.Connect1Entity.IsError == true)
{
GlobalVar.Connect1Entity.IsError = false;
}
}
}
else
{
_log.Error($"读取PLC状态失败: 真空箱1{r1.IsSuccess} - {r1.Message}; 真空箱2{r2.IsSuccess} - {r2.Message}");
}
}
else if (deviceNo == 2)
{
var r1 = _plc.ReadInt16(_plc.DeltaInstance3, "D15176");
if (r1.IsSuccess)
{
GlobalVar.Connect2Entity.StatusCode = r1.Content.ToString();
GlobalVar.Connect2Entity.Status = StatusJudge(r1.Content).ToString();
if (GlobalVar.Connect2Entity.Status == "1")
{
if (GlobalVar.Connect2Entity.IsError == false)
{
GlobalVar.Connect2Entity.ErrorCount++;
GlobalVar.Connect2Entity.LastErrorTime = DateTime.Now;
GlobalVar.Connect2Entity.IsError = true;
}
else
{
GlobalVar.Connect2Entity.ErrorTime = (int)(DateTime.Now - GlobalVar.Connect2Entity.LastErrorTime).TotalSeconds;
}
}
else
{
if (GlobalVar.Connect2Entity.IsError == true)
{
GlobalVar.Connect2Entity.IsError = false;
}
}
}
else
{
_log.Error($"读取PLC状态失败: 上料提升机{r1.IsSuccess} - {r1.Message}");
}
}
else if (deviceNo == 3)
{
var r1 = _plc.ReadInt16(_plc.DeltaInstance0, "D15176");
if (r1.IsSuccess)
{
GlobalVar.Connect3Entity.StatusCode = r1.Content.ToString();
GlobalVar.Connect3Entity.Status = StatusJudge(r1.Content).ToString();
if (GlobalVar.Connect3Entity.Status == "1")
{
if (GlobalVar.Connect3Entity.IsError == false)
{
GlobalVar.Connect3Entity.ErrorCount++;
GlobalVar.Connect3Entity.LastErrorTime = DateTime.Now;
GlobalVar.Connect3Entity.IsError = true;
}
else
{
GlobalVar.Connect3Entity.ErrorTime = (int)(DateTime.Now - GlobalVar.Connect3Entity.LastErrorTime).TotalSeconds;
}
}
else
{
if (GlobalVar.Connect3Entity.IsError == true)
{
GlobalVar.Connect3Entity.IsError = false;
}
}
}
else
{
_log.Error($"读取PLC状态失败: 烤箱{r1.IsSuccess} - {r1.Message}");
}
}
else if (deviceNo == 4)
{
var r1 = _plc.ReadInt16(_plc.DeltaInstance4, "D15176");
if (r1.IsSuccess)
{
GlobalVar.Connect4Entity.StatusCode = r1.Content.ToString();
GlobalVar.Connect4Entity.Status = StatusJudge(r1.Content).ToString();
if (GlobalVar.Connect4Entity.Status == "1")
{
if (GlobalVar.Connect4Entity.IsError == false)
{
GlobalVar.Connect4Entity.ErrorCount++;
GlobalVar.Connect4Entity.LastErrorTime = DateTime.Now;
GlobalVar.Connect4Entity.IsError = true;
}
else
{
GlobalVar.Connect4Entity.ErrorTime = (int)(DateTime.Now - GlobalVar.Connect4Entity.LastErrorTime).TotalSeconds;
}
}
else
{
if (GlobalVar.Connect4Entity.IsError == true)
{
GlobalVar.Connect4Entity.IsError = false;
}
}
}
else
{
_log.Error($"读取PLC状态失败: 下料提升机{r1.IsSuccess} - {r1.Message}");
}
}
//return (status, statusCode);
}
private void ErrorJudge(bool errorSituation)
{
}
/// <summary>
/// 根据StatusCode判断Status
/// </summary>
/// <param name="sc"></param>
/// <returns></returns>
private int StatusJudge(int sc)
{
if (sc == -1 || sc == 2)
{
return 0;
}
if (sc == 1 || sc == 10 || sc == 11)
{
return 1;
}
if (sc == 12)
{
return 10;
}
return 4;
}
/// <summary>
/// stationParameters参数设置
/// </summary>
public List<Parameter> ParameterSet(
string interfaceID,
string equipType,
string status,
string light,
string statusCode,
string passQty,
string failQty,
string cycleTime,
string runningTime,
string waitingTime,
string selfCheck,
string inputQty,
string errorCnt,
string errorTimes
)
{
return new List<Parameter>()
{
new GenericParameter()
{
Name = "InterfaceID",
Value = interfaceID
},
new GenericParameter()
{
Name = "EquipType",
Value = equipType
},
new GenericParameter()
{
Name = "Status",
Value = status
},
new GenericParameter()
{
Name = "Light",
Value = light
},
new GenericParameter()
{
Name = "StatusCode",
Value = statusCode
},
new GenericParameter()
{
Name = "PassQty",
Value = passQty
},
new GenericParameter()
{
Name = "FailQty",
Value = failQty
},
new GenericParameter()
{
Name = "CycleTime",
Value = cycleTime
},
new GenericParameter()
{
Name = "RunningTime",
Value = runningTime
},
new GenericParameter()
{
Name = "WaitingTime",
Value = waitingTime
},
new GenericParameter()
{
Name = "SelfCheck",
Value = selfCheck
},
new GenericParameter()
{
Name = "InputQty",
Value = inputQty
},
new GenericParameter()
{
Name = "ErrorCnt",
Value = errorCnt
},
new GenericParameter()
{
Name = "ErrorTimes",
Value = errorTimes
},
};
}
}
}

@ -4,6 +4,7 @@ using CFX.Structures.PressInsertion;
using HslCommunication;
using Sln.Iot.CFX.CFXConnect;
using Sln.Iot.CFX.Event;
using Sln.Iot.Common;
using Sln.Iot.PLC;
using Sln.Iot.Repository;
using Sln.Iot.Repository.dao;
@ -94,6 +95,14 @@ namespace Sln.Iot.Business
chars[j + 1] = temp;
}
prodcode[i] = new string(chars);
GlobalVar.Connect2Entity.InputQuantity++;
GlobalVar.Connect2Entity.PassQuantity++;
GlobalVar.Connect3Entity.InputQuantity++;
GlobalVar.Connect1Entity.InputQuantity++;
GlobalVar.Connect1Entity.PassQuantity++;
GlobalVar.Connect3Entity.PassQuantity++;
GlobalVar.Connect4Entity.InputQuantity++;
GlobalVar.Connect4Entity.PassQuantity++;
_log.Info($"{prodcode[i]}进入产线");
}
}

@ -5,6 +5,7 @@ using HslCommunication;
using Sln.Iot.CFX.CFXBusiness;
using Sln.Iot.CFX.CFXConnect;
using Sln.Iot.CFX.Event;
using Sln.Iot.Common;
using Sln.Iot.PLC;
using Sln.Iot.Repository.service;
using Sln.Iot.Serilog;
@ -92,6 +93,8 @@ namespace Sln.Iot.Business
string[] prodcode = trayBindingService.ProdCodeGet(traycode);
bool res = trayBindingService.TrayCodeDelete(traycode);
if (!res)

@ -29,7 +29,7 @@ namespace Sln.Iot.Business
public RecipeBusiness()
{
_timer = new Timer(TimerCallback, null, 0, 1500);
_timer = new Timer(TimerCallback, null, 0, 5000);
}
/// <summary>

@ -23,16 +23,18 @@
#endregion << 版 本 注 释 >>
using System.Diagnostics;
using CFX;
using CFX.InformationSystem.UnitValidation;
using CFX.Production;
using CFX.ResourcePerformance;
using CFX.Structures;
using CFX.Transport;
using Microsoft.Identity.Client;
using Sln.Iot.CFX.Event;
using Sln.Iot.CFX.RequestReceived;
using Sln.Iot.Config;
using Sln.Iot.Serilog;
using System.Diagnostics;
namespace Sln.Iot.CFX;
@ -43,6 +45,8 @@ public abstract class CFXHelper
{
SerilogHelper _log = SerilogHelper.Instance;
private readonly AppConfig _appConfig = AppConfigSetting.Load();
/// <summary>
/// CFX通讯端点
/// </summary>
@ -61,7 +65,7 @@ public abstract class CFXHelper
{
try
{
if(Endpoint == null)
if (Endpoint == null)
{
throw new ArgumentNullException("CFX 端点无引用null");
}
@ -118,7 +122,8 @@ public abstract class CFXHelper
//Task.Run(() =>
//{
Endpoint.Publish(env);
//_log.Iot($"{Endpoint.CFXHandle}推送事件{env.MessageName}");
if (_appConfig.IsCFXLog)
_log.Iot($"{Endpoint.CFXHandle}推送事件{env.MessageName}");
//});
}
catch (Exception e)

@ -3,11 +3,34 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sln.Iot.Model.Entity;
namespace Sln.Iot.Common
{
/// <summary>
/// 全局内存变量
/// </summary>
public class GlobalVar
{
//public static int
public static DateTime OpenTime;
/// <summary>
/// 真空箱数据
/// </summary>
public static MesReportEntity Connect1Entity = new MesReportEntity() { InterfaceID = "OT00470018" };
/// <summary>
/// 提升机1数据
/// </summary>
public static MesReportEntity Connect2Entity = new MesReportEntity() { InterfaceID = "OT00470019" };
/// <summary>
/// 烤箱2数据
/// </summary>
public static MesReportEntity Connect3Entity = new MesReportEntity() { InterfaceID = "OT00470017" };
/// <summary>
/// 提升机2数据
/// </summary>
public static MesReportEntity Connect4Entity = new MesReportEntity() { InterfaceID = "OT00470020" };
}
}

@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sln.Iot.Model\Sln.Iot.Model.csproj" />
<ProjectReference Include="..\Sln.Iot.Serilog\Sln.Iot.Serilog.csproj" />
</ItemGroup>

@ -34,6 +34,11 @@ namespace Sln.Iot.Config
/// </summary>
public string logPath { get; set; }
/// <summary>
/// 节拍时间(秒)
/// </summary>
public int CycleTime { get; set; }
/// <summary>
/// PLC配置
/// </summary>
@ -59,6 +64,31 @@ namespace Sln.Iot.Config
/// </summary>
public CFXConfig Lift2Config { get; set; }
/// <summary>
/// MES的URL
/// </summary>
public string MESURL { get; set; }
/// <summary>
/// MES的URN
/// </summary>
public string MESURN { get; set; }
/// <summary>
/// 是否输出报警日志
/// </summary>
public bool IsAlarmLog { get; set; }
/// <summary>
/// 是否输出MES日志
/// </summary>
public bool IsMESLog { get; set; }
/// <summary>
/// 是否输出CFX日志
/// </summary>
public bool IsCFXLog { get; set; }
/// <summary>
/// Gets the current application configuration instance.
/// </summary>

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sln.Iot.Model.Entity
{
/// <summary>
/// 日志上报实体类
/// </summary>
public class MesReportEntity
{
/// <summary>
/// 设备ID
/// </summary>
public string InterfaceID { get; set; }
/// <summary>
/// 设备运行状态
/// </summary>
public string Status { get; set; } = "0";
/// <summary>
/// 设备状态码
/// </summary>
public string StatusCode { get; set; } = "0";
/// <summary>
/// 良品数量
/// </summary>
public int PassQuantity { get; set; } = 0;
/// <summary>
/// 不良品数量
/// </summary>
public int FailQuantity { get; set; } = 0;
/// <summary>
/// 故障次数
/// </summary>
public int ErrorCount { get; set; } = 0;
/// <summary>
/// 故障时间
/// </summary>
public int ErrorTime { get; set; } = 0;
/// <summary>
/// 节拍时间
/// </summary>
public int CycleTime { get; set; } = 0;
/// <summary>
/// 运行时间
/// </summary>
public int RunningTime { get; set; } = 0;
/// <summary>
/// 等待时间
/// </summary>
public int WaitingTime { get; set; } = 10000;
/// <summary>
/// 投入数量
/// </summary>
public int InputQuantity { get; set; } = 0;
/// <summary>
/// 条码数据
/// </summary>
public string Barcode { get; set; } = "Unknow";
/// <summary>
/// 产品型号
/// </summary>
public string Cya { get; set; } = "灌胶机";
/// <summary>
/// 上次故障时间
/// </summary>
public DateTime LastErrorTime { get; set; }
/// <summary>
/// 现在是否故障
/// </summary>
public bool IsError { get; set; }
}
}

@ -66,14 +66,27 @@ namespace Sln.Iot.Repository.service
{
return false;
}
var res = _helper.Update(new OvenPlcData()
var oldData = _helper.Query(x => x.GUID == guid).FirstOrDefault();
if (oldData != null)
{
GUID = guid,
PreCureOven1TempActValue = data.PreCureOven1TempActValue,
PreCureOven2TempActValue = data.PreCureOven2TempActValue,
PreCureOven3TempActValue = data.PreCureOven3TempActValue,
PreCureOven4TempActValue = data.PreCureOven4TempActValue,
});
oldData.PreCureOven1TempActValue = data.PreCureOven1TempActValue;
oldData.PreCureOven2TempActValue = data.PreCureOven2TempActValue;
oldData.PreCureOven3TempActValue = data.PreCureOven3TempActValue;
oldData.PreCureOven4TempActValue = data.PreCureOven4TempActValue;
}
else
{
oldData = new OvenPlcData()
{
GUID = guid,
PreCureOven1TempActValue = data.PreCureOven1TempActValue,
PreCureOven2TempActValue = data.PreCureOven2TempActValue,
PreCureOven3TempActValue = data.PreCureOven3TempActValue,
PreCureOven4TempActValue = data.PreCureOven4TempActValue,
};
}
var res = _helper.Update(oldData);
return res == 0 ? false : true;
}
catch (Exception ex)
@ -95,14 +108,27 @@ namespace Sln.Iot.Repository.service
{
return false;
}
var res = _helper.Update(new OvenPlcData()
var oldData = _helper.Query(x => x.GUID == guid).FirstOrDefault();
if (oldData != null)
{
GUID = guid,
CureOven1TempActValue = data.CureOven1TempActValue,
CureOven2TempActValue = data.CureOven2TempActValue,
CureOven3TempActValue = data.CureOven3TempActValue,
CureOven4TempActValue = data.CureOven4TempActValue,
});
oldData.CureOven1TempActValue = data.CureOven1TempActValue;
oldData.CureOven2TempActValue = data.CureOven2TempActValue;
oldData.CureOven3TempActValue = data.CureOven3TempActValue;
oldData.CureOven4TempActValue = data.CureOven4TempActValue;
}
else
{
oldData = new OvenPlcData()
{
GUID = guid,
CureOven1TempActValue = data.CureOven1TempActValue,
CureOven2TempActValue = data.CureOven2TempActValue,
CureOven3TempActValue = data.CureOven3TempActValue,
CureOven4TempActValue = data.CureOven4TempActValue,
};
}
var res = _helper.Update(oldData!);
return res == 0 ? false : true;
}
catch (Exception ex)

@ -1,4 +1,5 @@
using Sln.Iot.Serilog;
using Sln.Iot.Config;
using Sln.Iot.Serilog;
using System.Text;
using TouchSocket.Core;
using TouchSocket.Http;
@ -20,6 +21,7 @@ namespace Sln.Iot.Socket
}
HttpClient DeltaClent = new HttpClient();
private readonly AppConfig _appConfig = AppConfigSetting.Load();
SerilogHelper _log = SerilogHelper.Instance;
@ -32,7 +34,7 @@ namespace Sln.Iot.Socket
{
var config = new TouchSocketConfig();
#region Http设置远程服务器地址
config.SetRemoteIPHost("http://10.148.192.32:8090");
config.SetRemoteIPHost(_appConfig.MESURL);
#endregion
#region Http客户端获取断线通知
@ -40,15 +42,24 @@ namespace Sln.Iot.Socket
{
a.AddTcpClosedPlugin(async (c, e) =>
{
Console.WriteLine("客户端断开连接");
_log.Info("客户端断开连接");
await e.InvokeNext();
});
});
//断线重连设置
config.ConfigurePlugins(a =>
{
a.UseReconnection<HttpClient>(options =>
{
options.PollingInterval = TimeSpan.FromSeconds(5);
});
});
#endregion
//配置config
await DeltaClent.SetupAsync(config);
await DeltaClent.ConnectAsync();//先做连接
_log.Info("MES连接成功");
}
catch (Exception ex)
{
@ -65,10 +76,9 @@ namespace Sln.Iot.Socket
var request = new HttpRequest();
request.SetContent(new StringHttpContent(jsonData, Encoding.UTF8, "application/json"))
.InitHeaders()
.SetUrl("/sensordata?sensorId=UploadMachineData")
.SetUrl(_appConfig.MESURN)
.SetHost(DeltaClent.RemoteIPHost.Host)
.AsPost();
try
{
//创建一个超时操作10秒后取消。
@ -77,8 +87,11 @@ namespace Sln.Iot.Socket
using (var responseResult = await DeltaClent.RequestAsync(request, cts.Token))
{
var response = responseResult.Response;
if (_appConfig.IsMESLog)
_log.Info($"发送数据:{jsonData}");
var result = await response.GetBodyAsync();
_log.Info($"响应结果:{result}");
if (_appConfig.IsMESLog)
_log.Info($"响应结果:{result}");
}
}
catch (Exception ex)

@ -1,16 +1,20 @@
global using Xunit;
global using Sln.Iot.Repository.dao;
global using Xunit;
using Sln.Iot.Business;
using Sln.Iot.Common;
using Sln.Iot.Config;
using Sln.Iot.PLC;
using Sln.Iot.Repository;
using Sln.Iot.Repository.service;
using System.Collections;
using Sln.Iot.Business;
using Sln.Iot.PLC;
using Sln.Iot.Common;
namespace Sln.Iot.Test
{
public class UnitTest1
{
private readonly AppConfig _appConfig = AppConfigSetting.Load();
[Fact]
public void Test1()
{
@ -80,9 +84,30 @@ namespace Sln.Iot.Test
[Fact]
public void Test3()
{
GetLocalIP.GetLocalIPAddress();
{
var ins = OvenPlcDataService.Instance;
var a = Guid.NewGuid().ToString();
ins.InsertData(a, 123);
ins.UpdateDataPreCure(a, new Model.Entity.UnitsProcess3Entity
{
PreCureOven1TempActValue = 1233,
PreCureOven2TempActValue = 1223,
PreCureOven3TempActValue = 1213,
PreCureOven4TempActValue = 1203,
});
ins.UpdateDataCure(a, new Model.Entity.UnitsProcess3Entity
{
CureOven1TempActValue = 1233,
CureOven2TempActValue = 1223,
CureOven3TempActValue = 1213,
CureOven4TempActValue = 1203,
});
}
[Fact]
public void Test4()
{
var a = _appConfig.IsCFXLog;
}
}
}

@ -7,6 +7,7 @@ using Sln.Iot.Business;
using Sln.Iot.CFX;
using Sln.Iot.CFX.CFXConnect;
using Sln.Iot.CFX.Event;
using Sln.Iot.Common;
using Sln.Iot.Config;
using Sln.Iot.PLC;
using Sln.Iot.Repository;
@ -53,6 +54,13 @@ namespace Sln.Iot
static async Task Main(string[] args)
{
bool isNotRunning; //互斥体判断
System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out isNotRunning); //同步基元变量
if (!isNotRunning) // 如果不是未运行状态
{
Environment.Exit(1);
}
SetConsoleCtrlHandler(cancelHandler, true);
//Serilog中间件
SerilogExtensions.UseSerilogExtensions();
@ -62,6 +70,7 @@ namespace Sln.Iot
var appConfig = AppConfigSetting.Load();
//PLC连接初始化
PLCConnect.Instance.InitConnect();
GlobalVar.OpenTime = DateTime.Now;
//CFX接口启动
//真空注胶机

@ -1,10 +1,16 @@
{
"AppConfig": {
//MESCycleTime
"CycleTime": 7200,
"logPath": "D:\\log",
//CFX
"VacuumConfig": {
//
"DeviceName": "Vacuum",
"CFXHandle": "CFX.A00.OT00470018",
//URI
"LocalURI": "amqp://127.0.0.1:1235",
//URI
"UpperURI": "http://10.148.192.32:8090/sensordata?sensorId=UploadMachineData"
},
"Lift1Config": {
@ -24,6 +30,16 @@
"CFXHandle": "CFX.A00.OT00470020",
"LocalURI": "amqp://127.0.0.1:1238",
"UpperURI": "http://10.148.192.32:8090/sensordata?sensorId=UploadMachineData"
}
},
//MES
"MESURL": "http://10.148.192.32:8090",
//MES
"MESURN": "/sensordata?sensorId=UploadMachineData",
//
"IsAlarmLog": true,
//MES
"IsMESLog": true,
//CFX
"IsCFXLog": false
}
}

Loading…
Cancel
Save