#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_TaskInfoService
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using Autofac.Core;
|
using AutoMapper;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.Extensions.DependencyInjection;
|
using NetTaste;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Diagnostics;
|
using System.Diagnostics.CodeAnalysis;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Net;
|
using System.Reflection;
|
using System.Reflection.Metadata;
|
using System.Security.Claims;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Comm.Http;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_Core.Enums;
|
using WIDESEAWCS_DTO.Enum;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_ISystemServices;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob.Models;
|
using WIDESEAWCS_QuartzJob.Service;
|
|
namespace WIDESEAWCS_TaskInfoService
|
{
|
public class RgvoperainformService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvoperainformService
|
{
|
private readonly IAgvStationService _gvStationService;
|
private readonly IServiceProvider _serviceProvider;
|
private static bool _isMonitoring = false;
|
//private static CancellationTokenSource _cancellationTokenSource;
|
|
// 在类级别添加独立的监控状态
|
private bool _isOutboundMonitoring = false;
|
private bool _isInboundMonitoring = false;
|
private bool _isSafetyDoorMonitoring = false;
|
|
private CancellationTokenSource _outboundCancellationTokenSource;
|
private CancellationTokenSource _inboundCancellationTokenSource;
|
private CancellationTokenSource _safetyDoorCancellationTokenSource;
|
public RgvoperainformService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, IServiceProvider serviceProvider) : base(BaseDal)
|
{
|
_gvStationService = agvStationService;
|
_serviceProvider = serviceProvider;
|
}
|
|
|
//=================================================读取设备信息==========================================================
|
|
|
|
|
|
/// <summary>
|
/// 获取设备状态(支持出库、入库和安全门独立监控)
|
/// </summary>
|
/// <param name="off">0:停止 1:启动 2:仅查询</param>
|
/// <param name="monitorType">监控类型:outbound-出库 inbound-入库 safetydoor-安全门 all-全部</param>
|
/// <returns></returns>
|
public WebResponseContent GetDeviceStatusDto(int off, string monitorType = "outbound")
|
{
|
bool isOutbound = monitorType == "outbound" || monitorType == "all";//出库
|
bool isInbound = monitorType == "inbound" || monitorType == "all";//入库
|
bool isSafetyDoor = monitorType == "safetydoor" || monitorType == "all";//安全门
|
|
if (off == 1)
|
{
|
// 启动监控
|
if (isOutbound && !_isOutboundMonitoring)
|
{
|
_isOutboundMonitoring = true;
|
_outboundCancellationTokenSource = new CancellationTokenSource();
|
_ = Task.Run(async () => await StartDeviceMonitoring(_outboundCancellationTokenSource.Token, "outbound"));
|
}
|
|
if (isInbound && !_isInboundMonitoring)
|
{
|
_isInboundMonitoring = true;
|
_inboundCancellationTokenSource = new CancellationTokenSource();
|
_ = Task.Run(async () => await StartDeviceMonitoring(_inboundCancellationTokenSource.Token, "inbound"));
|
}
|
|
if (isSafetyDoor && !_isSafetyDoorMonitoring)
|
{
|
_isSafetyDoorMonitoring = true;
|
_safetyDoorCancellationTokenSource = new CancellationTokenSource();
|
_ = Task.Run(async () => await StartDeviceMonitoring(_safetyDoorCancellationTokenSource.Token, "safetydoor"));
|
}
|
|
var immediateData = GetImmediateDeviceData(monitorType);
|
string message = GetMonitorStatusMessage(monitorType);
|
return WebResponseContent.Instance.OK($"设备状态监控已启动 - {message}", immediateData);
|
}
|
else if (off == 0)
|
{
|
// 停止监控
|
if (isOutbound && _isOutboundMonitoring)
|
{
|
_isOutboundMonitoring = false;
|
_outboundCancellationTokenSource?.Cancel();
|
}
|
|
if (isInbound && _isInboundMonitoring)
|
{
|
_isInboundMonitoring = false;
|
_inboundCancellationTokenSource?.Cancel();
|
}
|
|
if (isSafetyDoor && _isSafetyDoorMonitoring)
|
{
|
_isSafetyDoorMonitoring = false;
|
_safetyDoorCancellationTokenSource?.Cancel();
|
}
|
|
var finalData = GetImmediateDeviceData(monitorType);
|
string message = GetMonitorStatusMessage(monitorType);
|
return WebResponseContent.Instance.OK($"设备状态监控已停止 - {message}", finalData);
|
}
|
else
|
{
|
// 返回当前数据
|
var currentData = GetImmediateDeviceData(monitorType);
|
string message = GetMonitorStatusMessage(monitorType);
|
return WebResponseContent.Instance.OK($"设备状态监控当前状态 - {message}", currentData);
|
}
|
}
|
|
/// <summary>
|
/// 启动设备监控
|
/// </summary>
|
/// <param name="cancellationToken"></param>
|
/// <param name="monitorType">监控类型</param>
|
/// <returns></returns>
|
private async Task StartDeviceMonitoring(CancellationToken cancellationToken, string monitorType)
|
{
|
using (var scope = _serviceProvider.CreateScope())
|
{
|
var hubContext = scope.ServiceProvider.GetRequiredService<IHubContext<DeviceStatusHub>>();
|
|
while (!cancellationToken.IsCancellationRequested)
|
{
|
try
|
{
|
// 获取指定类型的设备数据
|
var deviceData = GetImmediateDeviceData(monitorType);
|
|
// 推送数据给所有连接的客户端,带上监控类型标识
|
await hubContext.Clients.All.SendAsync("ReceiveDeviceStatusUpdate",
|
new { MonitorType = monitorType, Data = deviceData }, cancellationToken);
|
|
Console.WriteLine($"✅ {GetMonitorTypeDisplayName(monitorType)}设备数据推送完成,时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
|
// 等待30秒
|
await Task.Delay(30000, cancellationToken);
|
}
|
catch (OperationCanceledException)
|
{
|
// 监控被取消,正常退出
|
Console.WriteLine($"{GetMonitorTypeDisplayName(monitorType)}设备监控已停止");
|
break;
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine($"❌ {GetMonitorTypeDisplayName(monitorType)}设备监控异常: {ex.Message}");
|
await Task.Delay(5000, cancellationToken);
|
}
|
}
|
}
|
|
// 更新监控状态
|
switch (monitorType)
|
{
|
case "outbound":
|
_isOutboundMonitoring = false;
|
break;
|
case "inbound":
|
_isInboundMonitoring = false;
|
break;
|
case "safetydoor":
|
_isSafetyDoorMonitoring = false;
|
break;
|
}
|
}
|
|
/// <summary>
|
/// 获取设备数据
|
/// </summary>
|
/// <param name="monitorType">监控类型</param>
|
/// <returns></returns>
|
private Dictionary<string, Dictionary<string, int>> GetImmediateDeviceData(string monitorType = "all")
|
{
|
// 定义设备分组
|
var deviceGroups = new Dictionary<string, List<string>>
|
{
|
// 出库设备
|
["MotherCar"] = new List<string> { "RGV112", "RGV110", "RGV114", "RGV115" },
|
["TransferCar"] = new List<string> { "RGV116", "RGV111" },
|
["MaterialOut"] = new List<string> { "RGV118" },
|
|
// 入库设备
|
["InboundMotherCar"] = new List<string> { "RGV103", "RGV105", "RGV108", "RGV109" },
|
["InboundTransferCar"] = new List<string> { "RGV104", "RGV107" },
|
["MaterialIn"] = new List<string> { "RGV101" },
|
|
// 安全门设备
|
["SafetyDoor"] = new List<string> { "HCJ2000" }, // 安全门
|
};
|
|
// 设备类型对应的参数配置
|
var paramConfigs = new Dictionary<string, List<(string DeviceProParamName, string DeviceProParamType, string DeviceProRemark)>>
|
{
|
// 出库设备参数配置
|
["TransferCar"] = new List<(string, string, string)>
|
{
|
("RgvCraneAutoStatus", "RgvCraneAutoStatus", "工作模式"),
|
("RGVCurrentlocation", "RGVCurrentlocation", "当前位置"),
|
("RgvEquipmentStatus", "RgvEquipmentStatus", "有货状态"),
|
("RGV_Targetaddress", "ReadDeviceCommand", "目标地址"),
|
("RGV_Rgvtaskstutas", "RGV_Rgvtaskstutas", "任务状态"),
|
("RGV_Rgvtaskid", "ReadDeviceCommand", "RGV任务编号"),
|
("RGV_Faultcode", "ReadDeviceCommand", "故障代码"),
|
("RGV_Risingsignalplace", "ReadDeviceCommand", "上升信号到位"),
|
("RGV_Descentsignal", "ReadDeviceCommand", "下降信号到位"),
|
("RGVInitialize", "RGVInitialize", "初始化未完成标志位")
|
},
|
["MotherCar"] = new List<(string, string, string)>
|
{
|
("RgvCraneAutoStatus", "RgvCraneAutoStatus", "工作模式"),
|
("RGVCurrentlocation", "RGVCurrentlocation", "当前位置"),
|
("RgvEquipmentStatus", "RgvEquipmentStatus", "有货状态"),
|
("RGV_Targetaddress", "ReadDeviceCommand", "目标地址"),
|
("RGV_Rgvtaskstutas", "RGV_Rgvtaskstutas", "任务状态"),
|
("RGV_Rgvtaskid", "ReadDeviceCommand", "RGV任务编号"),
|
("RGV_Faultcode", "ReadDeviceCommand", "故障代码"),
|
("RGVInitialize", "RGVInitialize", "初始化未完成标志位")
|
},
|
["MaterialOut"] = new List<(string, string, string)>
|
{
|
("RgvCraneAutoStatus", "RgvCraneAutoStatus", "工作模式"),
|
("RGVCurrentlocation", "RGVCurrentlocation", "当前位置"),
|
("RgvEquipmentStatus", "RgvEquipmentStatus", "有货状态"),
|
("RGV_Targetaddress", "ReadDeviceCommand", "目标地址"),
|
("RGV_Rgvtaskstutas", "RGV_Rgvtaskstutas", "任务状态"),
|
("RGV_Rgvtaskid", "ReadDeviceCommand", "RGV任务编号"),
|
("RGV_Faultcode", "ReadDeviceCommand", "故障代码"),
|
("RGV_Risingsignalplace", "ReadDeviceCommand", "上升信号到位"),
|
("RGV_Descentsignal", "ReadDeviceCommand", "下降信号到位"),
|
("RGV_Telescopicfork", "ReadDeviceCommand", "伸缩叉伸出信号"),
|
("RGV_Retractionsignal", "ReadDeviceCommand", "伸缩叉缩回信号"),
|
("RGV_Telescopicfork", "DeviceCommand", "伸出操作"),
|
("RGVForkCurrentPosition", "RGVForkCurrentPosition", "当前位置(货叉)"),
|
("RGVInitialize", "RGVInitialize", "初始化未完成标志位")
|
},
|
|
// 入库设备参数配置
|
["MaterialIn"] = new List<(string, string, string)>
|
{
|
("RgvCraneAutoStatus", "RgvCraneAutoStatus", "工作模式"),
|
("RGVCurrentlocation", "RGVCurrentlocation", "当前位置"),
|
("RgvEquipmentStatus", "RgvEquipmentStatus", "有货状态"),
|
("RGV_Targetaddress", "ReadDeviceCommand", "目标地址"),
|
("RGV_Rgvtaskstutas", "RGV_Rgvtaskstutas", "任务状态"),
|
("RGV_Rgvtaskid", "ReadDeviceCommand", "RGV任务编号"),
|
("RGV_Faultcode", "ReadDeviceCommand", "故障代码"),
|
("RGV_Risingsignalplace", "ReadDeviceCommand", "上升信号到位"),
|
("RGV_Descentsignal", "ReadDeviceCommand", "下降信号到位"),
|
("RGV_Telescopicfork", "ReadDeviceCommand", "伸缩叉伸出信号"),
|
("RGV_Retractionsignal", "ReadDeviceCommand", "伸缩叉缩回信号"),
|
("RGV_Telescopicfork", "DeviceCommand", "伸出操作"),
|
("RGVForkCurrentPosition", "RGVForkCurrentPosition", "当前位置(货叉)"),
|
("RGVInitialize", "RGVInitialize", "初始化未完成标志位")
|
},
|
["InboundMotherCar"] = new List<(string, string, string)>
|
{
|
("RgvCraneAutoStatus", "RgvCraneAutoStatus", "工作模式"),
|
("RGVCurrentlocation", "RGVCurrentlocation", "当前位置"),
|
("RgvEquipmentStatus", "RgvEquipmentStatus", "有货状态"),
|
("RGV_Targetaddress", "ReadDeviceCommand", "目标地址"),
|
("RGV_Rgvtaskstutas", "RGV_Rgvtaskstutas", "任务状态"),
|
("RGV_Rgvtaskid", "ReadDeviceCommand", "RGV任务编号"),
|
("RGV_Faultcode", "ReadDeviceCommand", "故障代码"),
|
("RGVInitialize", "RGVInitialize", "初始化未完成标志位")
|
},
|
["InboundTransferCar"] = new List<(string, string, string)>
|
{
|
("RgvCraneAutoStatus", "RgvCraneAutoStatus", "工作模式"),
|
("RGVCurrentlocation", "RGVCurrentlocation", "当前位置"),
|
("RgvEquipmentStatus", "RgvEquipmentStatus", "有货状态"),
|
("RGV_Targetaddress", "ReadDeviceCommand", "目标地址"),
|
("RGV_Rgvtaskstutas", "RGV_Rgvtaskstutas", "任务状态"),
|
("RGV_Rgvtaskid", "ReadDeviceCommand", "RGV任务编号"),
|
("RGV_Faultcode", "ReadDeviceCommand", "故障代码"),
|
("RGV_Risingsignalplace", "ReadDeviceCommand", "上升信号到位"),
|
("RGV_Descentsignal", "ReadDeviceCommand", "下降信号到位"),
|
("RGVInitialize", "RGVInitialize", "初始化未完成标志位")
|
},
|
|
// 安全门设备参数配置
|
["SafetyDoor"] = new List<(string, string, string)>
|
{
|
("IndicatorStatus", "ReadDeviceCommand", "安全门指示灯状态"),
|
("DoorRequest", "ReadDeviceCommand", "安全门请求开门"),
|
("PowerOffStatus", "ReadDeviceCommand", "安全门断电状态"),
|
("EmergencyStopStatus", "ReadDeviceCommand", "安全门急停状态"),
|
("SafetyLockStatus", "ReadDeviceCommand", "安全门锁状态"),
|
("ResetStatus", "ReadDeviceCommand", "安全门复位状态"),
|
("AlarmSummary", "DeviceCommand", "报警信息"),
|
("OpenDoor", "DeviceCommand", "开门信息")
|
}
|
};
|
|
// 创建最终结果字典
|
var finalResult = new Dictionary<string, Dictionary<string, int>>();
|
|
// 根据监控类型筛选设备组
|
var filteredDeviceGroups = deviceGroups.Where(group =>
|
{
|
return monitorType switch
|
{
|
"outbound" => group.Key == "MotherCar" || group.Key == "TransferCar" || group.Key == "MaterialOut",
|
"inbound" => group.Key == "MaterialIn" || group.Key == "InboundMotherCar" || group.Key == "InboundTransferCar",
|
"safetydoor" => group.Key == "SafetyDoor", // 安全门监控类型
|
"all" => true,
|
_ => group.Key == "MotherCar" || group.Key == "TransferCar" || group.Key == "MaterialOut"
|
};
|
}).ToDictionary(x => x.Key, x => x.Value);
|
|
int i = 0;
|
// 遍历筛选后的设备组
|
foreach (var deviceGroup in filteredDeviceGroups)
|
{
|
string deviceType = deviceGroup.Key;
|
List<string> deviceCodes = deviceGroup.Value;
|
|
// 获取该设备类型的参数配置
|
if (!paramConfigs.ContainsKey(deviceType))
|
continue;
|
|
var deviceParams = paramConfigs[deviceType];
|
|
// 遍历该类型下的所有设备
|
foreach (string deviceChildCode in deviceCodes)
|
{
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceChildCode);
|
|
// 处理不同类型的设备
|
if (device is SpeStackerCrane commonStacker)
|
{
|
// 为当前设备创建一个字典,用于保存 DeviceProRemark 和对应的值
|
var deviceData = new Dictionary<string, int>();
|
|
// 遍历该设备的所有参数
|
foreach (var param in deviceParams)
|
{
|
try
|
{
|
DeviceProDTO? rgvResetOperation = RgvOperationService.GetRGVDeviceProDTO(
|
commonStacker, deviceChildCode, param.DeviceProParamName, param.DeviceProParamType);
|
|
if (rgvResetOperation != null)
|
{
|
int res = RgvOperationService.GetLine(commonStacker, rgvResetOperation.DeviceProAddress);
|
|
// 确保每个 DeviceProRemark 都对应正确的查询结果
|
deviceData[param.DeviceProRemark] = res;
|
}
|
else
|
{
|
deviceData[param.DeviceProRemark] = -1; // 使用 -1 表示查询失败
|
}
|
}
|
catch (Exception)
|
{
|
deviceData[param.DeviceProRemark] = -1; // 使用 -1 表示查询异常
|
}
|
}
|
|
// 将当前设备的数据添加到最终结果中
|
finalResult[deviceChildCode] = deviceData;
|
}
|
else if (device is CommonConveyorLine conveyorLine)
|
{
|
// 处理安全门设备(CommonConveyorLine 类型)
|
// 创建三个安全门设备的数据
|
List<string> safetyDoorList = new List<string> { "AQM001", "AQM002", "AQM003" };
|
|
// 为每个安全门创建数据
|
foreach (string safetyDoorCode in safetyDoorList)
|
{
|
var deviceData = new Dictionary<string, int>();
|
|
// 遍历该设备的所有参数
|
foreach (var param in deviceParams)
|
{
|
try
|
{
|
// 使用安全门名称查询对应的参数
|
DeviceProDTO? devicePro = GetSafetyDoorDeviceProDTO(
|
conveyorLine, safetyDoorCode, param.DeviceProParamName, param.DeviceProParamType);
|
|
if (devicePro != null)
|
{
|
// 对于 CommonConveyorLine 类型,使用通用的数据读取方法
|
int res = ReadCommonConveyorLineData(conveyorLine, devicePro.DeviceProAddress);
|
deviceData[param.DeviceProRemark] = res;
|
}
|
else
|
{
|
deviceData[param.DeviceProRemark] = -1; // 使用 -1 表示查询失败
|
}
|
}
|
catch (Exception)
|
{
|
deviceData[param.DeviceProRemark] = -1; // 使用 -1 表示查询异常
|
}
|
}
|
|
// 将当前安全门设备的数据添加到最终结果中,使用安全门名称作为key
|
finalResult[safetyDoorCode] = deviceData;
|
}
|
}
|
else
|
{
|
// 即使设备不存在或不是支持的类型,也创建一个空字典
|
finalResult[deviceChildCode] = new Dictionary<string, int>();
|
if (device != null)
|
{
|
Console.WriteLine($"警告:设备 {deviceChildCode} 类型 {device.GetType().Name} 不支持,无法读取数据");
|
}
|
else
|
{
|
Console.WriteLine($"警告:设备 {deviceChildCode} 不存在");
|
}
|
}
|
}
|
}
|
|
return finalResult;
|
}
|
|
/// <summary>
|
/// 获取监控状态消息
|
/// </summary>
|
/// <param name="monitorType"></param>
|
/// <returns></returns>
|
private string GetMonitorStatusMessage(string monitorType)
|
{
|
return monitorType switch
|
{
|
"outbound" => $"出库监控: {(_isOutboundMonitoring ? "运行中" : "已停止")}",
|
"inbound" => $"入库监控: {(_isInboundMonitoring ? "运行中" : "已停止")}",
|
"safetydoor" => $"安全门监控: {(_isSafetyDoorMonitoring ? "运行中" : "已停止")}",
|
"all" => $"出库监控: {(_isOutboundMonitoring ? "运行中" : "已停止")}, 入库监控: {(_isInboundMonitoring ? "运行中" : "已停止")}, 安全门监控: {(_isSafetyDoorMonitoring ? "运行中" : "已停止")}",
|
_ => $"出库监控: {(_isOutboundMonitoring ? "运行中" : "已停止")}"
|
};
|
}
|
|
/// <summary>
|
/// 获取监控类型显示名称
|
/// </summary>
|
/// <param name="monitorType"></param>
|
/// <returns></returns>
|
private string GetMonitorTypeDisplayName(string monitorType)
|
{
|
return monitorType switch
|
{
|
"outbound" => "出库",
|
"inbound" => "入库",
|
"safetydoor" => "安全门",
|
"all" => "全部",
|
_ => "出库"
|
};
|
}
|
|
|
/// <summary>
|
/// 读取设备信息
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="DeviceProDataBlock"></param>
|
/// <returns></returns>
|
public static int ReadCommonConveyorLineData(CommonConveyorLine Commonstacker, string DeviceProDataBlock)
|
{
|
return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
|
}
|
|
|
/// <summary>
|
/// 查询安全门设备
|
/// </summary>
|
/// <param name="Commonstacker"></param>
|
/// <param name="SCAddress"></param>
|
/// <param name="Interactivet"></param>
|
/// <returns></returns>
|
public static DeviceProDTO? GetSafetyDoorDeviceProDTO(CommonConveyorLine Commonstacker, string SCAddress, string DeviceProParamName, string DeviceProParamType)
|
{
|
return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
|
}
|
|
//=================================================读取设备信息==========================================================
|
|
|
#region 设备信息
|
/***
|
/// <summary>
|
/// 查询RGV设备
|
/// </summary>
|
/// <param name="Commonstacker"></param>
|
/// <param name="SCAddress"></param>
|
/// <param name="Interactivet"></param>
|
/// <returns></returns>
|
public static DeviceProDTO? GetRGVDeviceProDTO(SpeStackerCrane Commonstacker, string SCAddress, string DeviceProParamName, string DeviceProParamType)
|
{
|
return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
|
}
|
/// <summary>
|
/// 读取设备信息
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="DeviceProDataBlock"></param>
|
/// <returns></returns>
|
public static int GetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
|
{
|
return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
|
}
|
|
/// <summary>
|
/// 写入设备信息
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="DeviceProDataBlock"></param>
|
/// <returns></returns>
|
public static bool RgvSetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock, short rgvvalues)
|
{
|
return Commonstacker.Communicator.Write<short>(DeviceProDataBlock, rgvvalues);
|
}
|
*/
|
#endregion
|
|
|
/// <summary>
|
/// 设备操作
|
/// </summary>
|
/// <param name="deviceName"></param>
|
/// <param name="operationType"></param>
|
/// <param name="parameter"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public WebResponseContent DeviceOperation(string deviceName, string operationType, int parameter)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceName);
|
if (device == null) return webResponse.Error("未找到此设备");
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
string DeviceProParamName = null;
|
string DeviceProParamType = null;
|
int zhi = 1002011;
|
try
|
{
|
|
switch (operationType)
|
{
|
case "cs": //初始化
|
//获取实例
|
DeviceProDTO? RGV_RGVtasktypetcs = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型 //第一步写入任务
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_RGVtasktypetcs.DeviceProAddress, (short)3);
|
//写入自动
|
DeviceProDTO? RGV_DWorkingmodecs = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_DWorkingmode", "DeviceCommand"); //任务id
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_DWorkingmodecs.DeviceProAddress, (short)1);
|
//写入清除任务
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_RGVtasktypetcs.DeviceProAddress, (short)4);
|
|
//反馈确认任务
|
DeviceProDTO? RGV_taskcompletecs = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_taskcomplete", "RGV_taskcomplete"); //任务id
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_taskcompletecs.DeviceProAddress, (short)1);
|
DeviceProParamName = "RGV_Resetoperation";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 1;
|
break;
|
case "sd": //手动
|
DeviceProParamName = "RGV_DWorkingmode";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 0;
|
break;
|
case "zd": //自动
|
DeviceProParamName = "RGV_DWorkingmode";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 1;
|
break;
|
case "ss": //上升
|
DeviceProParamName = "RGV_Risingsignalplace";
|
DeviceProParamType = "DeviceCommand";
|
zhi = parameter;
|
break;
|
case "xj": //下降
|
DeviceProParamName = "RGV_Descentsignal";
|
DeviceProParamType = "DeviceCommand";
|
zhi = parameter;
|
break;
|
case "dz": //地址
|
DeviceProParamName = "RGV_RGVTasklocationt";
|
DeviceProParamType = "DeviceCommand";
|
zhi = parameter;
|
//获取实例
|
DeviceProDTO? RGV_RGVtasktypet = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型
|
//第一步写入任务
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3);
|
|
//写入自动
|
DeviceProDTO? RGV_DWorkingmode = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_Rgvtaskidt", "DeviceCommand"); //任务id
|
//任务id
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)30001);
|
|
//任务id
|
DeviceProDTO? RGV_taskcomplete = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_Lanjiantaskidt", "DeviceCommand"); //任务id
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)30001);
|
break;
|
case "sc": //伸出
|
//DeviceProParamName = "RGV_DWorkingmode";
|
//DeviceProParamType = "DeviceCommand";
|
//zhi = 1;
|
break;
|
case "sh": //缩回
|
//DeviceProParamName = "RGV_Retractionsignal";
|
//DeviceProParamType = "DeviceCommand";
|
//zhi = 1;
|
break;
|
case "kld": //开雷达
|
DeviceProParamName = "RGV_Shieldradar";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 1;
|
break;
|
case "gld": //关雷达
|
DeviceProParamName = "RGV_Shieldradar";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 0;
|
break;
|
case "fw":
|
DeviceProParamName = "RGV_Resetoperation";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 1;
|
break;
|
}
|
|
//获取需要复位的设备
|
DeviceProDTO? RGV_Resetoperation = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType); //复位报警信息
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress,(short)zhi);
|
return webResponse.OK("设备操作成功");
|
}catch(Exception)
|
{
|
return webResponse.Error("设备操作失败");
|
}
|
|
}
|
|
|
/// <summary>
|
/// 一键操作
|
/// </summary>
|
/// <param name="monitorType"></param>
|
/// <param name="operationType"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public WebResponseContent OneClickOperation(string monitorType, string operationType)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
List<string> Devices = new List<string>();
|
if (monitorType == "Inbound")
|
{
|
//入库设备
|
Devices = new List<string> { "RGV103", "RGV105", "RGV108", "RGV109", "RGV104", "RGV107", "RGV101" };
|
}
|
else if (monitorType == "Outbound")
|
{
|
//出库设备
|
Devices = new List<string> { "RGV112", "RGV110", "RGV114", "RGV115", "RGV116", "RGV111", "RGV118" };
|
}
|
try
|
{
|
List<IDevice?> devices = Storage.Devices.Where(x => Devices.Contains(x.DeviceCode)).Cast<IDevice?>().ToList();
|
if (devices == null || !devices.Any())
|
{
|
return webResponse.Error("未找到相关设备");
|
}
|
string DeviceProParamName = null;
|
string DeviceProParamType = null;
|
int zhi = 1002011;
|
switch (operationType)
|
{
|
case "init": //初始化
|
DeviceProParamName = "RGV_Resetoperation";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 1;
|
break;
|
case "reset":
|
DeviceProParamName = "RGV_Resetoperation";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 1;
|
break;
|
case "start":
|
DeviceProParamName = "RGV_DWorkingmode";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 1;
|
break;
|
case "stop":
|
DeviceProParamName = "RGV_DWorkingmode";
|
DeviceProParamType = "DeviceCommand";
|
zhi = 0;
|
break;
|
}
|
foreach(var device in devices)
|
{
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
|
if (operationType == "init")
|
{
|
//获取实例
|
DeviceProDTO? RGV_RGVtasktypetcs = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, device.DeviceCode, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型 //第一步写入任务
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_RGVtasktypetcs.DeviceProAddress, (short)3);
|
//写入自动
|
DeviceProDTO? RGV_DWorkingmodecs = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, device.DeviceCode, "RGV_DWorkingmode", "DeviceCommand"); //任务id
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_DWorkingmodecs.DeviceProAddress, (short)1);
|
//写入清除任务
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_RGVtasktypetcs.DeviceProAddress, (short)4);
|
|
//反馈确认任务
|
DeviceProDTO? RGV_taskcompletecs = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, device.DeviceCode, "RGV_taskcomplete", "RGV_taskcomplete"); //任务id
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_taskcompletecs.DeviceProAddress, (short)1);
|
}
|
DeviceProDTO? RGV_Resetoperation = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, device.DeviceCode, DeviceProParamName, DeviceProParamType); //复位报警信息
|
RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)zhi);
|
}
|
return webResponse.OK("设备操作成功");
|
}catch(Exception)
|
{
|
return webResponse.Error("设备操作失败");
|
}
|
}
|
}
|
}
|
|