1
huangxiaoqiang
10 天以前 8e49faa42ff419efa0641478702ce7d5f8455bd9
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceInfoService.cs
@@ -18,6 +18,7 @@
using AutoMapper;
using HslCommunication;
using Newtonsoft.Json;
using SixLabors.ImageSharp.ColorSpaces;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -625,7 +626,7 @@
                    {
                        CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                        conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
                        return content.OK("停止成功");
                        return content.OK("退回成功");
                    }
                }
                return content.Error("未找到设备信息请联系IT");
@@ -648,7 +649,7 @@
                    {
                        CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                        conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(4), stationManager.stationChildCode);
                        return content.OK("停止成功");
                        return content.OK("取消成功");
                    }
                }
                return content.Error("未找到设备信息请联系IT");
@@ -671,7 +672,7 @@
                    {
                        CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                        conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(6), stationManager.stationChildCode);
                        return content.OK("停止成功");
                        return content.OK("初始化成功");
                    }
                }
                return content.Error("未找到设备信息请联系IT");
@@ -725,7 +726,446 @@
        #endregion
        #region  RGV手动命令
        public WebResponseContent RGVHandTask(HandTask RGVhand)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (RGVhand == null || RGVhand.TaskType == "")
                {
                    return content.Error("请输入任务命令");
                }
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == RGVhand.DeviceCode);
                if (device != null)
                {
                    if (RGVhand.DeviceCode == "RGV01" || RGVhand.DeviceCode == "RGV02")
                    {
                        CommonRGV_FirstFloor RGVcommand = (CommonRGV_FirstFloor)device;
                        if (RGVhand.TaskType == "1")
                        {
                            if (RGVhand.SourceAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandFirstFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}取定位命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}取定位命令取货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "2")
                        {
                            if (RGVhand.TargetAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandFirstFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}放定位命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}放定位命令放货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "3")
                        {
                            if (RGVhand.SourceAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandFirstFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}取货命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}取货命令取货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "4")
                        {
                            if (RGVhand.TargetAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandFirstFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}放货命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}放货命令放货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "5")
                        {
                            if (RGVhand.TargetAddress != null && RGVhand.TargetAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress),
                                    PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandFirstFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}取放货命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}取放货命令放货位和取货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "6")
                        {
                            if (RGVhand.TargetAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandFirstFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}退命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}退回命令放货位不能为空");
                            }
                        }
                        else
                        {
                            return content.Error($"{device.DeviceName}未知任务命令");
                        }
                    }
                    else
                    {
                        CommonRGV RGVcommand = (CommonRGV)device;
                        if (RGVhand.TaskType == "1")
                        {
                            if (RGVhand.SourceAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandSecondFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}取定位命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}取定位命令取货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "2")
                        {
                            if (RGVhand.TargetAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandSecondFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}放定位命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}放定位命令放货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "3")
                        {
                            if (RGVhand.SourceAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandSecondFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}取货命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}取货命令取货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "4")
                        {
                            if (RGVhand.TargetAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandSecondFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}放货命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}放货命令放货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "5")
                        {
                            if (RGVhand.TargetAddress != null && RGVhand.TargetAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress),
                                    PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandSecondFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}取放货命令下发成功");
                            }
                            else
                            {
                                return content.Error("取放货命令放货位和取货位不能为空");
                            }
                        }
                        else if (RGVhand.TaskType == "6")
                        {
                            if (RGVhand.TargetAddress != null)
                            {
                                RGVTaskCommand command = new RGVTaskCommand()
                                {
                                    PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress),
                                    TaskType = (byte)Convert.ToSByte(RGVhand.TaskType),
                                };
                                SendCommandSecondFloor(RGVcommand, command);
                                return content.OK($"{device.DeviceName}退回命令下发成功");
                            }
                            else
                            {
                                return content.Error($"{device.DeviceName}退回命令放货位不能为空");
                            }
                        }
                        else
                        {
                            return content.Error($"{device.DeviceName}未知任务命令");
                        }
                    }
                }
                return content.Error("未找到设备信息请联系IT");
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
        public WebResponseContent RGVReset(string DeviceCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
                if (device != null)
                {
                    if (DeviceCode == "RGV01" || DeviceCode == "RGV02")
                    {
                        CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9));
                    }
                    else
                    {
                        CommonRGV commonRGV = (CommonRGV)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9));
                    }
                    return content.OK($"{device.DeviceName}复位成功");
                }
                return content.Error("未找到设备信息请联系IT");
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
        public WebResponseContent RGVEmergencyStop(string DeviceCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
                if (device != null)
                {
                    if (DeviceCode == "RGV01" || DeviceCode == "RGV02")
                    {
                        CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(11));
                    }
                    else
                    {
                        CommonRGV commonRGV = (CommonRGV)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(11));
                    }
                    return content.OK($"{device.DeviceName}停止成功");
                }
                return content.Error("未找到设备信息请联系IT");
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
        public WebResponseContent RGVCancel(string DeviceCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
                if (device != null)
                {
                    if (DeviceCode == "RGV01" || DeviceCode == "RGV02")
                    {
                        CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9));
                    }
                    else
                    {
                        CommonRGV commonRGV = (CommonRGV)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9));
                    }
                    return content.OK($"{device.DeviceName}中断成功");
                }
                return content.Error("未找到设备信息请联系IT");
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
        public WebResponseContent RGVInitialize(string DeviceCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
                if (device != null)
                {
                    if (DeviceCode == "RGV01" || DeviceCode == "RGV02")
                    {
                        CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9));
                    }
                    else
                    {
                        CommonRGV commonRGV = (CommonRGV)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9));
                    }
                    return content.OK($"{device.DeviceName}初始化成功");
                }
                return content.Error("未找到设备信息请联系IT");
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
        public WebResponseContent RGVPause(string DeviceCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
                if (device != null)
                {
                    if (DeviceCode == "RGV01" || DeviceCode == "RGV02")
                    {
                        CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(10));
                    }
                    else
                    {
                        CommonRGV commonRGV = (CommonRGV)device;
                        commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(10));
                    }
                    return content.OK($"{device.DeviceName}暂停成功");
                }
                return content.Error("未找到设备信息请联系IT");
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
        public void SendCommandFirstFloor(CommonRGV_FirstFloor commonRGV, RGVTaskCommand? rgvTaskCommand)
        {
            commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(1));
            Thread.Sleep(100);
            commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, (byte)Convert.ToSByte(rgvTaskCommand.PutcargoLocation));
            Thread.Sleep(100);
            commonRGV.SetValue(StackerCraneDBName.PickupLocation, (byte)Convert.ToSByte(rgvTaskCommand.PickupLocation));
            Thread.Sleep(100);
            commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(rgvTaskCommand.TaskType));
        }
        public void SendCommandSecondFloor(CommonRGV commonRGV, RGVTaskCommand? rgvTaskCommand)
        {
            commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(1));
            Thread.Sleep(100);
            commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, (byte)Convert.ToSByte(rgvTaskCommand.PutcargoLocation));
            Thread.Sleep(100);
            commonRGV.SetValue(StackerCraneDBName.PickupLocation, (byte)Convert.ToSByte(rgvTaskCommand.PickupLocation));
            Thread.Sleep(100);
            commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(rgvTaskCommand.TaskType));
        }
        public class RGVTaskCommand
        {
            #region <Public Menber>
            /// <summary>
            /// å–货位
            /// </summary>
            public byte PickupLocation { get; set; }
            /// <summary>
            /// æ”¾è´§ä½
            /// </summary>
            public byte PutcargoLocation { get; set; }
            /// <summary>
            /// ä»»åŠ¡ç±»åž‹
            /// </summary>
            public byte TaskType { get; set; }
            /// <summary>
            /// é¢„ç•™
            /// </summary>
            public byte Spare { get; set; }
            /// <summary>
            /// ä»»åŠ¡å·
            /// </summary>
            public short TaskNum { get; set; }
            #endregion <Public Menber>
        }
        #endregion
    }