1
HuBingJie
8 天以前 5da3a276b7847187a7c155ee069d3cd4c9e58074
´úÂë¹ÜÀí/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvoperainformService.cs
@@ -1,4 +1,4 @@
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
/*----------------------------------------------------------------
 * å‘½åç©ºé—´ï¼šWIDESEAWCS_TaskInfoService
 * åˆ›å»ºè€…:胡童庆
@@ -25,6 +25,7 @@
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz.Util;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -40,7 +41,9 @@
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.Http;
using WIDESEA_Common.Log;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.Enum;
@@ -58,43 +61,45 @@
{
    public class RgvoperainformService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvoperainformService
    {
        private readonly IAgvStationService _gvStationService;
        private readonly IAgvStationService _agvStationService;
        private readonly IServiceProvider _serviceProvider;
        private static bool _isMonitoring = false;
        private readonly IRepository<DeviceAlarmLog> _deviceAlarmLog;
        //private static CancellationTokenSource _cancellationTokenSource;
        // åœ¨ç±»çº§åˆ«æ·»åŠ ç‹¬ç«‹çš„ç›‘æŽ§çŠ¶æ€
        private bool _isOutboundMonitoring = false;
        private bool _isInboundMonitoring = false;
        private bool _isSafetyDoorMonitoring = false;
        private bool _isPlatformMonitoring = false;
        // åœ¨ç±»çš„字段区
        private CancellationTokenSource? _platformCancellationTokenSource;
        private CancellationTokenSource _outboundCancellationTokenSource;
        private CancellationTokenSource _inboundCancellationTokenSource;
        private CancellationTokenSource _safetyDoorCancellationTokenSource;
        public RgvoperainformService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, IServiceProvider serviceProvider) : base(BaseDal)
        public RgvoperainformService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, IServiceProvider serviceProvider, IRepository<DeviceAlarmLog> deviceAlarmLog) : base(BaseDal)
        {
            _gvStationService = agvStationService;
            _agvStationService = agvStationService;
            _serviceProvider = serviceProvider;
            _deviceAlarmLog = deviceAlarmLog;
        }
        //=================================================读取设备信息==========================================================
        /// <summary>
        /// èŽ·å–è®¾å¤‡çŠ¶æ€ï¼ˆæ”¯æŒå‡ºåº“ã€å…¥åº“å’Œå®‰å…¨é—¨ç‹¬ç«‹ç›‘æŽ§ï¼‰
        /// èŽ·å–è®¾å¤‡çŠ¶æ€ï¼ˆæ”¯æŒå‡ºåº“ã€å…¥åº“ã€å®‰å…¨é—¨å’Œç«™å°ç‹¬ç«‹ç›‘æŽ§ï¼‰
        /// </summary>
        /// <param name="off">0:停止 1:启动 2:仅查询</param>
        /// <param name="monitorType">监控类型:outbound-出库 inbound-入库 safetydoor-安全门 all-全部</param>
        /// <param name="monitorType">监控类型:outbound-出库 inbound-入库 safetydoor-安全门 platform-站台 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";//安全门
            bool isPlatform = monitorType == "platform" || monitorType == "all";//站台
            if (off == 1)
            {
@@ -120,6 +125,13 @@
                    _ = Task.Run(async () => await StartDeviceMonitoring(_safetyDoorCancellationTokenSource.Token, "safetydoor"));
                }
                if (isPlatform && !_isPlatformMonitoring)
                {
                    _isPlatformMonitoring = true;
                    _platformCancellationTokenSource = new CancellationTokenSource();
                    _ = Task.Run(async () => await StartDeviceMonitoring(_platformCancellationTokenSource.Token, "platform"));
                }
                var immediateData = GetImmediateDeviceData(monitorType);
                string message = GetMonitorStatusMessage(monitorType);
                return WebResponseContent.Instance.OK($"设备状态监控已启动 - {message}", immediateData);
@@ -143,6 +155,12 @@
                {
                    _isSafetyDoorMonitoring = false;
                    _safetyDoorCancellationTokenSource?.Cancel();
                }
                if (isPlatform && _isPlatformMonitoring)
                {
                    _isPlatformMonitoring = false;
                    _platformCancellationTokenSource?.Cancel();
                }
                var finalData = GetImmediateDeviceData(monitorType);
@@ -212,6 +230,9 @@
                case "safetydoor":
                    _isSafetyDoorMonitoring = false;
                    break;
                case "platform":
                    _isPlatformMonitoring = false;
                    break;
            }
        }
@@ -236,7 +257,14 @@
                ["MaterialIn"] = new List<string> { "RGV101" },
                // å®‰å…¨é—¨è®¾å¤‡
                ["SafetyDoor"] = new List<string> { "HCJ2000" }, // å®‰å…¨é—¨
                ["SafetyDoor"] = new List<string> { "HCJ2000" },
                // ç«™å°è®¾å¤‡ - æ ¹æ®æ‚¨æä¾›çš„协议添加所有站台
                //        ["Platform"] = new List<string> {
                //    "1001", "1002", "2016", "2017", "2018", "2019", "1021", "1061", "1131", "1171"
                //}
                ["Platform"] = new List<string> { "HCJ2000" },
            };
            // è®¾å¤‡ç±»åž‹å¯¹åº”的参数配置
@@ -339,6 +367,13 @@
            ("ResetStatus", "ReadDeviceCommand", "安全门复位状态"),
            ("AlarmSummary", "DeviceCommand", "报警信息"),
            ("OpenDoor", "DeviceCommand", "开门信息")
        },
                // ç«™å°è®¾å¤‡å‚数配置 - æ ¹æ®æ‚¨æä¾›çš„协议添加
                ["Platform"] = new List<(string, string, string)>
        {
            ("HCJ_GoodsStatus", "ReadDeviceCommand", "光电信号"),
            ("DoorRequest", "DeviceCommand", "任务id")
        }
            };
@@ -352,13 +387,13 @@
                {
                    "outbound" => group.Key == "MotherCar" || group.Key == "TransferCar" || group.Key == "MaterialOut",
                    "inbound" => group.Key == "MaterialIn" || group.Key == "InboundMotherCar" || group.Key == "InboundTransferCar",
                    "safetydoor" => group.Key == "SafetyDoor", // å®‰å…¨é—¨ç›‘控类型
                    "safetydoor" => group.Key == "SafetyDoor",
                    "platform" => group.Key == "Platform", // ç«™å°ç›‘控类型
                    "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)
            {
@@ -413,57 +448,83 @@
                    }
                    else if (device is CommonConveyorLine conveyorLine)
                    {
                        // å¤„理安全门设备(CommonConveyorLine ç±»åž‹ï¼‰
                        // åˆ›å»ºä¸‰ä¸ªå®‰å…¨é—¨è®¾å¤‡çš„æ•°æ®
                        List<string> safetyDoorList = new List<string> { "AQM001", "AQM002", "AQM003" };
                        // ä¸ºæ¯ä¸ªå®‰å…¨é—¨åˆ›å»ºæ•°æ®
                        foreach (string safetyDoorCode in safetyDoorList)
                        // å¤„理安全门设备和站台设备(CommonConveyorLine ç±»åž‹ï¼‰
                        if (deviceType == "SafetyDoor")
                        {
                            var deviceData = new Dictionary<string, int>();
                            // å®‰å…¨é—¨è®¾å¤‡å¤„理逻辑(保持不变)
                            List<string> safetyDoorList = new List<string> { "AQM001", "AQM002", "AQM003" };
                            // éåŽ†è¯¥è®¾å¤‡çš„æ‰€æœ‰å‚æ•°
                            foreach (var param in deviceParams)
                            foreach (string safetyDoorCode in safetyDoorList)
                            {
                                try
                                {
                                    // ä½¿ç”¨å®‰å…¨é—¨åç§°æŸ¥è¯¢å¯¹åº”的参数
                                    DeviceProDTO? devicePro = GetSafetyDoorDeviceProDTO(
                                        conveyorLine, safetyDoorCode, param.DeviceProParamName, param.DeviceProParamType);
                                var deviceData = new Dictionary<string, int>();
                                    if (devicePro != null)
                                    {
                                        // å¯¹äºŽ CommonConveyorLine ç±»åž‹ï¼Œä½¿ç”¨é€šç”¨çš„æ•°æ®è¯»å–方法
                                        int res = ReadCommonConveyorLineData(conveyorLine, devicePro.DeviceProAddress);
                                        deviceData[param.DeviceProRemark] = res;
                                    }
                                    else
                                    {
                                        deviceData[param.DeviceProRemark] = -1; // ä½¿ç”¨ -1 è¡¨ç¤ºæŸ¥è¯¢å¤±è´¥
                                    }
                                }
                                catch (Exception)
                                foreach (var param in deviceParams)
                                {
                                    deviceData[param.DeviceProRemark] = -1; // ä½¿ç”¨ -1 è¡¨ç¤ºæŸ¥è¯¢å¼‚常
                                    try
                                    {
                                        DeviceProDTO? devicePro = GetSafetyDoorDeviceProDTO(
                                            conveyorLine, safetyDoorCode, param.DeviceProParamName, param.DeviceProParamType);
                                        if (devicePro != null)
                                        {
                                            int res = ReadCommonConveyorLineData(conveyorLine, devicePro.DeviceProAddress);
                                            deviceData[param.DeviceProRemark] = res;
                                        }
                                        else
                                        {
                                            deviceData[param.DeviceProRemark] = -1;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        deviceData[param.DeviceProRemark] = -1;
                                    }
                                }
                                finalResult[safetyDoorCode] = deviceData;
                            }
                        }
                            // å°†å½“前安全门设备的数据添加到最终结果中,使用安全门名称作为key
                            finalResult[safetyDoorCode] = deviceData;
                        if (deviceType == "Platform")
                        {
                            // å®‰å…¨é—¨è®¾å¤‡å¤„理逻辑(保持不变)
                            List<string> PlatformList = new List<string> { "1001", "1002", "2016", "2017", "2018", "2019", "1021", "1061", "1131", "1171" };
                            foreach (string Platform in PlatformList)
                            {
                                var deviceData = new Dictionary<string, int>();
                                foreach (var param in deviceParams)
                                {
                                    try
                                    {
                                        DeviceProDTO? devicePro = GetSafetyDoorDeviceProDTO(
                                            conveyorLine, Platform, param.DeviceProParamName, param.DeviceProParamType);
                                        if (devicePro != null)
                                        {
                                            int res = ReadCommonConveyorLineData(conveyorLine, devicePro.DeviceProAddress);
                                            deviceData[param.DeviceProRemark] = res;
                                        }
                                        else
                                        {
                                            deviceData[param.DeviceProRemark] = -1;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        deviceData[param.DeviceProRemark] = -1;
                                    }
                                }
                                finalResult[Platform] = deviceData;
                            }
                        }
                    }
                    else
                    {
                        // å³ä½¿è®¾å¤‡ä¸å­˜åœ¨æˆ–不是支持的类型,也创建一个空字典
                        finalResult[deviceChildCode] = new Dictionary<string, int>();
                        /*if (device != null)
                        {
                            Console.WriteLine($"警告:设备 {deviceChildCode} ç±»åž‹ {device.GetType().Name} ä¸æ”¯æŒï¼Œæ— æ³•读取数据");
                        }
                        else
                        {
                            Console.WriteLine($"警告:设备 {deviceChildCode} ä¸å­˜åœ¨");
                        }*/
                    }
                }
            }
