$npx -y skills add easyzoom/aix-skills --skill freemodbus-integrationUse when integrating, porting, configuring, or debugging FreeModbus RTU, ASCII, TCP, serial ports, timers, events, register callbacks, or Modbus protocol issues
| 1 | # FreeModbus Integration |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill to integrate FreeModbus by proving the port layer first: serial/TCP transport, timing, event dispatch, and register callbacks. Modbus bugs are often timing, endian, addressing, or task-context problems rather than protocol logic. |
| 6 | |
| 7 | ## When To Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - The user wants to add or debug FreeModbus RTU, ASCII, or TCP. |
| 12 | - The issue involves `portserial.c`, `porttimer.c`, `portevent.c`, register callbacks, CRC errors, timeouts, slave ID, function codes, or Modbus TCP/lwIP integration. |
| 13 | - A device does not respond, responds with exception codes, or has wrong register values. |
| 14 | |
| 15 | Do not use this skill when the UART or network transport is not verified. Use serial or lwIP skills first if the lower layer is unknown. |
| 16 | |
| 17 | ## First Questions |
| 18 | |
| 19 | Ask for: |
| 20 | |
| 21 | - Mode: RTU, ASCII, TCP, master, slave, or gateway. |
| 22 | - MCU/RTOS/compiler and FreeModbus fork/version. |
| 23 | - Transport: UART/RS-485, TCP/lwIP, or custom. |
| 24 | - Baud, parity, stop bits, DE/RE control, slave ID, and timeout settings. |
| 25 | - Register map and callback code. |
| 26 | - Logic analyzer, serial capture, Modbus poll output, or exception codes. |
| 27 | |
| 28 | ## Integration Checklist |
| 29 | |
| 30 | 1. Prove transport timing. |
| 31 | For RTU, verify baud, parity, stop bits, inter-frame gap, and RS-485 direction control. |
| 32 | |
| 33 | 1. Implement port files. |
| 34 | Serial, timer, and event callbacks must match the target scheduler and ISR rules. |
| 35 | |
| 36 | 1. Confirm protocol mode. |
| 37 | RTU, ASCII, and TCP have different framing, timing, and porting requirements. |
| 38 | |
| 39 | 1. Validate register callbacks. |
| 40 | Holding/input/coils/discrete callbacks must map Modbus addresses to internal storage correctly. |
| 41 | |
| 42 | 1. Check address and endian assumptions. |
| 43 | Modbus register numbering, zero-based offsets, word order, and byte order must be explicit. |
| 44 | |
| 45 | 1. Test one function at a time. |
| 46 | Start with a simple read holding register before adding writes, coils, or TCP gateway logic. |
| 47 | |
| 48 | ## Common Failures |
| 49 | |
| 50 | - RS-485 transmit enable timing cuts off the last byte. |
| 51 | - Timer tick is wrong, breaking RTU frame gap detection. |
| 52 | - Register addresses are off by one. |
| 53 | - Callback returns the wrong exception code or byte count. |
| 54 | - Modbus TCP works but RTU fails due to serial timing. |
| 55 | - Event handling blocks inside ISR or wrong task context. |
| 56 | |
| 57 | ## Verification |
| 58 | |
| 59 | Before claiming FreeModbus works: |
| 60 | |
| 61 | - State mode, role, slave ID, baud/network settings, and register map. |
| 62 | - Confirm one read and one write if writes are in scope. |
| 63 | - Confirm CRC or TCP framing is valid using capture/tool evidence. |
| 64 | - Confirm timeout and exception behavior. |
| 65 | - State RS-485 direction control and timer source when RTU is used. |
| 66 | |
| 67 | ## Example |
| 68 | |
| 69 | User: |
| 70 | |
| 71 | ```text |
| 72 | FreeModbus RTU 能收到包但主站一直超时。 |
| 73 | ``` |
| 74 | |
| 75 | Agent: |
| 76 | |
| 77 | 1. Asks for UART settings, RS-485 DE/RE control, timer port, slave ID, and bus capture. |
| 78 | 1. Checks frame gap timer and direction timing before register callbacks. |
| 79 | 1. Verifies a single read holding register with known data. |