首次提交:添加src文件夹代码

This commit is contained in:
2026-02-27 14:02:43 +08:00
commit d330cfbca7
4184 changed files with 5546478 additions and 0 deletions

View File

@@ -0,0 +1,244 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Common.Core;
using Cowain.Bake.Common.Enums;
using Cowain.Bake.Communication.Interface;
using Cowain.Bake.Model;
using Cowain.Bake.Model.Models;
using HslCommunication;
using System.Linq;
using Unity;
namespace Cowain.Bake.Main.Common
{
public class CmdFactories
{
IUnityContainer _unityContainer { get; set; }
//IPLCDevice agv = null;
public CmdFactories(IUnityContainer unityContainer)
{
_unityContainer = unityContainer;
}
public bool StartBaking(IPLCDevice plc, int stationId, bool[] bakeEanble, bool manual = false)
{
if (!Write<bool[]>(plc, EStoveSignal.HeatEnableStep.ToString(), stationId, 1, bakeEanble).IsSuccess)
{
LogHelper.Instance.Error($"层烘烤使能失败plc:{plc.Name}", true);
return false;
}
if (!Write<bool>(plc, EStoveSignal.BakingStart.ToString(), stationId, 1, true).IsSuccess)
{
LogHelper.Instance.GetCurrentClassError($"下发开始烘烤失败plc:{plc.Name}", true);
return false;
}
if (manual)
{
LogHelper.Instance.Info($"下发开始烘烤成功!", true);
}
return true;
}
//public bool EndBaking(int stationId)
//{
// TDeviceConfig conf = _unityContainer.Resolve<DeviceConfigService>().GetConfig(stationId);
// IPLCDevice plc = _unityContainer.Resolve<IPLCDevice>(conf.Name);
// if (plc == null || !plc.IsConnect)
// {
// LogHelper.Instance.GetCurrentClassError($"连接PLC失败plc:{plc.Name}", true);
// return false;
// }
// if (!Write<bool>(plc, EStoveSignal.BakingEnd.ToString(), stationId, true).IsSuccess)
// {
// LogHelper.Instance.GetCurrentClassError($"下发结束烘烤失败plc:{plc.Name}", true);
// return false;
// }
// LogHelper.Instance.Info($"下发结束烘烤成功!", true);
// return true;
//}
//复位结束烘烤
public bool ResetEndBaking(int machineId)
{
TDeviceConfig conf = _unityContainer.Resolve<DeviceConfigService>().GetConfig(machineId);
IPLCDevice plc = _unityContainer.Resolve<IPLCDevice>(conf.Name);
if (plc == null || !plc.IsConnect)
{
LogHelper.Instance.GetCurrentClassError($"连接PLC失败plc:{plc.Name}", true);
return false;
}
if (!Write<bool>(plc, EStoveSignal.BakingMark.ToString(), machineId, 1, false).IsSuccess)
{
LogHelper.Instance.GetCurrentClassError($"下发复位结束烘烤失败plc:{plc.Name}", true);
return false;
}
return true;
}
public bool OpenDoor(int stationId, int layer)
{
TDeviceConfig fromDev = _unityContainer.Resolve<DeviceConfigService>().GetConfig(stationId);
IPLCDevice plc = _unityContainer.Resolve<IPLCDevice>(fromDev.Name);
if (plc == null || !plc.IsConnect)
{
LogHelper.Instance.GetCurrentClassError($"连接PLC失败plc:{plc.Name},layer:{layer}", true);
return false;
}
if (!CommonFun.Instance.IsStoveQualified(plc, stationId, layer, false, true)) //不在工作中
{
return false;
}
if (Write<bool>(plc, EStoveSignal.OpenDoor.ToString(), stationId,1, true).IsSuccess)
{
HandyControl.Controls.MessageBox.Show($@"下发开门指令成功!", "操作提示");
return false;
}
else
{
HandyControl.Controls.MessageBox.Error($@"下发开门指令失败。", "操作提示");
LogHelper.Instance.GetCurrentClassError($"下发开门指令失败plc:{plc.Name},layer:{layer}");
}
return true;
}
public bool CloseDoor(int machineId, int layer)
{
TDeviceConfig fromDev = _unityContainer.Resolve<DeviceConfigService>().GetConfig(machineId);
IPLCDevice plc = _unityContainer.Resolve<IPLCDevice>(fromDev.Name);
if (plc == null || !plc.IsConnect)
{
LogHelper.Instance.GetCurrentClassError($"连接PLC失败plc:{plc.Name},layer:{layer}", true);
return false;
}
if (!CommonFun.Instance.IsStoveQualified(plc, machineId, layer, false, true)) //不在工作中
{
return false;
}
if (Write<bool>(plc, EStoveSignal.CloseDoor.ToString(), machineId, 1, true).IsSuccess)
{
HandyControl.Controls.MessageBox.Show($@"下发关门指令成功!", "操作提示");
return true;
}
else
{
HandyControl.Controls.MessageBox.Error($@"下发关门指令失败。", "操作提示");
LogHelper.Instance.GetCurrentClassError($"下发关门指令失败plc:{plc.Name},layer:{layer}");
return false;
}
}
public bool InitStove(int stationId, int layer)
{
TDeviceConfig dev = _unityContainer.Resolve<DeviceConfigService>().GetConfig(stationId);
IPLCDevice plc = _unityContainer.Resolve<IPLCDevice>(dev.Name);
if (plc == null || !plc.IsConnect)
{
LogHelper.Instance.GetCurrentClassError($"连接PLC失败plc:{plc.Name}");
return false;
}
if (!CommonFun.Instance.IsStoveQualified(plc, stationId, layer, false, true)) //不在工作中
{
return false;
}
if (Write<bool>(plc, EStoveSignal.Initial.ToString(), stationId, 1, true).IsSuccess)
{
HandyControl.Controls.MessageBox.Show($@"下发初始化请求指令成功!", "操作提示");
return true;
}
else
{
HandyControl.Controls.MessageBox.Error($@"下发初始化请求指令失败。", "操作提示");
LogHelper.Instance.GetCurrentClassError($"下发初始化请求指令失败plc:{plc.Name}");
return false;
}
}
//public bool NotifyPLCHavePallet(int machineId, int layer, int number)
//{
// TDeviceConfig dev = _unityContainer.Resolve<DeviceConfigService>().GetConfig(machineId);
// IPLCDevice plc = _unityContainer.Resolve<IPLCDevice>(dev.Name);
// if (plc == null || !plc.IsConnect)
// {
// LogHelper.Instance.GetCurrentClassError($"连接PLC失败plc:{plc.Name},layer:{layer}");
// return false;
// }
// if (!CommonFun.Instance.IsStoveQualified(plc, machineId, layer))
// {
// return false;
// }
// string Tray = number == 1 ? EStoveSignal.Tray1.ToString() : EStoveSignal.Tray2.ToString();
// if (Write<bool>(plc, Tray, machineId,layer,true).IsSuccess)
// {
// HandyControl.Controls.MessageBox.Show($@"下发托盘记忆成功!", "操作提示");
// return true;
// }
// else
// {
// HandyControl.Controls.MessageBox.Error($@"下发托盘记忆失败。", "操作提示");
// LogHelper.Instance.GetCurrentClassError($"下发托盘记忆失败plc:{plc.Name},layer:{layer}");
// return false;
// }
//}
//public bool NotifyPLCDontHavePallet(int machineId, int layer, int number)
//{
// TDeviceConfig dev = _unityContainer.Resolve<DeviceConfigService>().GetConfig(machineId);
// IPLCDevice plc = _unityContainer.Resolve<IPLCDevice>(dev.Name);
// if (plc == null || !plc.IsConnect)
// {
// LogHelper.Instance.GetCurrentClassError($"连接PLC失败plc:{plc.Name},layer:{layer}");
// return false;
// }
// if (!CommonFun.Instance.IsStoveQualified(plc, machineId, layer))
// {
// return false;
// }
// string Tray = number == 1 ? EStoveSignal.Tray1.ToString() : EStoveSignal.Tray2.ToString();
// if (Write<bool>(plc, Tray, machineId, layer, false).IsSuccess)
// {
// HandyControl.Controls.MessageBox.Show($@"下发托盘记忆成功!", "操作提示");
// return true;
// }
// else
// {
// HandyControl.Controls.MessageBox.Error($@"下发清除托盘记忆失败。", "操作提示");
// LogHelper.Instance.GetCurrentClassError($"下发清除托盘记忆失败plc:{plc.Name},layer:{layer}");
// return false;
// }
//}
public OperateResult Write<T>(IPLCDevice plc, string paramName, int machineId, int layer, T data)
{
string nodeAddr = "";
OperateResult result = new OperateResult()
{
IsSuccess = false,
};
Variable node = null;
node = (from storage in plc.Storages
from item in storage.VariableList
where storage.StationId == machineId && item.ParamName == paramName && item.Number == layer
select item).FirstOrDefault();
if (null == node)
{
return result;
}
nodeAddr = $"{node.Address}{node.VarName}";
return plc.Write<T>(nodeAddr, data);
}
}
}