@@ -483,7 +544,8 @@
                "outbound" => $"出库监控: {(_isOutboundMonitoring ? "运行中" : "已停止")}",
                "inbound" => $"入库监控: {(_isInboundMonitoring ? "运行中" : "已停止")}",
                "safetydoor" => $"安全门监控: {(_isSafetyDoorMonitoring ? "运行中" : "已停止")}",
                "all" => $"出库监控: {(_isOutboundMonitoring ? "运行中" : "已停止")}, å…¥åº“监控: {(_isInboundMonitoring ? "运行中" : "已停止")}, å®‰å…¨é—¨ç›‘控: {(_isSafetyDoorMonitoring ? "运行中" : "已停止")}",
                "platform" => $"站台监控: {(_isPlatformMonitoring ? "运行中" : "已停止")}", // ç«™å°ç›‘控状态
                "all" => $"出库监控: {(_isOutboundMonitoring ? "运行中" : "已停止")}, å…¥åº“监控: {(_isInboundMonitoring ? "运行中" : "已停止")}, å®‰å…¨é—¨ç›‘控: {(_isSafetyDoorMonitoring ? "运行中" : "已停止")}, ç«™å°ç›‘控: {(_isPlatformMonitoring ? "运行中" : "已停止")}",
                _ => $"出库监控: {(_isOutboundMonitoring ? "运行中" : "已停止")}"
            };
        }
