wanshenmean
6 天以前 37acb8358f5602a9013ee29c04a45e33483c2329
fix: 修复PLC字符串解析和任务处理逻辑

修复DeviceCommand中字符串解析逻辑,处理长度不一致情况
调整ConveyorLine任务处理逻辑,优化条件判断
添加Siemens通信中对byte数组类型的支持
更新.gitignore文件合并Visual Studio相关配置
修改LocationInfoService中库位编码生成规则
已添加2个文件
已修改8个文件
152 ■■■■ 文件已修改
Code/WCS/WIDESEAWCS_Server/.editorconfig 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/.gitignore 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/.vscode/launch.json 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/.vscode/tasks.json 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensDBDataType.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/DeviceBase/DeviceCommand.cs 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLine/ConveyorLineTaskCommandNew.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/.editorconfig
@@ -1,4 +1,4 @@
[*.cs]
# CS8618: åœ¨é€€å‡ºæž„造函数时,不可为 null çš„字段必须包含非 null å€¼ã€‚请考虑声明为可以为 null。
dotnet_diagnostic.CS8618.severity = none
# CS8600: å°† null å­—面量或可能为 null çš„值转换为非 null ç±»åž‹ã€‚
dotnet_diagnostic.CS8600.severity = silent
Code/WCS/WIDESEAWCS_Server/.gitignore
@@ -13,14 +13,8 @@
[Ll]og/
[Ll]ogs/
# Visual Studio
# Visual Studio and User-specific files
.vs/
*.user
*.suo
*.userosscache
*.sln.docstates
# User-specific files
*.rsuser
*.suo
*.user
Code/WCS/WIDESEAWCS_Server/.vscode/launch.json
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,35 @@
{
    "version": "0.2.0",
    "configurations": [
        {
            // ä½¿ç”¨ IntelliSense æ‰¾å‡º C# è°ƒè¯•存在哪些属性
            // å°†æ‚¬åœç”¨äºŽçŽ°æœ‰å±žæ€§çš„è¯´æ˜Ž
            // æœ‰å…³è¯¦ç»†ä¿¡æ¯ï¼Œè¯·è®¿é—® https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md。
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // å¦‚果已更改目标框架,请确保更新程序路径。
            "program": "${workspaceFolder}/WIDESEAWCS_Server/bin/Debug/net8.0/WIDESEAWCS_Server.dll",
            "args": [],
            "cwd": "${workspaceFolder}/WIDESEAWCS_Server",
            "stopAtEntry": false,
            // å¯ç”¨åœ¨å¯åЍ ASP.NET Core æ—¶å¯åЍ Web æµè§ˆå™¨ã€‚有关详细信息: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach"
        }
    ]
}
Code/WCS/WIDESEAWCS_Server/.vscode/tasks.json
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,41 @@
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary;ForceNoAlign"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary;ForceNoAlign"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "--project",
                "${workspaceFolder}/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensDBDataType.cs