View File

@@ -0,0 +1,179 @@
using ControlzEx.Standard;
using Cowain.Bake.Common;
using Cowain.Bake.Common.Core;
using Cowain.Bake.Common.Enums;
using Cowain.Bake.Communication.Interface;
using Cowain.Bake.Main.Models;
using Cowain.Bake.Main.Station;
using Cowain.Bake.Model.Models;
using HslCommunication;
using Opc.Ua;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Unity;
namespace Cowain.Bake.Main.Common
{
public class CommonFun
{
private static CommonFun instance;
public static CommonFun Instance
{
get
{
if (instance == null)
{
instance = new CommonFun();
}
return instance;
}
}
//public OperateResult Writes(IUnityContainer unityContainer, string reply, object[] values)
//{
// //string[] arrayAddress = reply.Address1.Split(',');
// //var plc = unityContainer.Resolve<IPLCDevice>(reply.PLCName);
// //EDataType dt = (EDataType)Enum.Parse(typeof(EDataType), reply.AddressType);
// //Type type = Type.GetType(dt.GetDescription());
// //var mi = this.GetType().GetMethod(ReflexFun.OPC_WRITE_NODES).MakeGenericMethod(new Type[] { type }); //反射;
// //return (OperateResult)mi.Invoke(this, new object[]
// //{
// // plc,
// // arrayAddress,
// // values
// //});
// return null;
//}
//public OperateResult Write(IUnityContainer unityContainer, string reply, object value)
//{
// //var plc = unityContainer.Resolve<IPLCDevice>(reply.PLCName);
// //EDataType dt = (EDataType)Enum.Parse(typeof(EDataType), reply.AddressType);
// //Type type = Type.GetType(dt.GetDescription());
// //var mi = this.GetType().GetMethod(ReflexFun.OPC_WRITE_NODE).MakeGenericMethod(new Type[] { type }); //反射;
// //return (OperateResult)mi.Invoke(this, new object[]
// //{
// // plc,
// // reply.Address,
// // value
// //});
// return null;
//}
//烘箱是否具备条件
public bool IsStoveQualified(IPLCDevice plc, int machineId, int layer, bool isWork, bool popupScreen = false) //popupScreen:人工下发指令要弹屏
{
//远程/本地模式
var mode = plc.GetValue<bool>(EStoveSignal.Remote.ToString(), machineId, layer);
if (!mode.IsSuccess) //本地
{
//LogHelper.Instance.Error("读取远程模式失败或本地模式!", null, true);
return false ;
}
if (!mode.Content) //true:远程, false:本地
{
if (popupScreen)
{
LogHelper.Instance.Error("本地模式,不能执行指令操作!", true);
}
//return false; //add by lsm 20250926 test
}
//0 / 空闲 1 / 待机 2 / 停止 3 / 工作 4 / 保压
var workStatus = plc.GetValue<Int16>(EStoveSignal.CavityStatus.ToString(), machineId, layer);
if (!workStatus.IsSuccess) //系统状态寄存器
{
if (popupScreen)
{
LogHelper.Instance.Error("读取烘箱工作状态失败!", true);
}
return false ;
}
if (isWork) //
{
if ((int)EStoveWorkMode.Standby >= workStatus.Content) //工作当中判断,0,1
{
if (popupScreen)
{
LogHelper.Instance.Error("判断要在工作当中,却为空闲,所以不满足条件执行!");
}
return false;
}
}
else //要求不是工作状态
{
if ((int)EStoveWorkMode.Standby < workStatus.Content) //非工作当中判断,2,3,4
{
if (popupScreen)
{
LogHelper.Instance.Error("判断要在空闲当中,却为工作,所以不满足条件执行!");
}
return false;
}
}
return true;
}
public bool IsStoveQualified(IPLCDevice plc, int machineId, int layer)
{
//远程/本地模式 var mode = plc.GetValue<bool>(EStoveSignal.CavityStatus.ToString(), item.Key, layer);
var mode = plc.GetValue<bool>(EStoveSignal.Remote.ToString(), machineId, layer);
if (!mode.IsSuccess) //本地
{
LogHelper.Instance.Error("读取远程模式失败或本地模式!", true);
return false;
}
if (!mode.Content) //true:远程, false:本地
{
LogHelper.Instance.Error("本地模式,不能执行其操作!", true);
return false;
}
return true;
}
//发送一个节点,数据可以是单个,也可以是数组
//public OperateResult WriteNode<T>(IPLCDevice plc, string address, object value)
//{
// if (value is Array)
// {
// T[] t = (T[])Convert.ChangeType(value, typeof(T[]));
// return plc.Write<T[]>(address, t);
// }
// else
// {
// T t = (T)Convert.ChangeType(value, typeof(T));
// return plc.Write<T>(address, t);
// }
//}
//public OperateResult WriteNodes<T>(IPLCDevice plc, string[] tags, object[] values)
//{
// //T t = (T)Convert.ChangeType(value, typeof(T));
// return plc.Writes(tags, values);
//}
public float[] UShortToFloat(Int16[] datas)
{
List<float> f = new List<float>();
for (int i = 1; i < datas.Count(); i++)
{
f.Add(datas[i] / 1.0f / 100);
}
return f.ToArray();
}
}
}