@@ -500,11 +562,11 @@
                "outbound" => "出库",
                "inbound" => "入库",
                "safetydoor" => "安全门",
                "platform" => "站台", // ç«™å°æ˜¾ç¤ºåç§°
                "all" => "全部",
                _ => "出库"
            };
        }
        /// <summary>
        /// è¯»å–设备信息
@@ -517,7 +579,6 @@
            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
        }
        /// <summary>
        /// æŸ¥è¯¢å®‰å…¨é—¨è®¾å¤‡
        /// </summary>
@@ -528,6 +589,19 @@
        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);
        }
        /// <summary>
        /// æŸ¥è¯¢ç«™å°è®¾å¤‡
        /// </summary>
        /// <param name="Commonstacker"></param>
        /// <param name="PlatformCode">站台编号</param>
        /// <param name="DeviceProParamName">参数名称</param>
        /// <param name="DeviceProParamType">参数类型</param>
        /// <returns></returns>
        public static DeviceProDTO? GetPlatformDeviceProDTO(CommonConveyorLine Commonstacker, string PlatformCode, string DeviceProParamName, string DeviceProParamType)
        {
            return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == PlatformCode && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
        }
        //=================================================读取设备信息==========================================================
@@ -590,7 +664,7 @@
            int zhi = 1002011;
            try
            {
            switch (operationType)
            {
                case "cs":          //初始化
@@ -624,14 +698,39 @@
                    DeviceProParamName = "RGV_Risingsignalplace";
                    DeviceProParamType = "DeviceCommand";
                    zhi = parameter;
                    break;
                case "xj":          //下降
                    DeviceProDTO? RGV_Resetoperationss1 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //上升
                    RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationss1.DeviceProAddress, (short)zhi);
                    //DeviceProDTO? RGV_Resetoperationss2 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_Risingsignalplace", "ReadDeviceCommand");        //上升到位信号
                    //    int resss = 0;
                    //    while (resss == 0)
                    //    {
                    //        Thread.Sleep(2000);
                    //        resss = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperationss2.DeviceProAddress);
                    //    }
                    //    DeviceProDTO? RGV_Resetoperationss3 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //上升
                    //    RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationss3.DeviceProAddress, 0);
                        return webResponse.OK();
                    case "xj":          //下降
                    DeviceProParamName = "RGV_Descentsignal";
                    DeviceProParamType = "DeviceCommand";
                    zhi = parameter;
                    break;
                        DeviceProDTO? RGV_Resetoperationxj1 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //下降
                        RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationxj1.DeviceProAddress, (short)zhi);
                        //DeviceProDTO? RGV_Resetoperationxj2 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_Descentsignal", "ReadDeviceCommand");        //下降到位信号
                        //int resxj = 0;
                        //while (resxj == 0)
                        //{
                        //    Thread.Sleep(2000);
                        //    resxj = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperationxj2.DeviceProAddress);
                        //}
                        //DeviceProDTO? RGV_Resetoperationxj3 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //上升
                        //RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationxj3.DeviceProAddress, 0);
                        return webResponse.OK();
                case "dz":          //地址
                    DeviceProParamName = "RGV_RGVTasklocationt";
                        if (!YiDongPD(Commonstacker, parameter)) { return webResponse.Error("目标地址被占用或条件不满足,禁止移动"); }
                        DeviceProParamName = "RGV_RGVTasklocationt";
                    DeviceProParamType = "DeviceCommand";
                    zhi = parameter;
                        //获取实例