@@ -84,6 +84,11 @@
        /// 32位无符号整型
        /// </summary>
        public const string DataType_UDInt = "udint";
        /// <summary>
        /// å­—节数组
        /// </summary>
        public const string DataType_ByteArray = "byte[]";
        #endregion <Const>
        /// <summary>
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Communicator/Siemens/SiemensS7Communicator.cs
@@ -242,6 +242,8 @@
                        return plc.Write(address, Convert.ToString(value));
                    case TypeCode.Char:
                        return plc.Write(address, Convert.ToChar(value));
                    //case TypeCode.arr:
                    //    return plc.Write(address, Convert.ToChar(value));
                    default:
                        if (value is int[])
                        {
@@ -673,6 +675,21 @@
                case SiemensDBDataType.DataType_Char:
                    break;
                case SiemensDBDataType.DataType_ByteArray:
                    {
                        byte[] writeVal;
                        try
                        {
                            writeVal = Encoding.UTF8.GetBytes(value.ToString());
                        }
                        catch (Exception ex)
                        {
                            throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex);
                        }
                        obj = GetResult(Write(address, writeVal), address, writeVal);
                    }
                    break;
                default:
                    throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, dataType, address), CommunicationErrorType.TypeError);
            }
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/DeviceBase/DeviceCommand.cs
@@ -23,6 +23,7 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core.LogHelper;
namespace WIDESEAWCS_QuartzJob.DeviceBase
{
@@ -160,18 +161,23 @@
                    case TypeCode.String:
                        ushort dataLength = CheckStringAttribute(propertyInfo);
                        //if (dataLength - 2 != Content[index])
                        //{
                        //    throw new Exception($"读取PLC字符串定义长度【{Content[index]}】与对象【{GetType().Name}】属性【{propertyInfo.Name}】特性定义字符串长度【{dataLength}】不一致");
                        //}
                        if (dataLength - 2 != Content[index])
                        {
                            //throw new Exception($"读取PLC字符串定义长度【{Content[index]}】与对象【{GetType().Name}】属性【{propertyInfo.Name}】特性定义字符串长度【{dataLength}】不一致");
                            //QuartzLogger.Debug($"读取PLC字符串定义长度【{Content[index]}】与对象【{GetType().Name}】属性【{propertyInfo.Name}】特性定义字符串长度【{dataLength}】不一致");
                        //if (Content[index + 1] > Content.Length - index - 2)
                        //{
                        //    throw new Exception($"读取PLC字符串实际长度【{Content[index + 1]}】超出当前byte数组长度,索引:【{index}】,字符串起始索引:【{index + 2}】,数组长度:【{Content.Length}】,解析长度:【{Content.Length - index - 2}】");
                        //}
                            propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index, dataLength).Trim().Replace("\0", "").Replace("\\u000","").Trim());
                            index += dataLength;
                            break;
                        }
                        // propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index + 2, Content[index + 1] > 0 ? Content[index + 1] : dataLength - 2));
                        propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index, dataLength - 2));
                        if (Content[index + 1] > Content.Length - index - 2)
                        {
                            throw new Exception($"读取PLC字符串实际长度【{Content[index + 1]}】超出当前byte数组长度,索引:【{index}】,字符串起始索引:【{index + 2}】,数组长度:【{Content.Length}】,解析长度:【{Content.Length - index - 2}】");
                        }
                        propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index + 2, Content[index + 1] > 0 ? Content[index + 1] : dataLength - 2));
                        //propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index, dataLength - 2));
                        index += dataLength;
                        break;
                    default:
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
@@ -4,6 +4,7 @@
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
using System.Text;
using System.Text.Json;
using WIDESEA_Core;
using WIDESEAWCS_Common.TaskEnum;
@@ -157,7 +158,7 @@
                            {
                                _logger.LogDebug("Execute:子设备 {ChildDeviceCode} å‘½ä»¤ä¸ºç©ºï¼Œè·³è¿‡", childDeviceCode);
                                QuartzLogger.Debug($"子设备 {childDeviceCode} å‘½ä»¤ä¸ºç©ºï¼Œè·³è¿‡", conveyorLine.DeviceCode);
                                return Task.CompletedTask;
                                continue;
                            }
                            // å¦‚æžœ WCS_ACK ä¸º 1,先清除(表示处理过上一次请求)
@@ -173,7 +174,7 @@
                            if (checkPalletPositions.Any(x => x.Code == childDeviceCode))
                            {
                                // æ£€æŸ¥è¾“送线状态(是否有托盘)
                                if (command.CV_State == 1)
                                if (command.CV_State == 2)
                                {
                                    // æ£€æŸ¥è¯¥ä½ç½®æ˜¯å¦å·²æœ‰ä»»åŠ¡
                                    var existingTask = _taskService.Db.Queryable<Dt_Task>().First(x => x.TargetAddress == childDeviceCode);
@@ -206,8 +207,6 @@
                            // åªæœ‰å½“ PLC_STB ä¸º 1 æ—¶æ‰å¤„理任务
                            if (command.PLC_STB != 1)
                            {
                                //_logger.LogDebug("Execute:子设备 {ChildDeviceCode} PLC_STB ä¸ä¸º1,跳过", childDeviceCode);
                                //QuartzLogger.Debug($"子设备 {childDeviceCode} PLC_STB ä¸ä¸º1,跳过", conveyorLine.DeviceCode);
                                return Task.CompletedTask;
                            }
@@ -222,7 +221,7 @@
                            }
                            // ========== å¤„理已有任务号的情况 ==========
                            if (command.TaskNo > 0)
                            if (command.TaskNo > 0 && !command.Barcode.IsNullOrEmpty())
                            {
                                // æŸ¥è¯¢æ­£åœ¨æ‰§è¡Œçš„任务
                                Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode);
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLine/ConveyorLineTaskCommandNew.cs
@@ -154,12 +154,12 @@
        public byte Last_pallet { get; set; }
        /// <summary>
        /// æ‰˜ç›˜æ¡ç ï¼ˆ22个字符)
        /// æ‰˜ç›˜æ¡ç ï¼ˆ20个字符)
        /// </summary>
        /// <remarks>
        /// å­˜å‚¨æ‰˜ç›˜çš„æ¡ç ä¿¡æ¯ï¼Œç”¨äºŽè´§ç‰©è¿½è¸ªå’Œåº“位管理。
        /// </remarks>
        [DataLength(22)]
        [DataLength(20)]
        public string Barcode { get; set; }
    }
}
Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
@@ -527,7 +527,8 @@
                EnableStatus = EnableStatusEnum.Normal.GetHashCode(),
                LocationStatus = LocationStatusEnum.Free.GetHashCode(),
                LocationType = LocationTypeEnum.Undefined.GetHashCode(),
                LocationCode = $"{roadwayNo}-{row:D3}-{col:D3}-{layer:D3}",
                //LocationCode = $"{roadwayNo}-{row:D3}-{col:D3}-{layer:D3}",
                LocationCode = $"{row:D3}-{col:D3}-{layer:D3}",
                LocationName = $"{roadwayNo}巷道{row:D3}行{col:D3}列{layer:D3}层{depth:D2}æ·±"
            };
        }