|
@@ -62,12 +62,18 @@ namespace IMCS.CCS.Services
|
|
|
|
|
|
private readonly IApiRequestService _apiRequestService;
|
|
|
|
|
|
- // 装载站
|
|
|
+ // 物料装载站
|
|
|
private static Dictionary<string, string> shangLiaoQaingQiu = new Dictionary<string, string>();
|
|
|
private static Dictionary<string, string> xiaLiaoQaingQiu = new Dictionary<string, string>();
|
|
|
private static Dictionary<string, string> shangLiaoZhuangTai = new Dictionary<string, string>();
|
|
|
private static Dictionary<string, string> xiaLiaoZhuangTai = new Dictionary<string, string>();
|
|
|
|
|
|
+ // 刀具装载站
|
|
|
+ private static Dictionary<string, string> cutterPutRequest = new Dictionary<string, string>();
|
|
|
+ private static Dictionary<string, string> cutterTakeRequest = new Dictionary<string, string>();
|
|
|
+ private static Dictionary<string, string> cutterPutStatus = new Dictionary<string, string>();
|
|
|
+ private static Dictionary<string, string> cutterTakeStatus = new Dictionary<string, string>();
|
|
|
+
|
|
|
public HttpRequestService(IDeviceService deviceService, ITaskCallbackService taskCallbackService,
|
|
|
ICcsActionService ccsActionService, ICcsTagValueService ccsTagValueService,
|
|
|
IEquipmentMonitorService equipmentMonitorService, ICcsActionAddressService ccsActionAddressService,
|
|
@@ -106,6 +112,26 @@ namespace IMCS.CCS.Services
|
|
|
xiaLiaoZhuangTai.Add("LAUP000102", "DB1000.296.2");
|
|
|
}
|
|
|
|
|
|
+ if (cutterPutRequest.Count == 0)
|
|
|
+ {
|
|
|
+ cutterPutRequest.Add("LAUPT00101", "DB1001.788.1");
|
|
|
+ cutterPutRequest.Add("LAUPT00102", "DB1001.788.2");
|
|
|
+ }
|
|
|
+ if (cutterTakeRequest.Count == 0)
|
|
|
+ {
|
|
|
+ cutterTakeRequest.Add("LAUPT00101", "DB1001.786.1");
|
|
|
+ cutterTakeRequest.Add("LAUPT00102", "DB1001.786.2");
|
|
|
+ }
|
|
|
+ if (cutterPutStatus.Count == 0) {
|
|
|
+ cutterPutStatus.Add("LAUPT00101", "DB1000.322.1");
|
|
|
+ cutterPutStatus.Add("LAUPT00102", "DB1000.322.2");
|
|
|
+ }
|
|
|
+ if (cutterTakeStatus.Count == 0)
|
|
|
+ {
|
|
|
+ cutterTakeStatus.Add("LAUPT00101", "DB1000.324.1");
|
|
|
+ cutterTakeStatus.Add("LAUPT00102", "DB1000.324.2");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -348,7 +374,7 @@ namespace IMCS.CCS.Services
|
|
|
|
|
|
if (shangliaoqingqiu == "False" && xialiaoqingqiu == "False")
|
|
|
{
|
|
|
- s7.Write(xialiaoqingqiu, true);
|
|
|
+ s7.Write(xialiaoqingqiuDB, true);
|
|
|
s7.ConnectClose();
|
|
|
Log.Instance.WriteLogAdd(ActionTypeEnum.RobotAction + "====已发送下料请求,等待下料允许====" + JsonConvert.SerializeObject(req),
|
|
|
EnumHelper.GetDescription(ActionTypeEnum.RobotAction));
|
|
@@ -472,6 +498,8 @@ namespace IMCS.CCS.Services
|
|
|
/// <summary>
|
|
|
/// 天轨机器人取放动作
|
|
|
/// </summary>
|
|
|
+ ///
|
|
|
+
|
|
|
public async Task<ResponseECSData> CutterRobotAction(RequestData<CutterLocationData> req)
|
|
|
{
|
|
|
ResponseECSData responseData = new ResponseECSData(req.taskId, req.taskNodeId, "执行成功");
|
|
@@ -555,6 +583,102 @@ namespace IMCS.CCS.Services
|
|
|
}
|
|
|
// 检查出发地,目的地比对数据结束===
|
|
|
|
|
|
+
|
|
|
+ //=========================上下料站请求判断 开始======================
|
|
|
+ // 目标点位是上下料站的判断下料请求是否为true,上料请求为false,
|
|
|
+ // 如果不是判断上料请求是否为true,
|
|
|
+ // 是提示状态不对,否则写下料请求状态
|
|
|
+
|
|
|
+ // 上料料请求
|
|
|
+ if (cutterPutRequest.ContainsKey(req.data.DestLocation))
|
|
|
+ {
|
|
|
+ string shangliaoqingqiuDB = cutterPutRequest[req.data.DestLocation];
|
|
|
+ string xialiaoqingqiuDB = cutterTakeRequest[req.data.DestLocation];
|
|
|
+ string shangliaoyunxuDB = cutterPutStatus[req.data.DestLocation];
|
|
|
+ string xialiaoyunxuDB = cutterTakeStatus[req.data.DestLocation];
|
|
|
+
|
|
|
+ string shangliaoqingqiu = s7.ReadBool(shangliaoqingqiuDB).Content.ToString();
|
|
|
+ string xialiaoqingqiu = s7.ReadBool(xialiaoqingqiuDB).Content.ToString();
|
|
|
+ string shangliaoyunxu = s7.ReadBool(shangliaoyunxuDB).Content.ToString();
|
|
|
+ string xialiaoyunxu = s7.ReadBool(xialiaoyunxuDB).Content.ToString();
|
|
|
+
|
|
|
+ if (shangliaoqingqiu == "False" && xialiaoqingqiu == "False")
|
|
|
+ {
|
|
|
+ s7.Write(shangliaoqingqiuDB, true);
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterRobotAction + "====已发送上料请求,等待上料允许====" + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterRobotAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "已发送上料请求,等待上料允许";
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ else if (shangliaoqingqiu == "False" && xialiaoqingqiu == "True")
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterRobotAction + "====状态不对,现在下料请求状态,等待下料任务完成====" + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterRobotAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "已被下料请求占用,等待下料任务完成";
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ else if (shangliaoqingqiu == "True" && shangliaoyunxu == "False")
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterRobotAction + "====已经发送上料请求,上料允许状态不满足====" + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterRobotAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "已经发送上料请求,上料允许状态不满";
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下料允许
|
|
|
+ if (cutterTakeRequest.ContainsKey(req.data.Location))
|
|
|
+ {
|
|
|
+
|
|
|
+ string shangliaoqingqiuDB = cutterPutRequest[req.data.Location];
|
|
|
+ string xialiaoqingqiuDB = cutterTakeRequest[req.data.Location];
|
|
|
+ string shangliaoyunxuDB = cutterPutStatus[req.data.Location];
|
|
|
+ string xialiaoyunxuDB = cutterTakeStatus[req.data.Location];
|
|
|
+
|
|
|
+ string shangliaoqingqiu = s7.ReadBool(shangliaoqingqiuDB).Content.ToString();
|
|
|
+ string xialiaoqingqiu = s7.ReadBool(xialiaoqingqiuDB).Content.ToString();
|
|
|
+ string shangliaoyunxu = s7.ReadBool(shangliaoyunxuDB).Content.ToString();
|
|
|
+ string xialiaoyunxu = s7.ReadBool(xialiaoyunxuDB).Content.ToString();
|
|
|
+
|
|
|
+ if (shangliaoqingqiu == "False" && xialiaoqingqiu == "False")
|
|
|
+ {
|
|
|
+ s7.Write(xialiaoqingqiuDB, true);
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterRobotAction + "====已发送下料请求,等待下料允许====" + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterRobotAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "已发送下料请求,等待下料允许";
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ else if (shangliaoqingqiu == "True" && xialiaoqingqiu == "False")
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterRobotAction + "====状态不对,现在上料请求状态,等待上料任务完成====" + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterRobotAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "已被上料请求占用,等待上料任务完成";
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ else if (xialiaoqingqiu == "True" && xialiaoyunxu == "False")
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterRobotAction + "====已经发送下料请求,下料允许状态不满足====" + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterRobotAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "已经发送下料请求,下料允许状态不满足";
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //=========================上下料站请求判断 结束======================
|
|
|
+
|
|
|
+
|
|
|
// 查询需要操作的plc的db块
|
|
|
CcsActionAddress actionAddressQuery = new CcsActionAddress();
|
|
|
actionAddressQuery.ActionId = actionInfo.Id;
|
|
@@ -666,6 +790,146 @@ namespace IMCS.CCS.Services
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// CNC刀具库请求上下料动作
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="req"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<ResponseECSData> CutterDeviceTakeOrPutRequest(RequestData<CutterLocationData> req)
|
|
|
+ {
|
|
|
+ ResponseECSData responseData = new ResponseECSData(req.taskId, req.taskNodeId, "执行成功");
|
|
|
+ SiemensS7Net s7 = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ // 获取所有在线的设备
|
|
|
+ List<Device> devices = _deviceService.GetDeviceList();
|
|
|
+
|
|
|
+ // 比较在线设备是否在其中
|
|
|
+ Device device = devices.Where(x => x.Ip == req.url && x.Port == req.port).FirstOrDefault();
|
|
|
+
|
|
|
+ if (device == null)
|
|
|
+ {
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterCncDeviceAction + "设备已离线===>>" + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterCncDeviceAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "设备已离线:" + req.url;
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据ip查询设备
|
|
|
+ CcsAction actionQuery = new CcsAction();
|
|
|
+ actionQuery.OperateType = ActionTypeEnum.CutterCncDeviceAction.ToString();
|
|
|
+ actionQuery.Ip = req.url;
|
|
|
+ CcsAction actionInfo = _ccsActionService.GetList(actionQuery).FirstOrDefault();
|
|
|
+
|
|
|
+ // 进行plc的连接
|
|
|
+ s7 = DevicePlcS7.SiemensS7(actionInfo.Ip);
|
|
|
+ OperateResult ConnectionResult = s7.ConnectServer();
|
|
|
+ if (!ConnectionResult.IsSuccess)
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterCncDeviceAction + "异常===>>" + "PLC连接不上" + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterCncDeviceAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = ActionTypeEnum.CutterCncDeviceAction + "异常===>>" + "PLC连接不上" + JsonConvert.SerializeObject(req);
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询需要操作的plc的db块
|
|
|
+ CcsActionAddress actionAddressQuery = new CcsActionAddress();
|
|
|
+ actionAddressQuery.ActionId = actionInfo.Id;
|
|
|
+ List<CcsActionAddress> CcsActionAddresses = _ccsActionAddressService.GetList(actionAddressQuery);
|
|
|
+
|
|
|
+ //查询出需要检查的地址列表
|
|
|
+ List<CcsActionAddress> CcsActionAddressChecks = CcsActionAddresses.Where(o => o.Type == ActionAddressTypeEnum.CHECK.ToString()).ToList();
|
|
|
+ foreach (CcsActionAddress actionAddress in CcsActionAddressChecks)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(actionAddress.Address) && !string.IsNullOrEmpty(actionAddress.Value))
|
|
|
+ {
|
|
|
+ string operateResult = s7.ReadBool(actionAddress.Address).Content.ToString();
|
|
|
+ if (actionAddress.CheckType ? operateResult != actionAddress.Value : operateResult == actionAddress.Value)
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterCncDeviceAction + "异常===>>" + "条件不满足" + actionAddress.Address + "值应为:" + actionAddress.Value + "====实际为:" + operateResult + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterCncDeviceAction));
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "异常===>>" + "条件不满足" + actionAddress.Address + "值应为:" + actionAddress.Value + "==实际为:" + operateResult;
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询需要写入地址列表
|
|
|
+ List<CcsActionAddress> CcsActionAddressWrites = CcsActionAddresses.Where(o => o.Type == ActionAddressTypeEnum.WRITE.ToString()).ToList();
|
|
|
+ foreach (CcsActionAddress actionAddress in CcsActionAddressWrites)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(actionAddress.Address))
|
|
|
+ {
|
|
|
+ string parValue = "";
|
|
|
+ // 写入取放点位、需要进行点位拼接
|
|
|
+ if (actionAddress.Sort == 1)
|
|
|
+ {
|
|
|
+
|
|
|
+ string before = "EMPTY00000";
|
|
|
+ if (req.data.Location != null && req.data.Location.Length>0) {
|
|
|
+ before = "ATC00" + req.data.LocationNo + req.data.Location.Substring(7, 3);
|
|
|
+ }
|
|
|
+ string theTail = "EMPTY00000";
|
|
|
+ if (req.data.DestLocation != null && req.data.DestLocation.Length>0) {
|
|
|
+ theTail = "ATC00" + req.data.DestLocationNo + req.data.DestLocation.Substring(7, 3);
|
|
|
+ }
|
|
|
+ parValue = before + theTail;
|
|
|
+
|
|
|
+ s7.Write(actionAddress.Address, Convert.ToString(parValue));
|
|
|
+ }
|
|
|
+ else if (actionAddress.Sort == 2)
|
|
|
+ {
|
|
|
+ // 需要写入启动状态
|
|
|
+ parValue = actionAddress.Value;
|
|
|
+ s7.Write(actionAddress.Address, Convert.ToBoolean(parValue));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 同步TagValue数据状态
|
|
|
+ CcsTagValue tagValueQuery = new CcsTagValue();
|
|
|
+ tagValueQuery.Ip = req.url;
|
|
|
+ tagValueQuery.Address = actionAddress.Address;
|
|
|
+ CcsTagValue tagValue = _ccsTagValueService.GetList(tagValueQuery).ToList().FirstOrDefault();
|
|
|
+ if (tagValue != null)
|
|
|
+ {
|
|
|
+ tagValue.TagValue = parValue;
|
|
|
+ await _ccsTagValueService.Update(tagValue);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Thread.Sleep(SLEEP_TIME);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ s7.ConnectClose();
|
|
|
+
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ // 记录日志
|
|
|
+ Log.Instance.WriteLogAdd(ActionTypeEnum.CutterCncDeviceAction + "取放异常===>>" + ex.Message + JsonConvert.SerializeObject(req),
|
|
|
+ EnumHelper.GetDescription(ActionTypeEnum.CutterCncDeviceAction));
|
|
|
+ responseData.resultMsg = ActionTypeEnum.CutterCncDeviceAction + "取放异常===>>" + ex.Message + JsonConvert.SerializeObject(req);
|
|
|
+ responseData.result = "false";
|
|
|
+
|
|
|
+ // 关闭plc连接
|
|
|
+ if (s7 != null)
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ }
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
/// 上传文件
|
|
@@ -1724,6 +1988,214 @@ namespace IMCS.CCS.Services
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 查询刀具上下料站、机床刀具位是否允许取
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<ResponseECSData> getCutterDeviceIsTake(RequestData<RequestToolData> req)
|
|
|
+ {
|
|
|
+
|
|
|
+ Log.Instance.WriteLogAdd("查询刀具上下料站、机床刀具位是否允许取===>> " + JsonConvert.SerializeObject(req), "刀具取放状态");
|
|
|
+ // 1、根据url查询设备信息 2、调用httpserveer 发送执行消息
|
|
|
+
|
|
|
+ ResponseECSData responseData = new ResponseECSData(req.taskId, req.taskNodeId, "允许下料");
|
|
|
+ SiemensS7Net s7 = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 获取所有在线的设备
|
|
|
+ List<Device> devices = _deviceService.GetDeviceList();
|
|
|
+
|
|
|
+ // 比较在线设备是否在其中
|
|
|
+ Device device = devices.Where(x => x.Ip == req.url && x.Port == req.port).FirstOrDefault();
|
|
|
+
|
|
|
+ if (device == null)
|
|
|
+ {
|
|
|
+ Log.Instance.WriteLogAdd("CutterTake" + req.data.location + "设备已离线===>>" + JsonConvert.SerializeObject(req),
|
|
|
+ "刀具取放状态");
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "设备已离线:" + req.url;
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据ip查询配置的字节数据
|
|
|
+ CcsAction actionQuery = new CcsAction();
|
|
|
+ actionQuery.OperateType = "CutterTake" + req.data.location.ToString();
|
|
|
+ actionQuery.Ip = req.url;
|
|
|
+ CcsAction actionInfo = _ccsActionService.GetList(actionQuery).FirstOrDefault();
|
|
|
+
|
|
|
+ // 进行plc的连接
|
|
|
+ s7 = DevicePlcS7.SiemensS7(actionInfo.Ip);
|
|
|
+ OperateResult ConnectionResult = s7.ConnectServer();
|
|
|
+ if (!ConnectionResult.IsSuccess)
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd("CutterTake" + req.data.location + "异常===>>" + "PLC连接不上" + JsonConvert.SerializeObject(req),
|
|
|
+ "刀具取放状态");
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "CutterTake" + req.data.location + "异常===>>" + "PLC连接不上" + JsonConvert.SerializeObject(req);
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询需要操作的plc的db块
|
|
|
+ CcsActionAddress actionAddressQuery = new CcsActionAddress();
|
|
|
+ actionAddressQuery.ActionId = actionInfo.Id;
|
|
|
+ List<CcsActionAddress> CcsActionAddresses = _ccsActionAddressService.GetList(actionAddressQuery);
|
|
|
+
|
|
|
+ //查询出需要检查的地址列表
|
|
|
+ List<CcsActionAddress> CcsActionAddressChecks = CcsActionAddresses.Where(o => o.Type == ActionAddressTypeEnum.CHECK.ToString()).ToList();
|
|
|
+ foreach (CcsActionAddress actionAddress in CcsActionAddressChecks)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(actionAddress.Address) && !string.IsNullOrEmpty(actionAddress.Value))
|
|
|
+ {
|
|
|
+ string operateResult = "";
|
|
|
+ if (actionAddress.AddressType.Equals(TagValueReadTypeEnum.BOOL.ToString()))
|
|
|
+ {
|
|
|
+ operateResult = s7.ReadBool(actionAddress.Address).Content.ToString();
|
|
|
+ }
|
|
|
+ else if (actionAddress.AddressType.Equals(TagValueReadTypeEnum.SHORT.ToString()))
|
|
|
+ {
|
|
|
+ operateResult = s7.ReadInt16(actionAddress.Address).Content.ToString();
|
|
|
+ }
|
|
|
+ else if (actionAddress.AddressType.Equals(TagValueReadTypeEnum.String.ToString()))
|
|
|
+ {
|
|
|
+ operateResult = s7.ReadString(actionAddress.Address).Content.ToString();
|
|
|
+ }
|
|
|
+ else if (actionAddress.AddressType.Equals(TagValueReadTypeEnum.Byte.ToString()))
|
|
|
+ {
|
|
|
+ operateResult = s7.ReadByte(actionAddress.Address).Content.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (actionAddress.CheckType ? operateResult != actionAddress.Value : operateResult == actionAddress.Value)
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd("CutterTake" + req.data.location + "异常===>>" + "条件不满足" + actionAddress.Address + "值应为:" + actionAddress.Value + "====实际为:" + operateResult + JsonConvert.SerializeObject(req),
|
|
|
+ "刀具取放状态");
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "异常===>>" + "条件不满足" + actionAddress.Address + "值应为:" + actionAddress.Value + "==实际为:" + operateResult;
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ Log.Instance.WriteLogAdd("CutterTake" + req.data.location + "任务下发异常===>>" + ex.Message + JsonConvert.SerializeObject(req),
|
|
|
+ "刀具取放状态");
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = ex.Message;
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询刀具上下料站、机床刀具位是否允许放
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<ResponseECSData> getCutterDeviceIsPut(RequestData<RequestToolData> req)
|
|
|
+ {
|
|
|
+
|
|
|
+ Log.Instance.WriteLogAdd("查询刀具上下料站、机床刀具位是否允许放===>> " + JsonConvert.SerializeObject(req), "刀具取放状态");
|
|
|
+ // 1、根据url查询设备信息 2、调用httpserveer 发送执行消息
|
|
|
+
|
|
|
+ ResponseECSData responseData = new ResponseECSData(req.taskId, req.taskNodeId, "允许下料");
|
|
|
+ SiemensS7Net s7 = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 获取所有在线的设备
|
|
|
+ List<Device> devices = _deviceService.GetDeviceList();
|
|
|
+
|
|
|
+ // 比较在线设备是否在其中
|
|
|
+ Device device = devices.Where(x => x.Ip == req.url && x.Port == req.port).FirstOrDefault();
|
|
|
+
|
|
|
+ if (device == null)
|
|
|
+ {
|
|
|
+ Log.Instance.WriteLogAdd("CutterPut" + req.data.location + "设备已离线===>>" + JsonConvert.SerializeObject(req),
|
|
|
+ "刀具取放状态");
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "设备已离线:" + req.url;
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据ip查询配置的字节数据
|
|
|
+ CcsAction actionQuery = new CcsAction();
|
|
|
+ actionQuery.OperateType = "CutterPut" + req.data.location.ToString();
|
|
|
+ actionQuery.Ip = req.url;
|
|
|
+ CcsAction actionInfo = _ccsActionService.GetList(actionQuery).FirstOrDefault();
|
|
|
+
|
|
|
+ // 进行plc的连接
|
|
|
+ s7 = DevicePlcS7.SiemensS7(actionInfo.Ip);
|
|
|
+ OperateResult ConnectionResult = s7.ConnectServer();
|
|
|
+ if (!ConnectionResult.IsSuccess)
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd("CutterPut" + req.data.location + "异常===>>" + "PLC连接不上" + JsonConvert.SerializeObject(req),
|
|
|
+ "刀具取放状态");
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "CutterPut" + req.data.location + "异常===>>" + "PLC连接不上" + JsonConvert.SerializeObject(req);
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询需要操作的plc的db块
|
|
|
+ CcsActionAddress actionAddressQuery = new CcsActionAddress();
|
|
|
+ actionAddressQuery.ActionId = actionInfo.Id;
|
|
|
+ List<CcsActionAddress> CcsActionAddresses = _ccsActionAddressService.GetList(actionAddressQuery);
|
|
|
+
|
|
|
+ //查询出需要检查的地址列表
|
|
|
+ List<CcsActionAddress> CcsActionAddressChecks = CcsActionAddresses.Where(o => o.Type == ActionAddressTypeEnum.CHECK.ToString()).ToList();
|
|
|
+ foreach (CcsActionAddress actionAddress in CcsActionAddressChecks)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(actionAddress.Address) && !string.IsNullOrEmpty(actionAddress.Value))
|
|
|
+ {
|
|
|
+ string operateResult = "";
|
|
|
+ if (actionAddress.AddressType.Equals(TagValueReadTypeEnum.BOOL.ToString()))
|
|
|
+ {
|
|
|
+ operateResult = s7.ReadBool(actionAddress.Address).Content.ToString();
|
|
|
+ }
|
|
|
+ else if (actionAddress.AddressType.Equals(TagValueReadTypeEnum.SHORT.ToString()))
|
|
|
+ {
|
|
|
+ operateResult = s7.ReadInt16(actionAddress.Address).Content.ToString();
|
|
|
+ }
|
|
|
+ else if (actionAddress.AddressType.Equals(TagValueReadTypeEnum.String.ToString()))
|
|
|
+ {
|
|
|
+ operateResult = s7.ReadString(actionAddress.Address).Content.ToString();
|
|
|
+ }
|
|
|
+ else if (actionAddress.AddressType.Equals(TagValueReadTypeEnum.Byte.ToString()))
|
|
|
+ {
|
|
|
+ operateResult = s7.ReadByte(actionAddress.Address).Content.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (actionAddress.CheckType ? operateResult != actionAddress.Value : operateResult == actionAddress.Value)
|
|
|
+ {
|
|
|
+ s7.ConnectClose();
|
|
|
+ Log.Instance.WriteLogAdd("CutterPut" + req.data.location + "异常===>>" + "条件不满足" + actionAddress.Address + "值应为:" + actionAddress.Value + "====实际为:" + operateResult + JsonConvert.SerializeObject(req),
|
|
|
+ "刀具取放状态");
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = "异常===>>" + "条件不满足" + actionAddress.Address + "值应为:" + actionAddress.Value + "==实际为:" + operateResult;
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ Log.Instance.WriteLogAdd("CutterPut" + req.data.location + "任务下发异常===>>" + ex.Message + JsonConvert.SerializeObject(req),
|
|
|
+ "刀具取放状态");
|
|
|
+ responseData.result = "false";
|
|
|
+ responseData.resultMsg = ex.Message;
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|