@@ -684,6 +783,657 @@
                return webResponse.Error("设备操作失败");
            }
        }
    /// <summary>
    /// 1、判断子车区域
    /// 2、判断子车当前位置
    /// 3、判断子车要去的位置
    /// 4、根据子车要去的为获取母车位置
    ///
    /// </summary>
    /// <param name="device">要移动的设备</param>
    /// <param name="parameter">要去的目标地址</param>
    /// <returns></returns>
        private bool YiDongPD(SpeStackerCrane Commonstacker, int parameter)
        {
            //入库设备
            List<string> InDevices = new List<string> {  "RGV104", "RGV107" };
            //出库设备
            List<string>  OutDevices = new List<string> {"RGV116", "RGV111"};
            Dictionary<int, string> HCJ = new Dictionary<int, string>
        {
            { 1061, "HCJ106" },
            { 1021, "HCJ102" },
            { 1131, "HCJ113" },
            { 1171, "HCJ117" },
        };
            AGVStation RGVTaskdevice = _agvStationService.Corridorequipment(Commonstacker.DeviceCode);   //根据设备获取到内容
            //根据子车获取到母车设备
            // æ ¹æ®å­è½¦èŽ·å–åˆ°æ¯è½¦è®¾å¤‡
            AGVStation Mu1 = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
            AGVStation Mu2 = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCardeputy);
            // èŽ·å–å­è½¦ä½ç½®
            int zhicheWZ = GetzicheWZ(Commonstacker, Commonstacker.DeviceCode);
            // ç»Ÿä¸€ç›®æ ‡å ç”¨æ£€æŸ¥ï¼ˆæ‰«æå…¶å®ƒ RGV æ˜¯å¦åœ¨åŒä¸€ç›®æ ‡åœ°å€ï¼‰
            bool IsAddressOccupied(int addr)
            {
                var allCodes = InDevices.Concat(OutDevices).Where(code => code != Commonstacker.DeviceCode).ToList();
                foreach (var code in allCodes)
                {
                    var dev = Storage.Devices.FirstOrDefault(x => x.DeviceCode == code) as SpeStackerCrane;
                    if (dev == null) continue;
                    try
                    {
                        DeviceProDTO? locDto = RgvOperationService.GetRGVDeviceProDTO(dev, code, "RGVCurrentlocation", "RGVCurrentlocation");
                        if (locDto == null) continue;
                        int loc = RgvOperationService.GetLine(dev, locDto.DeviceProAddress);
                        if (loc == addr) return true; // ç›®æ ‡è¢«å ç”¨
                    }
                    catch
                    {
                        // è¯»å–异常不当作占用,避免误拒
                    }
                }
                return false;
            }
            // ç›®æ ‡è¢«å…¶ä»– RGV å ç”¨åˆ™ç¦æ­¢
            if (IsAddressOccupied(parameter)) return false;
            if (RGVTaskdevice.Station_Area == 6) // å¤–ä¾§
            {
                if (zhicheWZ == RGVTaskdevice.WaitmomentOne) // ç­‰å¾…点1
                {
                    // åˆ¤æ–­å¤–侧小车是否在 HCJ ä¸Š
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    //判断传进来设备是否是入库
                    if (InDevices.Contains(Commonstacker.DeviceCode))
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    if (parameter == Mu1.ZicheMotherinlaw) //母1
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == Mu2.ZicheMotherinlaw) // æ¯2
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && mu2 != Mu2.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
                    {
                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu2.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }else if(parameter == 1021 || parameter == 1171)
                    {
                        if (RGVTaskdevice.ChildPosiDeviceCode == "RGV116" && Mucheywhaddres("HCJ102"))
                        {
                            return true;
                        }
                        string hcj = HCJ[parameter];
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                else if (zhicheWZ == RGVTaskdevice.WaitmomentTwo) // ç­‰å¾…点2
                {
                    // åˆ¤æ–­å¤–侧小车是否在 HCJ ä¸Š
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    //判断传进来设备是否是入库
                    if (InDevices.Contains(Commonstacker.DeviceCode))
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    if (parameter == Mu1.ZicheMotherinlaw)
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == Mu2.ZicheMotherinlaw)
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
                    {
                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu2.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == 1021 || parameter == 1171)
                    {
                        string hcj = HCJ[parameter];
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
            else if (RGVTaskdevice.Station_Area == 5) // å†…ä¾§
            {
                if (zhicheWZ == RGVTaskdevice.WaitmomentOne) // ç­‰å¾…点1
                {
                    // åˆ¤æ–­å¤–侧小车是否在 HCJ ä¸Š
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    //判断传进来设备是否是入库
                    if (InDevices.Contains(Commonstacker.DeviceCode))
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    if (parameter == Mu1.ZicheMotherinlaw) //母1
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == Mu2.ZicheMotherinlaw) // æ¯2
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }else if (parameter == RGVTaskdevice.HCJStorageaddress)
                    {
                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
                        if (Mucheywhaddres(hcj))
                        {
                            return true;
                        }
                    }
                    else
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                else if (zhicheWZ == RGVTaskdevice.WaitmomentTwo) // ç­‰å¾…点2
                {
                    // åˆ¤æ–­å¤–侧小车是否在 HCJ ä¸Š
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    //判断传进来设备是否是入库
                    if (InDevices.Contains(Commonstacker.DeviceCode))
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    if (parameter == Mu1.ZicheMotherinlaw)
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == Mu2.ZicheMotherinlaw)
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
                    {
                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode)&&Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
            // é»˜è®¤ï¼šæœªè¢«æ‹¦æˆªä¸”目标未占用 -> æ”¾è¡Œ
            return true;
        }
        /// <summary>
        /// ä¼ å…¥è®¾å¤‡ï¼Œè¿”回当前设备信息
        /// </summary>
        /// <param name="ChildPosiDeviceCode">设备</param>
        /// <returns></returns>
        public static int GetEquipmentInformation(string ChildPosiDeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null)
            {
                Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},003");
                return 0;
            }
            DeviceProDTO? deviceProDTOGZMS = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RgvCraneAutoStatus" && x.DeviceProParamType == "RgvCraneAutoStatus");
            int GZMS = RGVGetLine(speStackerCrane, deviceProDTOGZMS.DeviceProAddress);
            DeviceProDTO? deviceProDTORWZT = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGV_Rgvtaskstutas" && x.DeviceProParamType == "RGV_Rgvtaskstutas");
            int RWZT = RGVGetLine(speStackerCrane, deviceProDTORWZT.DeviceProAddress);
            DeviceProDTO? deviceProDTOBJGC = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVStepprocess" && x.DeviceProParamType == "RGVStepprocess");
            int BJGC = RGVGetLine(speStackerCrane, deviceProDTOBJGC.DeviceProAddress);
            DeviceProDTO? deviceProDTOWZ = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVCurrentlocation" && x.DeviceProParamType == "RGVCurrentlocation");
            int WZ = RGVGetLine(speStackerCrane, deviceProDTOWZ.DeviceProAddress);
            if (GZMS == 1 && RWZT == 0 && BJGC == 0)
            {
                return WZ;
            }
            else
            {
                return 0;
            }
        }
        public static bool Mucheywhaddres(string DeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
            DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeviceCode && x.DeviceProParamName == "RgvEquipmentStatus" && x.DeviceProParamType == "RgvEquipmentStatus");
            int MCGStatus = RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
            if (MCGStatus == (int)RgvEquipmentStatus.NoCargo)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// RGV设备状态
        /// </summary>
        public enum RgvEquipmentStatus
        {
            /// <summary>
            /// æ— è´§
            /// </summary>
            [Description("无货")]
            NoCargo,
            /// <summary>
            /// æœ‰è´§
            /// </summary>
            [Description("有货")]
            HasCargo,
            /// <summary>
            /// æœªçŸ¥
            /// </summary>
            [Description("未知")]
            Unkonw = 6
        }
        /// <summary>
        /// ä¼ å…¥è®¾å¤‡ï¼ŒèŽ·å–å½“å‰ä½ç½®ä½ç½®
        /// </summary>
        /// <param name="ChildPosiDeviceCode">设备</param>
        /// <returns></returns>
        public static int GetEquipmentlocation(string ChildPosiDeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null) return 0;
            DeviceProDTO? deviceProDTO = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVCurrentlocation" && x.DeviceProParamType == "RGVCurrentlocation");
            int MCGStatus = RGVGetLine(speStackerCrane, deviceProDTO.DeviceProAddress);
            return MCGStatus;
        }
        public static int RGVGetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
        {
            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
        }
        /// <summary>
        /// èŽ·å–åˆ°å­è½¦ä½ç½®
        /// </summary>
        /// <param name="commonstacker"></param>
        /// <param name="deviceCode"></param>
        /// <returns></returns>
        private int GetzicheWZ(SpeStackerCrane commonstacker, string deviceCode)
        {
            DeviceProDTO? RGVCurrentlocation = RgvOperationService.GetRGVDeviceProDTO(commonstacker, commonstacker.DeviceCode, "RGVCurrentlocation", "RGVCurrentlocation");
            return RgvOperationService.GetLine(commonstacker, RGVCurrentlocation.DeviceProAddress);
        }
