{"record":{"id":"a5bcc8bea8f5cc99","repo":"YunaiV/ruoyi-vue-pro","slug":"error-a5bcc8","errorCode":null,"errorMessage":"不支持的功能码: {}","messagePattern":"不支持的功能码: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpClientUtils.java","lineNumber":141,"sourceCode":"        });\n    }\n\n    /**\n     * 创建读取请求\n     */\n    @SuppressWarnings(\"EnhancedSwitchMigration\")\n    private static ModbusRequest createReadRequest(Integer functionCode, Integer address, Integer count) {\n        switch (functionCode) {\n            case FC_READ_COILS:\n                return new ReadCoilsRequest(address, count);\n            case FC_READ_DISCRETE_INPUTS:\n                return new ReadInputDiscretesRequest(address, count);\n            case FC_READ_HOLDING_REGISTERS:\n                return new ReadMultipleRegistersRequest(address, count);\n            case FC_READ_INPUT_REGISTERS:\n                return new ReadInputRegistersRequest(address, count);\n            default:\n                throw new IllegalArgumentException(\"不支持的功能码: \" + functionCode);\n        }\n    }\n\n    /**\n     * 创建写入请求\n     */\n    @SuppressWarnings(\"EnhancedSwitchMigration\")\n    private static ModbusRequest createWriteRequest(Integer functionCode, Integer address, Integer count, int[] values) {\n        switch (functionCode) {\n            case FC_READ_COILS: // 写线圈（使用功能码 5 或 15）\n                if (count == 1) {\n                    return new WriteCoilRequest(address, values[0] != 0);\n                } else {\n                    BitVector bv = new BitVector(count);\n                    for (int i = 0; i < Math.min(values.length, count); i++) {\n                        bv.setBit(i, values[i] != 0);\n                    }\n                    return new WriteMultipleCoilsRequest(address, bv);","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/YunaiV/ruoyi-vue-pro/blob/0418084e222612af2fc1141f566af454f9236ab1/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpClientUtils.java#L123-L159","documentation":"createReadRequest() only accepts the four Modbus read function codes: FC1 (read coils), FC2 (read discrete inputs), FC3 (read holding registers), FC4 (read input registers). Any other integer value hits the default branch and throws IllegalArgumentException. This means the point/device config supplied a functionCode outside {1,2,3,4} for a read operation.","triggerScenarios":"point.getFunctionCode() returns a write FC (5,6,15,16), 0 (default/unset), null auto-unboxed to NPE (caught upstream then re-wrapped), or any non-standard code; a read is then attempted.","commonSituations":"Device config accidentally uses a write function code for a read point; functionCode column defaulted to 0 in the DB; vendor uses a non-standard/custom function code for reads.","solutions":["Set the point functionCode to 1, 2, 3, or 4 (the standard Modbus read codes) per the device register map.","Add config-load validation rejecting points whose functionCode is not in {1,2,3,4} for read points.","If the device uses a custom function code (e.g. FC65), use a protocol variant that supports it (the Modbus TCP Server protocol uses a custom FC for auth) rather than the generic read path."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before reading, ensure the function code is a supported read code\nif (functionCode == null || functionCode < 1 || functionCode > 4) {\n    throw new IllegalArgumentException(\"读取功能码必须在 1-4 之间, 当前: \" + functionCode);\n}","typeGuard":"boolean isSupportedReadFc(Integer fc) {\n    return fc != null && fc >= 1 && fc <= 4;\n}","tryCatchPattern":null,"preventionTips":["Validate functionCode at device-config load time, rejecting points outside {1,2,3,4} for reads.","Default functionCode to a sane value (3 = holding registers) rather than 0.","Add a config integrity unit test that asserts all point function codes are valid for their access direction."],"tags":["modbus","config","validation"],"backgroundTag":null,"analyzedSha":"0418084e222612af2fc1141f566af454f9236ab1","analyzedAt":"2026-08-14T00:56:18.412Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}