Files
6098/Cowain.Bake.Main/Common/CommonFun.cs

180 lines
6.2 KiB
C#

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();
}
}
}