@@ -769,6 +1519,170 @@
                return webResponse.Error("设备操作失败");
            }
}
        /// <summary>
        /// æŸ¥çœ‹æŠ¥è­¦
        /// </summary>
        public WebResponseContent LogAlarmToDatabase(string JobDeviceName)
        {
            // è®¾å¤‡åˆ†ç±» - åˆå¹¶ç‰ˆæœ¬
            var deviceCategories = new Dictionary<string, List<string>>
            {
                ["MotherCar"] = new List<string> { "RGV112", "RGV110", "RGV114", "RGV115", "RGV103", "RGV105", "RGV108", "RGV109" },
                ["TransferCar"] = new List<string> { "RGV116", "RGV111", "RGV104", "RGV107" },
                ["ExternalRGV"] = new List<string> { "RGV118", "RGV101" }
            };
            WebResponseContent webResponse = new WebResponseContent();
            string DeviceName = JobDeviceName;    //设备名称
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            if (device == null) return webResponse.Error();
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
            DeviceProDTO? RGV_Resetoperation = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Faultcode", "ReadDeviceCommand");
            DeviceProDTO? RGVCurrentlocation = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGVCurrentlocation", "RGVCurrentlocation");
            DeviceProDTO? RGV_Rgvtaskid = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Rgvtaskid", "ReadDeviceCommand");
            int baoj = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress);
            if (baoj<=0)
            {
                return null;
            }
            int Currentlocation = RgvOperationService.GetLine(Commonstacker, RGVCurrentlocation.DeviceProAddress);
            int Rgvtaskid = RgvOperationService.GetLine(Commonstacker, RGV_Rgvtaskid.DeviceProAddress);
            string alarmMessage = "";
            if (deviceCategories["MotherCar"].Contains(DeviceName))
            {
                // æ¯è½¦ä¸“用报警处理逻辑
                alarmMessage = HandleMotherCarAlarm(baoj);
            }
            else if (deviceCategories["TransferCar"].Contains(DeviceName))
            {
                // å­è½¦ä¸“用报警处理逻辑
                alarmMessage = HandleTransferCarAlarm(baoj);
            }
            else if (deviceCategories["ExternalRGV"].Contains(DeviceName))
            {
                // å¤–口RGV专用报警处理逻辑
                alarmMessage = HandleExternalRGVAlarm(baoj);
            }
            // å†™å…¥æ–‡æœ¬æ—¥å¿—(按设备分组/按日切分)
            var logContent = $"设备:{DeviceName} | æŠ¥è­¦ç :{baoj} | æŠ¥è­¦æè¿°:{alarmMessage} | å½“前位置:{Currentlocation} | ä»»åŠ¡å·:{Rgvtaskid}";
            // groupName: Alarm,logName: è®¾å¤‡å
            WriteLog.Write_Log("Alarm", DeviceName, logContent, new
            {
                DeviceCode = DeviceName,
                AlarmCode = baoj,
                AlarmContent = alarmMessage,
                DeviceLocation = Currentlocation,
                TaskNum = Rgvtaskid,
                Time = DateTime.Now
            });
            return webResponse.OK();
        }
        // æŠ¥è­¦ä»£ç æ˜ å°„方法
        private string HandleExternalRGVAlarm(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
{
    {0, "无报警"},
    {1, "RGV小车急停被按下"},
    {2, "正转雷达报警"},
    {3, "反转雷达报警"},
    {4, "前进限位报警"},
    {5, "后退限位报警"},
    {6, ""},
    {7, "PLC模块故障"},
    {8, "PLC扩展模块故障"},
    {9, "称重模块故障"},
    {10, "扫码定位故障"},
    {11, "RGV长时间空转故障"},
    {12, "目的地不等于实际位置故障"},
    {13, "与总控通讯故障"},
    {14, "前雷达屏蔽警告"},
    {15, "后雷达屏蔽警告"},
    {16, "行走变频器故障"},
    {17, "伸缩叉变频器故障"},
    {18, "液压单元过载保护故障"},
    {19, "液压上升超时报警"},
    {20, "液压下降超时报警"},
    {21, "伸缩叉伸出超时报警"},
    {22, "伸缩叉缩回超时报警"},
    {23, "外形检测报警"},
    {24, "称重超重报警"},
    {25, "货叉伸出极限限位报警"},
    {26, "货叉缩回极限限位报警"},
    {27, "取货时自身有货物报警"},
    {28, "放货时自身无货物报警"},
    {29, "货叉未回到初始位报警"},
    {30, "触发仅移动命令时货叉不在初始位报警"},
    {31, "货叉到达初始位但中位传感器未检测到报警"},
    {32, "行走轴没到位禁止货叉伸出"},
    {33, "取货异常报警"},
    {34, "放货异常报警"},
    {35, "外型检测-前超出报警"},
    {36, "外型检测-后超出报警"},
    {37, "外型检测-左超出报警"},
    {38, "外型检测-右超出报警"},
    {39, "外型检测-上超出报警"}
};
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
        private string HandleTransferCarAlarm(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
    {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "前进限位报警"},
        {3, "后退限位报警"},
        {4, "PLC摸块故障"},
        {5, "PLC扩展模块故障"},
        {6, "扫码定位故障"},
        {7, "RGV长时间空转故障"},
        {8, "目的地不等于实际位置故障"},
        {9, "与总控通讯故障"},
        {10, "行走变频器故障"},
        {11, "液压单元过载保护故障"},
        {12, "液压上升超时报警"},
        {13, "液压下降超时报警"},
        {14, "取货时自身有货物报警"},
        {15, "放货时自身无货物报警"},
        {16, "取货检测不到货物报警"}
    };
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
        private string HandleMotherCarAlarm(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
    {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "前进限位报警"},
        {3, "后退限位报警"},
        {4, "PLC摸块故障"},
        {5, "PLC扩展模块故障"},
        {6, "RGV长时间空转故障"},
        {7, "目的地不等于实际位置故障"},
        {8, "与总控通讯故障"},
        {9, "行走变频器故障"},
        {10, "取货时自身有货物报警"},
        {11, "放货时自身无货物报警"},
        {12, "停止时位置过冲报警"}
    };
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
    }
}