using iWareSda.Common;
using System.Linq;
using iWareModel;
using System;
using System.Collections.Generic;
using System.Threading;
using iWareCommon.Utils;
using iWareCommon.Common.Globle;
using iWareCommon;
using iWareSda.Devices._3_Conveyer.ConveyerModel;
using Newtonsoft.Json;
using iWareSda.Model;
using Newtonsoft.Json.Linq;
namespace iWareSda
{
public class ConveyerEntity : IDevice
{
public ConveyerEntity()
{
}
#region OPC相关
///
/// 写的DB块
///
public ConveyerDBForWrite DBBlockForWrite { get; set; }
///
/// 读的DB块
///
public ConveyerDBForRead DBBlockForRead { get; set; }
///
/// 读取PLC实例
///
public PLCService plcService { get; set; }
///
/// 视图对象
///
public ConveyerView View { get; set; }
#endregion
///
/// 初始化数据
///
public void InitData()
{
}
public ConveyerEntity(string srmName, int deviceId, ConveyerDBForWrite _dbBlockForWrite, ConveyerDBForRead _dbBlockForRead, PLCService _plcService)
{
this.View = new ConveyerView();
this.View.DeviceName = srmName;
this.View.DeviceId = deviceId;
//集合赋值初始化
this.View.R_ConveyerForReadCommList = new List();
this.View.W_ConveyerForWriteCommList = new List();
for (int i = 0; i < WareSdaStruct.ConveyerStationList.Count; i++)
{
this.View.R_ConveyerForReadCommList.Add(new ConveyerDB2ObjForReadComm() { StationCode = WareSdaStruct.ConveyerStationList[i] });
this.View.W_ConveyerForWriteCommList.Add(new ConveyerDB2ObjForWriteComm() { StationCode = WareSdaStruct.ConveyerStationList[i] });
}
plcService = _plcService;
DBBlockForWrite = _dbBlockForWrite;
DBBlockForRead = _dbBlockForRead;
}
#region 个性化方法
///
/// Conveyer任务发送
///
///
///
///
///
///
///
///
public bool SendTask(int deviceId, int taskId, string sourcePlce, string toPlace, string containertype, string taskType, out string msg)
{
try
{
msg = "";
if (!CanSendTask(deviceId, out msg))
{
return false;
}
//这里特殊转换一下
if (toPlace == ((int)EDevice.出库口1012).ToString())
{
toPlace = ((int)EDevice.提升机1030).ToString();
}
ConveyerDBForWriteComm w_db_source = this.DBBlockForWrite.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == sourcePlce);
ConveyerDBForReadComm w_de_read = this.DBBlockForRead.R_ConveyerForReadCommList.FirstOrDefault(x => x.StationCode == sourcePlce);
ConveyerDB2ObjForWriteComm w_dbObj_source = this.View.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == sourcePlce);
//ConveyerDBForWriteComm w_db_to = this.DBBlockForWrite.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == toPlace);
//ConveyerDB2ObjForWriteComm w_dbObj_to = this.View.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == toPlace);
//如果ACK为true,表示不能发任务
var readObj = this.View.R_ConveyerForReadCommList.FirstOrDefault(x => x.StationCode == sourcePlce);
//if (readObj.R_ACK == true)
//{
// msg = "ACK为TRUE,不允许发任务";
// return false;
//}
MessageModel b2 = this.plcService.WriteValuePoint(w_db_source.W_Destination, Convert.ToInt16(toPlace), w_dbObj_source.W_Destination);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1}发送任务{2},写入目标站点{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, taskId, toPlace);
return false;
}
b2 = this.plcService.WriteValuePoint(w_db_source.W_Source, Convert.ToInt16(sourcePlce), w_dbObj_source.W_Source);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入任务号{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, taskId);
return false;
}
b2 = this.plcService.WriteValuePoint(w_db_source.W_TaskID, Convert.ToInt32(taskId), w_dbObj_source.W_TaskID);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入任务号{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, taskId);
return false;
}
b2 = this.plcService.WriteValuePoint(w_db_source.W_SalverType, Convert.ToInt16(containertype), w_dbObj_source.W_SalverType);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入容器类型{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, true);
return false;
}
b2 = this.plcService.WriteValuePoint(w_db_source.W_TaskType, Convert.ToInt16(taskType), w_dbObj_source.W_TaskType);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入任务类型{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, true);
return false;
}
int flag = 0;
//下发完再读取一遍
short newtoplace = Convert.ToInt16(this.plcService.ReadValuePoint(w_db_source.W_Destination, typeof(short)));
if (Convert.ToInt16(toPlace) != newtoplace)
{
msg = string.Format("目标位置下发值与读取值不一致");
//return false;
flag = 1;
}
short newsourcePlce = Convert.ToInt16(this.plcService.ReadValuePoint(w_db_source.W_Source, typeof(short)));
if (Convert.ToInt16(sourcePlce) != newsourcePlce)
{
msg = string.Format("起始位置下发值与读取值不一致");
//return false;
flag = 1;
}
int newtaskid = Convert.ToInt32(this.plcService.ReadValuePoint(w_db_source.W_TaskID, typeof(int)));
if (Convert.ToInt32(taskId) != newtaskid)
{
msg = string.Format("任务号下发值与读取值不一致");
//return false;
flag = 1;
}
short newW_SalverType = Convert.ToInt16(this.plcService.ReadValuePoint(w_db_source.W_SalverType, typeof(short)));
if (Convert.ToInt16(containertype) != newW_SalverType)
{
msg = string.Format("托盘高度下发值与读取值不一致");
//return false;
flag = 1;
}
short new_taskType = Convert.ToInt16(this.plcService.ReadValuePoint(w_db_source.W_TaskType, typeof(short)));
if (Convert.ToInt16(taskType) != new_taskType)
{
msg = string.Format("任务类型下发值与读取值不一致");
//return false;
flag = 1;
}
if (flag == 1)
{
//清除所有信号
b2 = this.plcService.WriteValuePoint(w_db_source.W_Destination, Convert.ToInt16(0), w_dbObj_source.W_Destination);
b2 = this.plcService.WriteValuePoint(w_db_source.W_Source, Convert.ToInt16(0), w_dbObj_source.W_Source);
b2 = this.plcService.WriteValuePoint(w_db_source.W_TaskID, Convert.ToInt32(0), w_dbObj_source.W_TaskID);
b2 = this.plcService.WriteValuePoint(w_db_source.W_SalverType, Convert.ToInt16(0), w_dbObj_source.W_SalverType);
b2 = this.plcService.WriteValuePoint(w_db_source.W_TaskType, Convert.ToInt16(0), w_dbObj_source.W_TaskType);
return false;
}
//将STP改为TRUE
b2 = this.plcService.WriteValuePoint(w_db_source.W_STP, true, w_dbObj_source.W_STP);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入STP{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, true);
return false;
}
bool b = Convert.ToBoolean(this.plcService.ReadValuePoint(w_db_source.W_STP, typeof(bool)));
if (b != true)
{
msg = string.Format("STP下发值与读取值不一致");
//清除所有信号
b2 = this.plcService.WriteValuePoint(w_db_source.W_Destination, Convert.ToInt16(0), w_dbObj_source.W_Destination);
b2 = this.plcService.WriteValuePoint(w_db_source.W_Source, Convert.ToInt16(0), w_dbObj_source.W_Source);
b2 = this.plcService.WriteValuePoint(w_db_source.W_TaskID, Convert.ToInt32(0), w_dbObj_source.W_TaskID);
b2 = this.plcService.WriteValuePoint(w_db_source.W_SalverType, Convert.ToInt16(0), w_dbObj_source.W_SalverType);
b2 = this.plcService.WriteValuePoint(w_db_source.W_TaskType, Convert.ToInt16(0), w_dbObj_source.W_TaskType);
b2 = this.plcService.WriteValuePoint(w_db_source.W_STP, false, w_dbObj_source.W_STP);
return false;
}
return true;
}
catch (Exception ex)
{
msg = ex.Message;
Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, "发送任务出现异常:" + ex.Message, ex);
return false;
}
}
///
/// Conveyer任务发送
///
///
///
///
///
///
///
///
public bool ClearTask(int deviceId, int taskId, string sourcePlce, string toPlace, string containertype, string taskType, out string msg)
{
try
{
msg = "";
if (!CanSendTask(deviceId, out msg))
{
return false;
}
//这里特殊转换一下
if (toPlace == ((int)EDevice.出库口1012).ToString())
{
toPlace = ((int)EDevice.提升机1030).ToString();
}
ConveyerDBForWriteComm w_db_source = this.DBBlockForWrite.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == sourcePlce);
ConveyerDB2ObjForWriteComm w_dbObj_source = this.View.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == sourcePlce);
//ConveyerDBForWriteComm w_db_to = this.DBBlockForWrite.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == toPlace);
//ConveyerDB2ObjForWriteComm w_dbObj_to = this.View.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == toPlace);
//如果ACK为true,表示不能发任务
var readObj = this.View.R_ConveyerForReadCommList.FirstOrDefault(x => x.StationCode == sourcePlce);
//if (readObj.R_ACK == true)
//{
// msg = "ACK为TRUE,不允许发任务";
// return false;
//}
MessageModel b2 = this.plcService.WriteValuePoint(w_db_source.W_Destination, 0, w_dbObj_source.W_Destination);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1}发送任务{2},写入目标站点{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, taskId, toPlace);
return false;
}
b2 = this.plcService.WriteValuePoint(w_db_source.W_Source, 0, w_dbObj_source.W_Source);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入任务号{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, taskId);
return false;
}
b2 = this.plcService.WriteValuePoint(w_db_source.W_TaskID, 0, w_dbObj_source.W_TaskID);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入任务号{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, taskId);
return false;
}
b2 = this.plcService.WriteValuePoint(w_db_source.W_SalverType, 0, w_dbObj_source.W_SalverType);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入容器类型{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, true);
return false;
}
b2 = this.plcService.WriteValuePoint(w_db_source.W_TaskType, 0, w_dbObj_source.W_TaskType);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},起点{1},目标点{2},写入任务类型{3}失败,返回结果:" + b2.resMsg, this.View.DeviceName, sourcePlce, toPlace, true);
return false;
}
return true;
}
catch (Exception ex)
{
msg = ex.Message;
Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, "发送任务出现异常:" + ex.Message, ex);
return false;
}
}
///
/// 任务下发确认(收到PLC反馈后WCS清除)
///
///
///
///
public bool WriteStp(int deviceId, string stationCode, bool value, out string msg)
{
try
{
msg = "";
ConveyerDBForWriteComm w_db = this.DBBlockForWrite.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == stationCode);
ConveyerDB2ObjForWriteComm w_dbObj = this.View.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == stationCode);
MessageModel b2 = this.plcService.WriteValuePoint(w_db.W_STP, value, w_dbObj.W_STP);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},站点号{1}写 任务下发确认(收到PLC反馈后WCS清除) " + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, stationCode);
return false;
}
return true;
}
catch (Exception ex)
{
msg = ex.Message;
var logcontext = string.Format("向Conveyer{0},站点号{1}写 任务下发确认(收到PLC反馈后WCS清除) " + true + "出现异常:" + JsonConvert.SerializeObject(ex),
deviceId, stationCode);
Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, logcontext, ex);
return false;
}
}
///
/// 1015重新扫码
///
///
///
///
///
public bool Write1015ReScan(int deviceId, bool value, out string msg)
{
msg = "";
return false;
//try
//{
// msg = "";
// MessageModel b2 = this.plcService.WriteValuePoint(this.DBBlockForWrite.W_1015_ReScan, value, this.View.W_1015_ReScan);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer地址{0} 写 " + value + "失败,返回结果:" + b2.resMsg,
// this.DBBlockForWrite.W_1015_ReScan);
// return false;
// }
// return true;
//}
//catch (Exception ex)
//{
// msg = ex.Message;
// var logcontext = string.Format("向Conveyer地址{0} " + value + "出现异常:" + JsonConvert.SerializeObject(ex),
// this.DBBlockForWrite.W_1015_ReScan);
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, logcontext, ex);
// return false;
//}
}
///
/// 101扫码接受完成
///
///
///
///
///
public bool Write101Scan(int deviceId, bool value, out string msg)
{
try
{
msg = "";
MessageModel b2 = this.plcService.WriteValuePoint(this.DBBlockForWrite.W_Scan1_ReceiveFinish, value, this.View.W_Scan1_ReceiveFinish);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},站点号{1}写 任务下发确认(收到PLC反馈后WCS清除) " + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, "101");
return false;
}
return true;
}
catch (Exception ex)
{
msg = ex.Message;
var logcontext = string.Format("向Conveyer{0},站点号{1}写 任务下发确认(收到PLC反馈后WCS清除) " + true + "出现异常:" + JsonConvert.SerializeObject(ex),
deviceId, "101");
Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, logcontext, ex);
return false;
}
}
///
/// Conveyer的任务完成ACK赋值
///
///
///
///
///
public bool WriteConveyer_FinishACK(int deviceId, bool value, int plcTaskId, string stationCode, out string msg)
{
try
{
msg = "";
ConveyerDBForWriteComm w_db = this.DBBlockForWrite.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == stationCode);
ConveyerDB2ObjForWriteComm w_dbObj = this.View.W_ConveyerForWriteCommList.FirstOrDefault(x => x.StationCode == stationCode);
MessageModel b2 = this.plcService.WriteValuePoint(w_db.W_ConfirmTaskFinish, value, w_dbObj.W_ConfirmTaskFinish);
if (!b2.result && !value)
{
msg = string.Format("向Conveyer{0},站点号{1}写 任务完成确认(收到PLC反馈后WCS清除) " + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, stationCode);
return false;
}
else if (!b2.result && value)
{
msg = string.Format("向Conveyer{0},站点号{1}写 任务完成确认 " + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, stationCode);
return false;
}
return true;
}
catch (Exception ex)
{
msg = ex.Message;
var logcontext = string.Format("向Conveyer{0},站点号{1}写 任务下发确认(收到PLC反馈后WCS清除) " + true + "出现异常:" + JsonConvert.SerializeObject(ex),
deviceId, stationCode);
Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, logcontext, ex);
return false;
}
}
///
/// 四个入库口扫描验证ACK赋值
///
///
///
///
///
public bool WriteScanValidateACK(bool isReset, int deviceId, string stationCode, bool value, int plcTaskId, out string msg)
{
msg = "";
return false;
//MessageModel b2 = null;
//string address_fail = "";
//string address_success = "";
//try
//{
// switch (stationCode)
// {
// case "1002":
// address_fail = this.DBBlockForWrite.W_1002_ScanFailACK;
// address_success = this.DBBlockForWrite.W_1002_ScanSuccessACK;
// break;
// case "1004":
// address_fail = this.DBBlockForWrite.W_1004_ScanFailACK;
// address_success = this.DBBlockForWrite.W_1004_ScanSuccessACK;
// break;
// case "1006":
// address_fail = this.DBBlockForWrite.W_1006_ScanFailACK;
// address_success = this.DBBlockForWrite.W_1006_ScanSuccessACK;
// break;
// case "1007":
// address_fail = this.DBBlockForWrite.W_1007_ScanFailACK;
// address_success = this.DBBlockForWrite.W_1007_ScanSuccessACK;
// break;
// default:
// throw new Exception("不支持的站点");
// }
// if (isReset)
// {//是重置
// b2 = this.plcService.WriteValuePoint(address_success, false, this.View.W_1002_ScanSuccessACK);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer地址{0} 写 " + false + "失败,返回结果:" + b2.resMsg,
// address_success);
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, msg, null);
// return false;
// }
// b2 = this.plcService.WriteValuePoint(address_fail, false, this.View.W_1002_ScanFailACK);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer地址{0} 写 " + false + "失败,返回结果:" + b2.resMsg,
// address_fail);
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, msg, null);
// return false;
// }
// }
// else
// {//不是重置
// if (value)
// {//表示扫描验证通过
// b2 = this.plcService.WriteValuePoint(address_success, true, this.View.W_1002_ScanSuccessACK);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer地址{0} 写 " + true + "失败,返回结果:" + b2.resMsg,
// address_success);
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, msg, null);
// return false;
// }
// }
// else
// {//表示扫描验证不通过
// b2 = this.plcService.WriteValuePoint(address_fail, true, this.View.W_1002_ScanFailACK);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer地址{0} 写 " + true + "失败,返回结果:" + b2.resMsg,
// address_fail);
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, msg, null);
// return false;
// }
// }
// }
// Log4NetHelper.WriteInfoLog(Conveyer_CacheEntity.curLogType, "WriteScanFailACK方法,写入 四个入库口扫描失败ACK赋值 ScanFailACK(" + address_fail + ")值为" + value + "成功!因为PLC任务号:" + plcTaskId + ",isReset:" + isReset);
// return true;
//}
//catch (Exception ex)
//{
// msg = ex.Message;
// var logcontext = string.Format("WriteScanFailACK方法,向Conveyer地址{0} " + value + "出现异常:" + JsonConvert.SerializeObject(ex),
// address_fail);
// if (value)
// {
// logcontext = string.Format("WriteScanFailACK方法,向Conveyer地址{0} " + value + "出现异常:" + JsonConvert.SerializeObject(ex),
// address_success);
// }
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, logcontext, ex);
// return false;
//}
}
///
/// 取消报警
///
///
///
///
public bool ClearAlarm(int deviceId, out string msg)
{
msg = "";
return true;
//try
//{
// msg = "";
// var dbNumber = Conveyer_CacheEntity.W_DBHeader;
// MessageModel b2 = this.plcService.WriteValuePoint( this.DBBlockForWrite.W_Reset, true, this.View.W_Reset);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer{0}写入设备复位" + true + "失败,返回结果:" + b2.resMsg, this.View.DeviceName);
// return false;
// }
// return true;
//}
//catch (Exception ex)
//{
// msg = ex.Message;
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, "取消报警出现异常:" + ex.Message, ex);
// return false;
//}
}
///
/// 任务删除
///
///
///
///
///
public bool DeleteTask(int deviceId, int taskId, out string msg)
{
msg = "";
return true;
//try
//{
// msg = "";
// if (this.View.R_TaskNo != taskId)
// {
// msg = string.Format("Conveyer当前非执行taskId={0}的任务", taskId);
// return false;
// }
// var dbNumber = Conveyer_CacheEntity.W_DBHeader;
// MessageModel b2 = this.plcService.WriteValuePoint( this.DBBlockForWrite.W_TaskNo, taskId, this.View.W_TaskNo);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer{0}写入任务号" + taskId + "失败,返回结果:" + b2.resMsg, this.View.DeviceName);
// return false;
// }
// b2 = this.plcService.WriteValuePoint( this.DBBlockForWrite.W_Reset, 1, this.View.W_Reset);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer{0}写入设备复位" + 1 + "失败,返回结果:" + b2.resMsg, this.View.DeviceName);
// return false;
// }
// return true;
//}
//catch (Exception ex)
//{
// msg = ex.Message;
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, "任务删除出现异常:" + ex.Message, ex);
// return false;
//}
}
///
/// 急停
///
///
///
///
public bool EmergencyStop(int deviceId, string stationCode, out string msg)
{
msg = "";
return true;
//try
//{
// msg = "";
// var dbNumber = Conveyer_CacheEntity.W_DBHeader;
// MessageModel b2 = this.plcService.WriteValuePoint( this.DBBlockForWrite.W_ConveyerForWriteCommList.Find(x => x.StationCode == stationCode)., 1, this.View.W_EStop);
// if (!b2.result)
// {
// msg = string.Format("向Conveyer{0}写入急停" + 1 + "失败,返回结果:" + b2.resMsg, this.View.DeviceName);
// return false;
// }
// return true;
//}
//catch (Exception ex)
//{
// msg = ex.Message;
// Log4NetHelper.WriteErrorLog(Conveyer_CacheEntity.curLogType, "急停出现异常:" + ex.Message, ex);
// return false;
//}
}
///
/// 是否可以发送任务
///
///
///
///
///
public bool CanSendTask(int deviceId, out string msg)
{
msg = "";
//模拟
//if (!this.View.IsConnected)
//{
// msg = "已离线";
// return false;
//}
//if (this.View.R_Mode != (int)EConveyerMode.连机自动模式)
//{
// msg = "当前非自动模式";
// return false;
//}
//if (this.View.R_State != (int)EConveyerState.空闲)
//{
// msg = "设备状态非空闲,无法执行其他任务";
// return false;
//}
return true;
}
///
/// Conveyer是否是自动待机模式
///
///
///
public bool ConveyerIsAutoAwaitMode(string stationCode, out string msg)
{
msg = "";
var readData = this.View;
if (readData.R_Mode_Auto == false)
{
msg = "站点" + stationCode + " 当前模式是非自动待机模式";
return false;
}
return true;
}
///
/// Conveyer是否是自动模式
///
///
///
public bool ConveyerIsAuto(string stationCode, out string msg)
{
msg = "";
var readData = this.View;
if (readData.R_Mode_Auto == false)
{
msg = "站点" + stationCode + " 当前模式是非自动模式";
return false;
}
return true;
}
///
/// Conveyer是否是空闲状态
///
///
///
public bool ConveyerIsStateFree(string stationCode, out string msg)
{
msg = "";
var readData = this.View.R_ConveyerForReadCommList.Where(x => x.StationCode == stationCode).FirstOrDefault();
//if (readData.R_State != (int)EConveyerState.空闲)
//{
// EConveyerMode mode = (EConveyerMode)Enum.Parse(typeof(EConveyerMode), readData.R_Model.ToString());
// msg = "站点" + stationCode + " 当前状态是[" + mode.ToString() + "],非空闲";
// return false;
//}
return true;
}
#endregion
public void SetPropertyValueForRead()
{
var r_dbBlock = this.DBBlockForRead;
SdaHelper.SetPropertyValueForDB(r_dbBlock, this.View, this.plcService, "");
//特殊处理List集合
foreach (var item in r_dbBlock.R_ConveyerForReadCommList)
{
ConveyerDB2ObjForReadComm ConveyerDB2ObjForReadComm = this.View.R_ConveyerForReadCommList.Where(x => x.StationCode == item.StationCode).First();
SdaHelper.SetPropertyValueForDB(item, ConveyerDB2ObjForReadComm, this.plcService, "");
}
}
public void SetPropertyValueForWrite()
{
var w_dbBlock = this.DBBlockForWrite;
SdaHelper.SetPropertyValueForDB(w_dbBlock, this.View, this.plcService, "");
//特殊处理List集合
foreach (var item in w_dbBlock.W_ConveyerForWriteCommList)
{
ConveyerDB2ObjForWriteComm ConveyerDB2ObjForWriteComm = this.View.W_ConveyerForWriteCommList.Where(x => x.StationCode == item.StationCode).First();
SdaHelper.SetPropertyValueForDB(item, ConveyerDB2ObjForWriteComm, this.plcService, "");
}
}
///
/// 是否有心跳
///
///
public bool IsHaveHeatBeat()
{
try
{
var r_dbBlock = this.DBBlockForRead;
short value = Convert.ToInt16(this.plcService.ReadValuePoint(r_dbBlock.R_HandShake, typeof(short)));
//约定 等待2秒
Thread.Sleep(2000);
short value_next = Convert.ToInt16(this.plcService.ReadValuePoint(r_dbBlock.R_HandShake, typeof(short)));
if (value == value_next)
{//没有心跳
return false;
}
else
{//有心跳
return true;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// AGV请求进
///
///
public bool AGVRequestIN(bool value, out string msg)
{
try
{
MessageModel b2 = this.plcService.WriteValuePoint(this.DBBlockForWrite.W_AGV_RequestIn, value, this.View.W_AGV_RequestIn);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},写AGV请求进入" + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, "101");
return false;
}
var result = Convert.ToBoolean(this.plcService.ReadValuePoint(this.DBBlockForWrite.W_AGV_RequestIn, typeof(bool)));
if (result == value)
{
msg = "成功";
return true;
}
else
{
msg = "失败";
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// AGV请求进
///
///
public bool AGVRequestINARR(bool value, out string msg)
{
try
{
MessageModel b2 = this.plcService.WriteValuePoint(this.DBBlockForWrite.W_AGV_RequestInArr, value, this.View.W_AGV_RequestInArr);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},写AGV请求进入到位" + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, "101");
return false;
}
var result = Convert.ToBoolean(this.plcService.ReadValuePoint(this.DBBlockForWrite.W_AGV_RequestInArr, typeof(bool)));
if (result == value)
{
msg = "成功";
return true;
}
else
{
msg = "失败";
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// AGV请求进
///
///
public bool AGVRequestOUT(bool value, out string msg)
{
try
{
MessageModel b2 = this.plcService.WriteValuePoint(this.DBBlockForWrite.W_AGV_RequestOut, value, this.View.W_AGV_RequestOut);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},写AGV请求进入" + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, "101");
return false;
}
var result = Convert.ToBoolean(this.plcService.ReadValuePoint(this.DBBlockForWrite.W_AGV_RequestOut, typeof(bool)));
if (value == result)
{
msg = "成功";
return true;
}
else
{
msg = "失败";
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// AGV请求进
///
///
public bool AGVRequestOUTARR(bool value, out string msg)
{
try
{
MessageModel b2 = this.plcService.WriteValuePoint(this.DBBlockForWrite.W_AGV_RequestOutArr, value, this.View.W_AGV_RequestOutArr);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},写AGV请求进入" + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, "101");
return false;
}
var result = Convert.ToBoolean(this.plcService.ReadValuePoint(this.DBBlockForWrite.W_AGV_RequestOutArr, typeof(bool)));
if (result == value)
{
msg = "成功";
return true;
}
else
{
msg = "失败";
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// AGV请求进
///
///
public bool AGVTaskType(short value, out string msg)
{
try
{
MessageModel b2 = this.plcService.WriteValuePoint(this.DBBlockForWrite.W_AGV_TaskType, value, this.View.W_AGV_TaskType);
if (!b2.result)
{
msg = string.Format("向Conveyer{0},写AGV任务类型" + value + "失败,返回结果:" + b2.resMsg,
this.View.DeviceName, "101");
return false;
}
//读取
var result = Convert.ToInt16(this.plcService.ReadValuePoint(this.DBBlockForWrite.W_AGV_TaskType, typeof(short)));
if (result == value)
{
msg = "成功";
return true;
}
else
{
msg = "失败";
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 读取bool值
///
///
public bool Read(string address)
{
try
{
bool b2 = (bool)this.plcService.ReadValuePoint(address, typeof(bool));
return b2;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 读取bool值
///
///
public string ReadStr(string address)
{
try
{
string b2 = (string)this.plcService.ReadValuePoint(address, typeof(string));
return b2;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 读取bool值
///
///
public short ReadShort(string address)
{
try
{
short b2 = Convert.ToInt16(this.plcService.ReadValuePoint(address, typeof(short)));
return b2;
}
catch (Exception ex)
{
throw ex;
}
}
#region 获取当前报警信息
///
/// 获取Conveyer当前报警信息
///
///
public List GetConveyerAlertDatas()
{
List db_warningList = new List();
try
{
string _dbValue;
var isHasAlert = false;
IDictionary ConveyerAlertDict = new Dictionary();
ConveyerAlertDict = WareSdaStruct.ConveyerAlertDict;
foreach (var item in ConveyerAlertDict)
{
_dbValue = item.Key;
isHasAlert = Convert.ToBoolean(this.plcService.ReadValuePoint(Conveyer_CacheEntity.R_DBHeader_Conveyer_Alert, item.Key, typeof(bool)));
if (isHasAlert)
{
db_warningList.Add(new DeviceWarningInfo()
{
Address = item.Key,
Code = item.Key,
Context = item.Value.Trim()
});
}
}
}
catch (Exception ex)
{
throw ex;
}
return db_warningList;
}
///
/// 获取输送线当前报警信息
///
///
public List GetLineAlertDatas()
{
List db_warningList = new List();
try
{
IDictionary srmAlertDict = new Dictionary();
foreach (var item in this.View.R_ConveyerForReadCommList)
{
//if (item.r_mo > 0)
//{
// item.R_AlarmCodeMsg = WareSdaStruct.ConveyerAlertDict[item.R_AlarmCode.ToString()];
//}
}
}
catch (Exception ex)
{
throw ex;
}
return db_warningList;
}
#endregion
}
}