View File

@@ -0,0 +1,79 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Common.Core;
using Cowain.Bake.Common.Interface;
using Cowain.Bake.Communication.MOM;
using Cowain.Bake.Main.Station;
using Cowain.Bake.Main.ViewModels;
using Cowain.Bake.Main.Views;
using Cowain.Bake.Model;
using System.Collections.Generic;
using System.Linq;
using Unity;
using JSON = Newtonsoft.Json.JsonConvert;
using static Cowain.Bake.Common.Models.MESModel;
namespace Cowain.Bake.Main.Common
{
public class ExecCommonFun : ICommonFun
{
readonly IUnityContainer _unityContainer;
public ExecCommonFun(IUnityContainer unityContainer)
{
_unityContainer = unityContainer;
}
public void ModifyOrderNum()
{
var basicInfoViewModel = _unityContainer.Resolve<BasicInfoViewModel>();
var memory = _unityContainer.Resolve<MemoryDataProvider>();
basicInfoViewModel.CurrentJobNum = memory.CurrentUser.JobNum;
basicInfoViewModel.CurrentOperation = memory.CurrentUser.ProcessParamName;
SettingProvider.Instance.WaterPallet = 0;
}
public bool ManualTaskCmd(TTaskRecord task, short stepId)
{
return _unityContainer.Resolve<TaskStation>().ManualTaskCmd(task, stepId); //发送
}
public void InitWindows()
{
_unityContainer.Resolve<MainHeaderView>().ClearWindows(); //
_unityContainer.Resolve<MainHeaderView>().Init(); //
}
public void SetBatteryCodeLen()
{
_unityContainer.Resolve<LoadingStation>().SetBatteryCodeLen(); //
}
public string ManualMesOutUnBinding(TPalletInfo palletInfo, TBatteryInfo battery)
{
string msg = "";
List<TBatteryInfo> betterys = new List<TBatteryInfo>() ;
betterys.Add(battery);
var mesResult = _unityContainer.Resolve<UnLoadingStation>().MesOutUnBinding(palletInfo, betterys, true);
if (mesResult == null)
{
msg = $"出站MOM返回超时,电芯条码:{string.Join(",", betterys.Select(x => x.BatteryCode).ToList())}";
LogHelper.Instance.Error(msg); //偶尔会返回空,
}
else if (mesResult.Info.ResultFlag.ToUpper() == "NG")
{
msg = $"出站MOM返回信息异常,信息:{JSON.SerializeObject(mesResult)}";
}
else
{
msg = $"信息:{JSON.SerializeObject(mesResult)}";
}
return msg;
}
public MESReturnCmdModel SendData(string info)
{
return _unityContainer.Resolve<MESProcess>().SendData(info); //发送
}
}
}

