using System;
|
using System.Threading;
|
using iWareCommon.Utils;
|
|
using System.Linq;
|
using Newtonsoft.Json;
|
using System.Collections.Generic;
|
using iWareCommon;
|
using System.Text;
|
using iWareModel;
|
|
|
|
namespace iWareSda
|
{
|
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“LineService”。
|
public class LineService : ILineService
|
{
|
private static string _namespace = "iWareSda.LineService";
|
private static string nofoundStackerMsg = SysHelper.Language(WareSdaStruct.LanguageFlg, "没有找到输送线", "No found the Line");
|
public LineView GetLineInfo(int deviceId)
|
{
|
var device = Line_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
|
if (device == null)
|
{
|
return null;
|
}
|
return device.View;
|
}
|
|
/// <summary>
|
/// 判断是否有心跳
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <returns></returns>
|
public SdaResEntity IsHaveHeatBeat(int deviceId)
|
{
|
SdaResEntity sdaResult = new SdaResEntity();
|
string msg;
|
try
|
{
|
var device = Line_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
|
if (device == null)
|
{
|
sdaResult.resMsg = nofoundStackerMsg;
|
return sdaResult;
|
}
|
|
var result = device.IsHaveHeatBeat();
|
|
sdaResult.result = true;
|
sdaResult.resData = result;
|
return sdaResult;
|
|
}
|
catch (Exception ex)
|
{
|
msg = "验证是否有心跳出现异常:" + ex.Message;
|
Log4NetHelper.WriteErrorLog(LogType.LineSdaService, msg, ex);
|
sdaResult.result = false;
|
sdaResult.resMsg = msg;
|
return sdaResult;
|
}
|
}
|
|
/// <summary>
|
/// 检测设备是否可以发任务
|
/// </summary>
|
/// <returns></returns>
|
public SdaResEntity IsAllowSendTask(int deviceId)
|
{
|
SdaResEntity res = new SdaResEntity();
|
res.result = true;
|
return res;
|
//try
|
//{
|
// DeviceEnum device = (DeviceEnum)Enum.Parse(typeof(DeviceEnum), deviceId.ToString());
|
// AreaEnum area = BussinessHelper.GetAreaByDevice(device);
|
// var line = Line_CacheEntity.Lines[0];
|
// switch (area)
|
// {
|
// case AreaEnum.区域1:
|
// if (!line.R_AutoMode_1)
|
// {
|
// res.resData = false;
|
// res.resMsg = "区域1设备不是自动模式";
|
// return res;
|
// }
|
// break;
|
// case AreaEnum.区域2:
|
// if (!line.R_AutoMode_2)
|
// {
|
// res.resData = false;
|
// res.resMsg = "区域2设备不是自动模式";
|
// return res;
|
// }
|
// break;
|
// }
|
|
// if (!line.IsConnected)
|
// {
|
// res.resData = false;
|
// res.resMsg = "未与PLC连接";
|
// return res;
|
// }
|
|
// switch (device)
|
// {
|
// case DeviceEnum.翻转机R01:
|
// if (line.R_R01_TaskNo != 0)
|
// {
|
// res.resData = false;
|
// res.resMsg = "R01上有任务在执行";
|
// return res;
|
// }
|
// break;
|
// case DeviceEnum.翻转机R04:
|
// if (line.R_R04_TaskNo != 0)
|
// {
|
// res.resData = false;
|
// res.resMsg = "R04上有任务在执行";
|
// return res;
|
// }
|
// break;
|
// default:
|
// break;
|
// }
|
|
// res.resData = true;
|
// return res;
|
//}
|
//catch (Exception ex)
|
//{
|
// Log4NetHelper.WriteErrorLog(LogType.SdaService, "检测R01是否可以发任务 出现异常", ex);
|
// res.result = false;
|
// res.resMsg = "检测R01是否可以发任务 出现异常:" + ex.Message;
|
// return res;
|
//}
|
}
|
|
/// <summary>
|
/// 写入TaskFinish
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="rgvLocation"></param>
|
/// <returns></returns>
|
public SdaResEntity WriteTaskFinish(int deviceId, int rgvLocation)
|
{
|
SdaResEntity sdaResult = new SdaResEntity();
|
string msg;
|
try
|
{
|
var line = Line_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
|
if (line == null)
|
{
|
sdaResult.resMsg = nofoundStackerMsg;
|
return sdaResult;
|
}
|
LineLocation _rgv = (LineLocation)Enum.Parse(typeof(LineLocation), rgvLocation.ToString());
|
MessageModel fr = null;
|
switch (_rgv)
|
{
|
case LineLocation.RGV1:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T1_Finish, 1, line.View.W_T1_Finish);
|
break;
|
case LineLocation.RGV2:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T2_Finish, 1, line.View.W_T2_Finish);
|
break;
|
case LineLocation.RGV3:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T3_Finish, 1, line.View.W_T3_Finish);
|
break;
|
}
|
if (fr.result)
|
{
|
sdaResult.result = true;
|
return sdaResult;
|
}
|
else
|
{
|
sdaResult.resMsg = fr.resMsg;
|
return sdaResult;
|
}
|
}
|
catch (Exception ex)
|
{
|
msg = "写入Task_Finish_ACK出现异常:" + ex.Message;
|
Log4NetHelper.WriteErrorLog(LogType.LineSdaService, msg, ex);
|
sdaResult.result = false;
|
sdaResult.resMsg = msg;
|
return sdaResult;
|
}
|
}
|
|
|
/// <summary>
|
/// 写入 Die (是否有货)
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="rgvLocation"></param>
|
/// <returns></returns>
|
public SdaResEntity WriteDie(int deviceId, int rgvLocation, int dieValue)
|
{
|
SdaResEntity sdaResult = new SdaResEntity();
|
string msg;
|
try
|
{
|
var line = Line_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
|
if (line == null)
|
{
|
sdaResult.resMsg = nofoundStackerMsg;
|
return sdaResult;
|
}
|
LineLocation _rgv = (LineLocation)Enum.Parse(typeof(LineLocation), rgvLocation.ToString());
|
MessageModel fr = null;
|
switch (_rgv)
|
{
|
case LineLocation.RGV1:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T1_Die, dieValue, line.View.W_T1_Die);
|
break;
|
case LineLocation.RGV2:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T2_Die, dieValue, line.View.W_T2_Die);
|
break;
|
case LineLocation.RGV3:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T3_Die, dieValue, line.View.W_T3_Die);
|
break;
|
}
|
if (fr.result)
|
{
|
sdaResult.result = true;
|
return sdaResult;
|
}
|
else
|
{
|
sdaResult.resMsg = fr.resMsg;
|
return sdaResult;
|
}
|
}
|
catch (Exception ex)
|
{
|
msg = "写入 Die 出现异常:" + ex.Message;
|
Log4NetHelper.WriteErrorLog(LogType.LineSdaService, msg, ex);
|
sdaResult.result = false;
|
sdaResult.resMsg = msg;
|
return sdaResult;
|
}
|
}
|
|
|
/// <summary>
|
/// 写入 Stock (是否有库存)
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="rgvLocation"></param>
|
/// <returns></returns>
|
public SdaResEntity WriteStock(int deviceId, int rgvLocation, int stockValue)
|
{
|
SdaResEntity sdaResult = new SdaResEntity();
|
string msg;
|
try
|
{
|
var line = Line_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
|
if (line == null)
|
{
|
sdaResult.resMsg = nofoundStackerMsg;
|
return sdaResult;
|
}
|
LineLocation _rgv = (LineLocation)Enum.Parse(typeof(LineLocation), rgvLocation.ToString());
|
MessageModel fr = null;
|
switch (_rgv)
|
{
|
case LineLocation.RGV1:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T1_Stock, stockValue, line.View.W_T1_Stock);
|
break;
|
case LineLocation.RGV2:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T2_Stock, stockValue, line.View.W_T2_Stock);
|
break;
|
case LineLocation.RGV3:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T3_Stock, stockValue, line.View.W_T3_Stock);
|
break;
|
}
|
if (fr.result)
|
{
|
sdaResult.result = true;
|
return sdaResult;
|
}
|
else
|
{
|
sdaResult.resMsg = fr.resMsg;
|
return sdaResult;
|
}
|
}
|
catch (Exception ex)
|
{
|
msg = "写入 Stock 出现异常:" + ex.Message;
|
Log4NetHelper.WriteErrorLog(LogType.LineSdaService, msg, ex);
|
sdaResult.result = false;
|
sdaResult.resMsg = msg;
|
return sdaResult;
|
}
|
}
|
|
|
|
/// <summary>
|
/// 写入 request_ok (WCS确认标记)
|
/// </summary>
|
/// <param name="deviceId"></param>
|
/// <param name="rgvLocation"></param>
|
/// <returns></returns>
|
public SdaResEntity Write_Request_ok(int deviceId, int rgvLocation, bool value)
|
{
|
SdaResEntity sdaResult = new SdaResEntity();
|
string msg;
|
try
|
{
|
var line = Line_CacheEntity.DeviceObjs.FirstOrDefault(x => x.View.DeviceId == deviceId);
|
if (line == null)
|
{
|
sdaResult.resMsg = nofoundStackerMsg;
|
return sdaResult;
|
}
|
LineLocation _rgv = (LineLocation)Enum.Parse(typeof(LineLocation), rgvLocation.ToString());
|
MessageModel fr = null;
|
switch (_rgv)
|
{
|
case LineLocation.RGV1:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T1_request_ok, value, line.View.W_T1_request_ok);
|
break;
|
case LineLocation.RGV2:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T2_request_ok, value, line.View.W_T2_request_ok);
|
break;
|
case LineLocation.RGV3:
|
fr = line.plcService.WriteValuePoint(Line_CacheEntity.W_DBHeader, line.DBBlockForWrite.W_T3_request_ok, value, line.View.W_T3_request_ok);
|
break;
|
}
|
if (fr.result)
|
{
|
sdaResult.result = true;
|
return sdaResult;
|
}
|
else
|
{
|
sdaResult.resMsg = fr.resMsg;
|
return sdaResult;
|
}
|
}
|
catch (Exception ex)
|
{
|
msg = "写入 request_ok 出现异常:" + ex.Message;
|
Log4NetHelper.WriteErrorLog(LogType.LineSdaService, msg, ex);
|
sdaResult.result = false;
|
sdaResult.resMsg = msg;
|
return sdaResult;
|
}
|
}
|
|
|
}
|
}
|