{"record":{"id":"64d8749049be0da0","repo":"YunaiV/yudao-cloud","slug":"error-64d874","errorCode":null,"errorMessage":"不支持的功能码: {}","messagePattern":"不支持的功能码: (.+?)","errorType":"exception","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/yudao-cloud/blob/477be9dd49ab7223a972a6abdff0684d6423dec3/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":"IotModbusTcpClientUtils.createReadRequest switches on the function code and only maps the four Modbus read codes — FC_READ_COILS (01), FC_READ_DISCRETE_INPUTS (02), FC_READ_HOLDING_REGISTERS (03), FC_READ_INPUT_REGISTERS (04). Any other value (write codes 05/06/0F/10, 0, null, or exotic codes) hits the default branch and throws IllegalArgumentException '不支持的功能码'. The code comes from the IoT thing-model point configuration.","triggerScenarios":"A read/poll issued against a point whose functionCode is a write code (05, 06, 15, 16); point created with functionCode 0/null; typo in the FC field during bulk point import; using a nonstandard vendor FC.","commonSituations":"Bulk-importing thing model points with wrong FC column; copy-pasting a register point and forgetting to change its FC; device doc listing decimal vs hex FCs (16 entered where 0x10=16 is meant inconsistently).","solutions":["Set the point's function code to one of 1, 2, 3, 4 for readable points","Use write codes (5, 6, 15, 16) only for points that are written, and never route reads to them","Validate the FC column when importing points in bulk (1-4 for read, 5/6/15/16 for write)"],"exampleFix":"// before: holding-register point given a write FC\n{\"identifier\":\"temp\",\"functionCode\":6}\n\n// after\n{\"identifier\":\"temp\",\"functionCode\":3} // FC3 = read holding registers","handlingStrategy":"type-guard","validationCode":"Set<Integer> READABLE_FC = Set.of(1, 2, 3, 4);\nif (!READABLE_FC.contains(point.getFunctionCode())) {\n    throw new IllegalArgumentException(\"点位 functionCode=\" + point.getFunctionCode()\n        + \" 不支持读取 (需 01/02/03/04)\");\n}","typeGuard":"boolean isReadableFunctionCode(Integer fc) {\n    return fc != null && Set.of(1, 2, 3, 4).contains(fc);\n}","tryCatchPattern":null,"preventionTips":["Validate FC on point creation: reads only for FC 1-4, writes only via 5/6/15/16","Bulk-import with a FC whitelist check per point","Watch decimal-vs-hex confusion (16 vs 0x10) when transcribing device manuals"],"tags":["iot","modbus","function-code","read","thing-model"],"backgroundTag":null,"analyzedSha":"477be9dd49ab7223a972a6abdff0684d6423dec3","analyzedAt":"2026-08-14T13:35:31.121Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}