首次提交:添加src文件夹代码
This commit is contained in:
215
Cowain.Bake.Main/Station/LifeCycleStation.cs
Normal file
215
Cowain.Bake.Main/Station/LifeCycleStation.cs
Normal file
@@ -0,0 +1,215 @@
|
||||
using Cowain.Bake.BLL;
|
||||
using Cowain.Bake.Common;
|
||||
using Cowain.Bake.Common.Core;
|
||||
using Cowain.Bake.Common.Enums;
|
||||
using Cowain.Bake.Common.Interface;
|
||||
using Cowain.Bake.Communication.Interface;
|
||||
using Cowain.Bake.Model;
|
||||
using Cowain.Bake.Model.Models;
|
||||
using HslCommunication;
|
||||
using Newtonsoft.Json;
|
||||
using Opc.Ua;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Unity;
|
||||
|
||||
namespace Cowain.Bake.Main.Station
|
||||
{
|
||||
public class LifeCycleStation : IServerManager
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<TStation> _station = null;
|
||||
public IUnityContainer _unityContainer { get; set; }
|
||||
public LifeCycleStation(IUnityContainer unityContainer)
|
||||
{
|
||||
_unityContainer = unityContainer;
|
||||
_station = _unityContainer.Resolve<MemoryDataProvider>().AllStation;
|
||||
}
|
||||
|
||||
// 心跳
|
||||
public void LifeCycle(DataValue data, Variable node)
|
||||
{
|
||||
OperateResult writeResult = null;
|
||||
dynamic d = JsonConvert.DeserializeObject<dynamic>(node.Json);
|
||||
Int16 value = 0;
|
||||
if (data.WrappedValue.TypeInfo.BuiltInType == Opc.Ua.BuiltInType.Int16)
|
||||
{
|
||||
value = (System.Int16)data.WrappedValue.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Instance.Warn($"没有找到生命周期信号这个数据类型,节点名为{node.VarDesc}");
|
||||
}
|
||||
|
||||
var config = _unityContainer.Resolve<DeviceConfigService>().GetConfig(node.StationId);
|
||||
var plc = _unityContainer.Resolve<IPLCDevice>(config.Name);
|
||||
|
||||
writeResult = plc.Write<Int16>((string)d.WriteHeart, value); //回复为接收到的计数
|
||||
if (!writeResult.IsSuccess)
|
||||
{
|
||||
LogHelper.Instance.Warn($"LifeCycle-{node.StationId}-{value}-{(string)d.WriteHeart}:{writeResult.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
//向上位机请求任务,PLC请求命令:0=无意义;10=无托盘;20=有托盘
|
||||
public void ReqTask(DataValue data, Variable node)
|
||||
{
|
||||
//bool IsAccord = false; //是否符合取放盘
|
||||
try
|
||||
{
|
||||
dynamic d = JsonConvert.DeserializeObject<dynamic>(node.Json);
|
||||
Int16 value = 0;
|
||||
if (data.WrappedValue.TypeInfo.BuiltInType == Opc.Ua.BuiltInType.Int16)
|
||||
{
|
||||
value = (System.Int16)data.WrappedValue.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Instance.Warn($"没有找到请求任务信号这个数据类型,节点名为{node.VarDesc}");
|
||||
return;
|
||||
}
|
||||
|
||||
TStation station = _station.Where(p => p.Id == node.StationId).FirstOrDefault();
|
||||
LogHelper.Instance.Warn($"取放盘,值:{value},station:{node.StationId},层{node.Number}");
|
||||
|
||||
|
||||
//是否符合取放盘
|
||||
//if (_unityContainer.Resolve<CavityInfoService>().IsAccordReq(station, node.Number, (sbyte)value))
|
||||
{
|
||||
//IsAccord = true;
|
||||
//修改取放盘状态
|
||||
if (!_unityContainer.Resolve<CavityInfoService>().UpdateReqStatus(station, node.Number, (sbyte)value))
|
||||
{
|
||||
LogHelper.Instance.GetCurrentClassError($"修改请求任务失败,StationId:{node.StationId},Number:{node.Number},value:{value}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// LogHelper.Instance.GetCurrentClassError($"不符合取放盘,StationId:{node.StationId},Number:{node.Number},value:{value}");
|
||||
//}
|
||||
|
||||
//DealPalletRequest(value, node); //取消这个,不然上位机启动,会报异常
|
||||
|
||||
var config = _unityContainer.Resolve<DeviceConfigService>().GetConfig(node.StationId);
|
||||
var plc = _unityContainer.Resolve<IPLCDevice>(config.Name);
|
||||
var writeResult = plc.Write<int>((string)d.WriteRetCommand, value); //收到什么反馈什么。
|
||||
if (!writeResult.IsSuccess)
|
||||
{
|
||||
LogHelper.Instance.Warn($"ReqTask-{(string)d.WriteRetCommand}:{writeResult.Message}");
|
||||
}
|
||||
|
||||
value = (short)(value == 0 ? -1 : 1); //1=OK,2=重新上传,如果PLC请求命令是0,WCS返回-1
|
||||
writeResult = plc.Write<int>((string)d.WriteResult, value); //收到什么反馈什么。
|
||||
if (!writeResult.IsSuccess)
|
||||
{
|
||||
LogHelper.Instance.Warn($"ReqTask-{(string)d.WriteResult}:{writeResult.Message}");
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
LogHelper.Instance.Error($"请求解析出错:{node.Json},{node.TrigJson},{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
void DealPalletRequest(int value, Variable node)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case (int)ECavityStatus.RequestPick:
|
||||
DealPick(node);
|
||||
break;
|
||||
case (int)ECavityStatus.RequestPlace:
|
||||
//DealPlace(station, json);
|
||||
break;
|
||||
case (int)ECavityStatus.None:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DealPlace(TStation station, string json)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void DealPick(Variable node)
|
||||
{
|
||||
MethodInfo mi = null;
|
||||
dynamic d = JsonConvert.DeserializeObject<dynamic>(node.TrigJson);
|
||||
string service = d.ReflexService;
|
||||
string func = d.ReflexFunc;
|
||||
string param = d.Param; //方法的参数,如果是扫码,则是扫码的编号
|
||||
|
||||
if (string.IsNullOrEmpty(service))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LogHelper.Instance.Info($"请求取盘触发事件:{node.TrigJson}");
|
||||
var instnce = _unityContainer.Resolve<TrigStation>();
|
||||
Type type = Type.GetType(MyPath.SIGNAL_TRIGGER + service);
|
||||
mi = this.GetType().GetMethod(ReflexFun.TRIG_REPLY).MakeGenericMethod(new Type[] { type }); //回复信息;
|
||||
mi.Invoke(this, new object[]
|
||||
{
|
||||
func,
|
||||
1,
|
||||
param,
|
||||
node
|
||||
});
|
||||
}
|
||||
|
||||
public void TrigReply<T>(string func, int curValue, string param, Variable node)
|
||||
{
|
||||
//取得实例
|
||||
var instnce = _unityContainer.Resolve<T>(); //上下料实例
|
||||
Type t = instnce.GetType();
|
||||
|
||||
//取得方法
|
||||
MethodInfo mi = t.GetMethod(func);
|
||||
//调用方法
|
||||
mi.Invoke(instnce, new object[]
|
||||
{
|
||||
curValue,
|
||||
param,
|
||||
node
|
||||
});
|
||||
}
|
||||
|
||||
//心跳
|
||||
public void Alive(DataValue data, Variable node)
|
||||
{
|
||||
dynamic d = JsonConvert.DeserializeObject<dynamic>(node.Json);
|
||||
Int16 value = 0;
|
||||
if (data.WrappedValue.TypeInfo.BuiltInType == Opc.Ua.BuiltInType.Int16)
|
||||
{
|
||||
value = (System.Int16)data.WrappedValue.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Instance.Warn($"收到心跳解析出错,工站:{node.StationId},节点名为{node.VarDesc}");
|
||||
return;
|
||||
}
|
||||
|
||||
var config = _unityContainer.Resolve<DeviceConfigService>().GetConfig(node.StationId);
|
||||
var plc = _unityContainer.Resolve<IPLCDevice>(config.Name);
|
||||
var writeResult = plc.Write<int>(d.RetCommand, value); //收到什么反馈什么。
|
||||
if (!writeResult.IsSuccess)
|
||||
{
|
||||
LogHelper.Instance.Warn($"Alive-{d.WriteResult}:{writeResult.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user