View File

@@ -0,0 +1,106 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Common;
using Cowain.Bake.Common.Enums;
using Cowain.Bake.Main.Station;
using Cowain.Bake.Main.ViewModels;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
namespace Cowain.Bake.Main.Common
{
public class HeaderCMD
{
private readonly IUnityContainer _unityContainer;
public HeaderCMD(IUnityContainer unityContainer)
{
_unityContainer = unityContainer;
//_basicInfo = basicInfo;
}
public void Auto(string JSON)
{
Views.MainHeaderView.ribbonButtonDic["Auto"].IsEnabled = false;
Views.MainHeaderView.ribbonButtonDic["Manual"].IsEnabled = true;
Bake.Common.Core.SettingProvider.Instance.DispMode = EDispatchMode.Auto;
HandyControl.Controls.MessageBox.Success("自动调度", "切换调度模式");
_unityContainer.Resolve<TaskStation>()._newTaskEvent.Set();
_unityContainer.Resolve<BasicInfoViewModel>().DispMode= EDispatchMode.Auto.GetDescription();
}
public void Manual(string JSON)
{
if (System.Windows.MessageBoxResult.OK ==HandyControl.Controls.MessageBox.Ask("调度机器人将停下来,您确定手动调度?", "切换调度模式"))
{
Views.MainHeaderView.ribbonButtonDic["Manual"].IsEnabled = false;
Views.MainHeaderView.ribbonButtonDic["Auto"].IsEnabled = true;
Bake.Common.Core.SettingProvider.Instance.DispMode = EDispatchMode.Manual;
_unityContainer.Resolve<BasicInfoViewModel>().DispMode = EDispatchMode.Manual.GetDescription();
}
}
public void ScanCodeMode(string JSON)
{
string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
UpdateSwitch(JSON, Cowain.Bake.Common.Enums.ESysSetup.ScanCodeMode.ToString(), methodName);
_unityContainer.Resolve<LogService>().AddLog($@"切换【{Cowain.Bake.Common.Enums.ESysSetup.ScanCodeMode.GetDescription()}】!", E_LogType.Operate.ToString());
}
private bool UpdateSwitch(string JSON, string paraID, string methodName)
{
DataTable table = _unityContainer.Resolve<Cowain.Bake.BLL.MenuInfoService>().GetLabelName(methodName);
string labelName = table.Rows[0]["Header"].ToString();
var service = _unityContainer.Resolve<Cowain.Bake.BLL.SysSetupService>();
if (Views.MainHeaderView.toggleButtonLabelDic[labelName].Content.ToString()
== table.Rows[0]["Value0"].ToString())
{
Views.MainHeaderView.toggleButtonLabelDic[labelName].Content = table.Rows[0]["Value1"].ToString();
return service.UpdateValue(paraID, "1");
}
else
{
Views.MainHeaderView.toggleButtonLabelDic[labelName].Content = table.Rows[0]["Value0"].ToString();
return service.UpdateValue(paraID, "0");
}
}
public void DebugMode(string JSON)
{
string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
DataTable table = _unityContainer.Resolve<Cowain.Bake.BLL.MenuInfoService>().GetLabelName(methodName);
string labelName = table.Rows[0]["Header"].ToString();
if (Views.MainHeaderView.toggleButtonLabelDic[labelName].Content.ToString()
== table.Rows[0]["Value0"].ToString())
{
Views.MainHeaderView.toggleButtonLabelDic[labelName].Content = table.Rows[0]["Value1"].ToString();
_unityContainer.Resolve<BLL.SysSetupService>().UpdateValue(ESysSetup.DebugMode.ToString(), ((int)EProductionMode.Normal).ToString());
}
else
{
Views.MainHeaderView.toggleButtonLabelDic[labelName].Content = table.Rows[0]["Value0"].ToString();
_unityContainer.Resolve<BLL.SysSetupService>().UpdateValue(ESysSetup.DebugMode.ToString(), ((int)EProductionMode.Debug).ToString());
}
}
public void MOMEnable(string JSON)
{
string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
DataTable table = _unityContainer.Resolve<Cowain.Bake.BLL.MenuInfoService>().GetLabelName(methodName);
string labelName = table.Rows[0]["Header"].ToString();
if (Views.MainHeaderView.toggleButtonLabelDic[labelName].Content.ToString()
== table.Rows[0]["Value0"].ToString())
{
Views.MainHeaderView.toggleButtonLabelDic[labelName].Content = table.Rows[0]["Value1"].ToString();
_unityContainer.Resolve<BLL.SysSetupService>().UpdateValue(ESysSetup.MOMEnable.ToString(), ((int)EMOMEnable.Enable).ToString());
}
else
{
Views.MainHeaderView.toggleButtonLabelDic[labelName].Content = table.Rows[0]["Value0"].ToString();
_unityContainer.Resolve<BLL.SysSetupService>().UpdateValue(ESysSetup.MOMEnable.ToString(), ((int)EMOMEnable.Disable).ToString());
}
}
}
}