Logo : Esp Modbus Skill

Esp Modbus Skill

Communauté
JasonYANG170
esp-modbus-skill

AI Skill for Espressif esp-modbus (Modbus RTU / ASCII / TCP) firmware development on ESP-IDF. Used when users need to create, modify, or debug Modbus master/slave applications, configure the Data Dictionary and register area descriptors, map CIDs to Modbus registers, register custom function-code handlers, or resolve Modbus communication errors on ESP32 family chips. Trigger words: "Modbus", "RTU", "ASCII", "Modbus TCP", "RS485", "esp-modbus", "freemodbus", "Modbus 主站", "Modbus 从站", "保持寄存器", "输入寄存器", "线圈", "离散输入", "Holding", "Coil", "mbc_master", "mbc_slave", "Data Dictionary", "数据字典"

Présentation

ÉditeurJasonYANG170
Dépôtesp-dev-skill
Nom de la compétenceesp-modbus-skill
Étoiles
32
Forks
3
Fichiers inclus
16
LicenceApache-2.0
Liens
  • Instructions en Markdown

    Un fichier SKILL.md que le modèle charge à la demande : il ne consomme donc des tokens que lorsqu’une demande correspond réellement à la compétence.

  • Compatible avec tous les LLM

    Les compétences IA sont rédigées en Markdown et non sous forme de code propre à un fournisseur. Elles fonctionnent donc avec GPT, Claude, Gemini, Grok ou un modèle local.

  • Fichiers inclus : 16

    Des scripts, des gabarits et des références que le modèle peut consulter pendant son travail. Les fichiers sont en lecture seule et ne sont jamais exécutés.

  • Open source

    Publiée par JasonYANG170 sur GitHub. Consultez les sources avant de l’installer.

Installation

Installez la compétence IA Esp Modbus Skill dans TypingMind pour l’utiliser avec n’importe quel LLM, ou ajoutez-la à un autre agent capable de lire SKILL.md.

1

Installer dans TypingMind

TypingMind installe une compétence directement depuis son dossier GitHub : l’application lit SKILL.md, regroupe les fichiers de ressources et enregistre le tout localement.

  1. Ouvrez l’application et accédez à Plugins → Compétences.
  2. Choisissez « Installer depuis GitHub ».
  3. Copiez l’URL ci-dessous, qui pointe vers le dossier de la compétence, puis collez-la et confirmez.
    https://github.com/JasonYANG170/esp-dev-skill/tree/main/repos/esp-modbus
  4. Activez la compétence dans chaque discussion où vous souhaitez pouvoir l’utiliser.
Plugins → Compétences → Ajouter une compétence → Via une URL GitHub, puis collez l’URL du dossier et appuyez sur Continuer.
2

Installer dans un autre agent

Tout agent capable de lire le format Agent Skills peut utiliser cette compétence : copiez le dossier dans le répertoire des compétences de cet agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/JasonYANG170/esp-dev-skill.git /tmp/esp-dev-skill
mkdir -p .claude/skills
cp -r /tmp/esp-dev-skill/repos/esp-modbus .claude/skills/esp-modbus-skill
Redémarrez Claude Code après la copie pour que la nouvelle compétence soit prise en compte.

Utilisez cette compétence dans TypingMind

Activez Esp Modbus Skill dans n’importe quelle discussion TypingMind et le modèle s’occupe du reste. Le nom et la description de la compétence figurent dans le prompt système. Dès qu’une demande correspond, le modèle charge lui-même l’intégralité des instructions : vous n’avez jamais à l’invoquer manuellement, et elle ne consomme aucun token tant qu’elle n’est pas utilisée.

Le modèle charge automatiquement Esp Modbus Skill dès qu’une demande correspond à cette compétence.

Compatible avec tous les modèles IA

Les compétences IA sont de simples instructions Markdown, et non du code propre à un fournisseur. Ainsi, la compétence Esp Modbus Skill n’est pas liée au modèle pour lequel elle a été conçue. Installez-la une seule fois dans TypingMind et utilisez-la avec GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ou un modèle local que vous exécutez vous-même, le tout avec vos propres clés API.

  • Chargée uniquement en cas de besoin

    Le prompt système ne contient que le nom et la description. Les instructions sont récupérées à la première demande correspondante : une compétence inutilisée ne coûte donc rien.

  • Changez de modèle en cours de discussion

    La compétence étant constituée d’instructions et non de code, elle reste fonctionnelle lorsque vous changez de modèle : le nouveau modèle lit le même fichier SKILL.md.

Instructions de la compétence

Voici le contenu de SKILL.md que le modèle charge. Lisez-le avant l’installation : une compétence contient des instructions que votre modèle suivra.

esp-modbus-skill

AI Skill for developing firmware with the Espressif esp-modbus library (component version v2.x.x). Covers Modbus RTU, ASCII and TCP, the v2 instance-based master/slave API (mbc_*_create_* returning a handle), the Data Dictionary (CID → register mapping), slave register-area descriptors, custom function-code handlers, the endianness/extended-types conversion API, and the Kconfig configuration keys. Every API name, struct, macro, and code snippet below is grounded in the repository's own docs/, headers under modbus/mb_controller/common/include/, and the examples under examples/.

Core Principles

  1. v2 is instance-based — Every master/slave object is created by mbc_master_create_serial / mbc_master_create_tcp / mbc_slave_create_serial / mbc_slave_create_tcp, which fill a void *handle. That handle is the first argument of every later API call for that object. The legacy single-instance global-handle API is gone.
  2. Never guess APIs — All public functions live in mbcontroller.h → esp_modbus_master.h / esp_modbus_slave.h. If a function is not there, it does not exist; do not invent it.
  3. Communication mode is compile-time + per-instance — The serial modes (RTU, ASCII) and TCP must be enabled at compile time (CONFIG_FMB_COMM_MODE_RTU_EN, CONFIG_FMB_COMM_MODE_ASCII_EN, CONFIG_FMB_COMM_MODE_TCP_EN). The per-instance mode is then set in mb_communication_info_t (.ser_opts.mode = MB_RTU / MB_ASCII, or .tcp_opts.mode = MB_TCP).
  4. Master needs a Data Dictionary — The master does not read raw registers; it reads CIDs. A mb_parameter_descriptor_t device_parameters[] table must be registered via mbc_master_set_descriptor() before mbc_master_start(). Each CID maps to a slave UID + register type + start + size + data type.
  5. Slave needs register-area descriptors — A slave must register at least one mb_register_area_descriptor_t per register type it wants to serve (Holding/Input/Coil/Discrete) via mbc_slave_set_descriptor(). Unmapped accesses return a Modbus exception.
  6. Initialization order is fixed — create → (set descriptor / register handlers) → uart_set_pin + uart_set_mode(UART_MODE_RS485_HALF_DUPLEX) for serial → start. For master, set_descriptor must happen before start.
  7. RS485 UART setup is the app's job — esp-modbus does not configure pins or half-duplex mode. The app must call uart_set_pin() and uart_set_mode(MB_PORT_NUM, UART_MODE_RS485_HALF_DUPLEX) itself (see serial examples).
  8. Master timeout governs reliability — CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND (or per-instance ser_opts.response_tout_ms / tcp_opts.response_tout_ms) must be greater than the worst-case slave round-trip time, otherwise the master drops in-flight responses and the slave logs a race-condition warning.
  9. Extended data types need a Kconfig flag — The big family of PARAM_TYPE_U32_ABCD, PARAM_TYPE_FLOAT_CDAB, PARAM_TYPE_DOUBLE_HGFEDCBA, etc., and the mb_get_* / mb_set_* endianness helpers, only exist when CONFIG_FMB_EXT_TYPE_SUPPORT=y. On the slave side they require #include "mb_endianness_utils.h" (pulled in automatically when the flag is set).
  10. Access shared slave data under lock — When the stack is active, the app must guard direct reads/writes of the mapped register storage with mbc_slave_lock()/mbc_slave_unlock() (or a FreeRTOS critical section for cross-object sharing).
  11. Custom handlers run in the controller task — mbc_set_handler() callbacks execute in the Modbus controller event task and must be short, non-blocking, and never log heavily; a slow handler makes the slave miss the master's response window.
  12. Destroy on teardown — mbc_master_delete() / mbc_slave_delete() stop the stack and free all tasks/queues. For TCP, also tear down netif/services afterwards.

When to Use

Applicable:

  • Creating a Modbus RTU/ASCII master or slave over RS485 on an ESP32-family chip
  • Creating a Modbus TCP master or slave over Wi-Fi/Ethernet
  • Mapping physical parameters (temperature, humidity, relay state) to CIDs via the Data Dictionary
  • Implementing vendor-specific (non-standard) Modbus function codes via custom handlers
  • Reading/writing 32-bit / 64-bit / float / double values with specific byte order (ABCD/CDAB/…)
  • Diagnosing Modbus errors (ESP_ERR_TIMEOUT 0x107, ESP_ERR_NOT_SUPPORTED 0x106, ESP_ERR_INVALID_RESPONSE 0x108, ESP_ERR_INVALID_STATE 0x103)
  • Migrating from the legacy built-in freemodbus component to esp-modbus v2

Not applicable:

  • Non-Modbus serial protocols (plain UART, DMX, proprietary)
  • Bare-metal (non-ESP-IDF) projects — esp-modbus depends on FreeRTOS, UART and lwIP/esp_netif from ESP-IDF
  • Other vendors' Modbus stacks (MicroPython modbus, Linux libmodbus, etc.)
  • PCB / RS485 transceiver schematic design (only the firmware side)

Scenario Quick Reference (Recipes)

When the user's intent matches a scenario below, read the corresponding recipe first — it has the full call chain, step-by-step instructions, real code, and a common-errors table.

Serial (RTU / ASCII over RS485)

recipescenario
recipes/serial_slave.mdBuild a Modbus serial slave (RTU or ASCII): UART + RS485 setup, register-area descriptors, event loop
recipes/serial_master.mdBuild a Modbus serial master: UART + RS485 setup, Data Dictionary, polling loop, teardown

TCP (over Wi-Fi / Ethernet)

recipescenario
recipes/tcp_slave.mdBuild a Modbus TCP slave: netif init, mbc_slave_create_tcp, multi-connection, keep-alive
recipes/tcp_master.mdBuild a Modbus TCP master: slave IP address table, MDNS resolution, mbc_master_create_tcp

Data model & advanced

recipescenario
recipes/data_dictionary.mdAuthor the master Data Dictionary (mb_parameter_descriptor_t), CID enum, OPTS/STR macros, offset macros
recipes/slave_register_areas.mdMap slave storage structs to Modbus areas via mbc_slave_set_descriptor + HOLD_OFFSET macros
recipes/custom_handlers.mdRegister/override function-code handlers with mbc_set_handler / mbc_get_handler / mbc_delete_handler, including the FC 0x41 echo example
recipes/extended_types.mdUse CONFIG_FMB_EXT_TYPE_SUPPORT, the PARAM_TYPE_*_ABCD family, and mb_set_float_abcd / mb_get_uint32_dcba helpers
recipes/slave_device_id.mdSet vendor-specific slave device identification (short UID + running status + vendor data) via mbc_set_slave_id / mbc_get_slave_id for retrieval by master FC 0x11 Report Slave ID

Modbus Register Types & Data Areas

Modbus areamb_param_type_tFunction codes (master)DirectionSize unit
Holding RegistersMB_PARAM_HOLDING0x03 Read, 0x06 Write Single, 0x10 Write Multiple, 0x17 R/W Multipleread/write16-bit register
Input RegistersMB_PARAM_INPUT0x04 Read Inputread-only16-bit register
CoilsMB_PARAM_COIL0x01 Read, 0x05 Write Single, 0x0F Write Multipleread/write1 bit
Discrete InputsMB_PARAM_DISCRETE0x02 Read Discreteread-only1 bit
CustomMB_PARAM_CUSTOMvendor code (e.g. 0x41)n/an/a

The master's mb_size field is in registers (2 bytes) for Holding/Input, and in bits for Coil/Discrete.

Communication Mode / Config Structure Selection

ModeCompile flagmode valueConfig union memberCreate call
Serial RTUCONFIG_FMB_COMM_MODE_RTU_ENMB_RTUmb_communication_info_t::ser_optsmbc_master_create_serial / mbc_slave_create_serial
Serial ASCIICONFIG_FMB_COMM_MODE_ASCII_ENMB_ASCII…::ser_optsmbc_master_create_serial / mbc_slave_create_serial
TCP/IPCONFIG_FMB_COMM_MODE_TCP_EN (needs LWIP_ENABLE)MB_TCP…::tcp_optsmbc_master_create_tcp / mbc_slave_create_tcp

Key Kconfig Quick Reference

SymbolDefaultPurpose
CONFIG_FMB_COMM_MODE_RTU_ENyEnable RTU mode
CONFIG_FMB_COMM_MODE_ASCII_ENyEnable ASCII mode
CONFIG_FMB_COMM_MODE_TCP_ENy (needs LWIP)Enable TCP mode
CONFIG_FMB_TCP_PORT_DEFAULT502Default Modbus TCP port
CONFIG_FMB_TCP_PORT_MAX_CONN5Max simultaneous TCP slave connections
CONFIG_FMB_TCP_CONNECTION_TOUT_SEC2TCP connection (accept) timeout
CONFIG_FMB_TCP_KEEP_ALIVE_TOUT_SEC4TCP keep-alive probe interval
CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND10000Master wait for slave response (ms)
CONFIG_FMB_MASTER_DELAY_MS_CONVERT200Master broadcast convert delay (ms)
CONFIG_FMB_QUEUE_LENGTH50Event task queue length
CONFIG_FMB_PORT_TASK_STACK_SIZE4096Port rx/tx task stack
CONFIG_FMB_PORT_TASK_PRIO10Port task priority (controller = prio − 1)
CONFIG_FMB_PORT_TASK_AFFINITYCPU0Core affinity (NO_AFFINITY / CPU0 / CPU1)
CONFIG_FMB_BUFFER_SIZE260 (TCP) / 256 (serial)RX/TX buffer size
CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORTyEnable Report Slave ID (FC 0x11)
CONFIG_FMB_CONTROLLER_SLAVE_ID0x00112233Default slave ID value
CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE20Slave parameter-notification queue size
CONFIG_FMB_EXT_TYPE_SUPPORTnEnable extended types + endianness API
CONFIG_FMB_FUNC_HANDLERS_MAX16Max registered function handlers per object
CONFIG_FMB_TIMER_USE_ISR_DISPATCH_METHODnISR dispatch for timer (selects UART_ISR_IN_IRAM)
CONFIG_FMB_MDNS_INTEGRATION_ENABLEyResolve MDNS names in TCP master slave table

Modbus Error Code → esp_err_t Mapping

Modbus erroresp_err_tHexMeaning
MB_ENOERRESP_OK0x0Success
MB_ENOREGESP_ERR_NOT_SUPPORTED0x106Register not supported / exception from slave
MB_ETIMEDOUTESP_ERR_TIMEOUT0x107Slave did not respond in time
MB_EILLFUNC / MB_ERECVDATAESP_ERR_INVALID_RESPONSE0x108Unsupported/incorrect response from slave
MB_EBUSY / MB_EILLSTATE / MB_ENOCONNESP_ERR_INVALID_STATE0x103FSM busy / not connected / critical failure

Critical Pitfalls (Must Read)

These are the most common errors. Violating any of these produces non-working Modbus firmware.

1. Master handle is the first parameter of every call

c
// ❌ WRONG — calling the v1-style no-argument API (does not exist in v2)
mbc_master_start();
mbc_master_get_parameter(CID_TEMP, temp_data, &type);

// ✅ CORRECT — pass the handle returned by mbc_master_create_serial/tcp
static void *master_handle = NULL;
mbc_master_create_serial(&comm, &master_handle);
mbc_master_start(master_handle);
mbc_master_get_parameter(master_handle, CID_TEMP, temp_data, &type);

2. Master: set the descriptor BEFORE start

c
// ❌ WRONG — start before descriptor, reads return ESP_ERR_INVALID_STATE
mbc_master_start(master_handle);
mbc_master_set_descriptor(master_handle, device_parameters, num_device_parameters);

// ✅ CORRECT — descriptor first, then start
mbc_master_set_descriptor(master_handle, device_parameters, num_device_parameters);
uart_set_mode(MB_PORT_NUM, UART_MODE_RS485_HALF_DUPLEX);
mbc_master_start(master_handle);

3. Serial RS485: the app must set pins and half-duplex mode

c
// ❌ WRONG — relying on esp-modbus to configure the UART pins/mode (it does not)
mbc_slave_create_serial(&comm, &slave_handle);
mbc_slave_start(slave_handle);   // no RS485 direction control -> garbage on the line

// ✅ CORRECT — app sets pins and RS485 half-duplex mode itself
mbc_slave_create_serial(&comm, &slave_handle);
ESP_ERROR_CHECK(uart_set_pin(MB_PORT_NUM, CONFIG_MB_UART_TXD,
                             CONFIG_MB_UART_RXD, CONFIG_MB_UART_RTS,
                             UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_set_mode(MB_PORT_NUM, UART_MODE_RS485_HALF_DUPLEX));
mbc_slave_start(slave_handle);

4. Slave: register at least one area per type you want to serve

c
// ❌ WRONG — master reads Holding but slave never called mbc_slave_set_descriptor for HOLDING
//           -> slave returns Modbus exception 0x02 (Illegal Data Address)

// ✅ CORRECT — register the area with correct byte size
mb_register_area_descriptor_t reg_area = {0};
reg_area.type = MB_PARAM_HOLDING;
reg_area.start_offset = 0;
reg_area.address = &holding_reg_params.holding_data0;
reg_area.size = sizeof(float) * 4;          // size is in BYTES
reg_area.access = MB_ACCESS_RW;
ESP_ERROR_CHECK(mbc_slave_set_descriptor(slave_handle, reg_area));

5. Data Dictionary mb_size is registers (2 bytes), param_size is bytes

c
// ❌ WRONG — confusing register count with byte count
{ CID_TEMP, STR("Temp"), STR("C"), 1, MB_PARAM_HOLDING,
  0, 4 /*bytes?*/, 0, PARAM_TYPE_FLOAT, 4, OPTS(0,100,0), PAR_PERMS_READ },

// ✅ CORRECT — mb_size = registers (float = 2 registers), param_size = bytes (float = 4 bytes)
{ CID_TEMP, STR("Temp"), STR("C"), 1, MB_PARAM_HOLDING,
  0, 2 /*registers*/, 0, PARAM_TYPE_FLOAT, 4 /*bytes*/, OPTS(0,100,0),
  PAR_PERMS_READ_WRITE_TRIGGER },

6. Extended types require CONFIG_FMB_EXT_TYPE_SUPPORT=y

c
// ❌ WRONG — using PARAM_TYPE_FLOAT_CDAB without enabling extended types
//   builds fail: 'PARAM_TYPE_FLOAT_CDAB' undeclared, mb_set_float_cdab missing
{ CID_F, STR("F"), STR("--"), 1, MB_PARAM_HOLDING, 0, 2,
  0, PARAM_TYPE_FLOAT_CDAB, 4, OPTS(0,0,0), PAR_PERMS_READ_WRITE_TRIGGER };

// ✅ CORRECT — enable in sdkconfig / menuconfig first
//   CONFIG_FMB_EXT_TYPE_SUPPORT=y
// then the PARAM_TYPE_*_ABCD/CDAB/... enumerators and mb_set_*/mb_get_* exist

7. Master response timeout must beat the slave's round-trip time

c
// ❌ WRONG — 1000 ms timeout while the slave takes 1400 ms to answer
//   slave logs: "handling time [ms]: 1394, exceeds slave response time in master."
//   master reports ESP_ERR_TIMEOUT (0x107) for the first request
.ser_opts.response_tout_ms = 1000;

// ✅ CORRECT — timeout > worst-case RTT; raise CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND
//   or set per-instance response_tout_ms
.ser_opts.response_tout_ms = 0;     // 0 = use CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND (>= 1000 recommended)
// and in menuconfig: CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=5000

8. Guard shared slave storage with lock/unlock

c
// ❌ WRONG — modifying mapped storage while the stack may read/write it -> data race
holding_reg_params.holding_data0 += 1.0f;

// ✅ CORRECT — lock around the access while the stack is active
mbc_slave_lock(slave_handle);
holding_reg_params.holding_data0 += 1.0f;
mbc_slave_unlock(slave_handle);

9. Custom handler must stay short and non-blocking

c
// ❌ WRONG — blocking/logging-heavy handler in the controller task
mb_exception_t my_handler(void *inst, uint8_t *frame, uint16_t *len) {
    vTaskDelay(pdMS_TO_TICKS(50));        // blocks the whole stack
    ESP_LOG_BUFFER_HEXDUMP("HUGE", buf, 4096, ESP_LOG_INFO);  // too verbose
    return MB_EX_NONE;
}

// ✅ CORRECT — minimal work, return quickly
mb_exception_t my_handler(void *inst, uint8_t *frame, uint16_t *len) {
    MB_RETURN_ON_FALSE((frame && len && *len < (MB_CUST_DATA_LEN - 1)),
                       MB_EX_ILLEGAL_DATA_VALUE, TAG, "bad frame");
    strncpy(my_buf, (char *)&frame[1], MB_CUST_DATA_LEN);
    return MB_EX_NONE;
}

10. TCP master slave table must end with NULL

c
// ❌ WRONG — no NULL terminator, master reads past the table -> crash/garbage
char *slave_ip_address_table[] = {
    "01;192.168.1.5;502",
    "02;192.168.1.6;502",
};

// ✅ CORRECT — last entry is NULL
char *slave_ip_address_table[] = {
    "01;mb_slave_tcp_01;502",     // UID;host(or IP);port
    "02;192.168.1.6;1502",
    NULL
};

11. CID and param_key must be unique

c
// ❌ WRONG — two entries share CID 0; mbc_master_get_cid_info returns the wrong one
{ 0, STR("Temp"),   ... }, { 0, STR("Humid"), ... },

// ✅ CORRECT — unique CID and unique param_key; use an enum
enum { CID_TEMP = 0, CID_HUMID, CID_COUNT };
const mb_parameter_descriptor_t device_parameters[] = {
    { CID_TEMP, STR("Temperature"), ... },
    { CID_HUMID, STR("Humidity"),   ... },
};

12. FC 0x17 (Read/Write Multiple) needs the wr_rd_multi_reg_func sub-fields

c
// ❌ WRONG — leaving write fields zero for command 0x17, the write part is lost
mb_param_request_t req = { .slave_addr = 1, .command = 0x17,
                           .reg_start = HOLD_REG_START(holding_data2),
                           .reg_size = 2 };

// ✅ CORRECT — fill wr_reg_start / wr_reg_size (in registers)
mb_param_request_t req = {
    .slave_addr = 1,
    .command = 0x17,
    .reg_start = HOLD_REG_START(holding_data2),     // read start
    .reg_size  = 2,                                  // read length (registers)
    .wr_rd_multi_reg_func.wr_reg_start = HOLD_REG_START(holding_data0), // write start
    .wr_rd_multi_reg_func.wr_reg_size  = 6,          // write length (registers)
};
mbc_master_send_request(master_handle, &req, &read_write_buf);

13. ESP-IDF releases with built-in freemodbus must exclude it

cmake
# ❌ WRONG on older ESP-IDF: link error / wrong API, because the built-in
#    freemodbus component (old single-instance API) shadows esp-modbus v2
# (no EXCLUDE_COMPONENTS line)

# ✅ CORRECT — in the project CMakeLists.txt, before project()
set(EXCLUDE_COMPONENTS freemodbus)

14. TCP master: netif must exist before create_tcp

c
// ❌ WRONG — calling mbc_master_create_tcp before network is up; the
//    .tcp_opts.ip_netif_ptr is NULL -> connection failures
mbc_master_create_tcp(&cfg, &master_handle);   // ip_netif_ptr = NULL
example_connect();

// ✅ CORRECT — bring up netif first, then pass get_example_netif()
example_connect();
mb_communication_info_t cfg = {
    .tcp_opts.port = 502,
    .tcp_opts.mode = MB_TCP,
    .tcp_opts.addr_type = MB_IPV4,
    .tcp_opts.ip_addr_table = (void *)slave_ip_address_table,
    .tcp_opts.ip_netif_ptr = (void *)get_example_netif(),
    ...
};
mbc_master_create_tcp(&cfg, &master_handle);

Execution Workflow

StepNameDescription
1PlanIdentify role (master/slave), transport (serial RTU/ASCII or TCP), target chip, register map
2RecipeRead the matching recipe in recipes/ and follow its call chain end-to-end
3ConfigEnable the right CONFIG_FMB_COMM_MODE_*_EN flags; set CONFIG_FMB_EXT_TYPE_SUPPORT=y if extended types are needed; pick UART pins / netif
4AuthorWrite app_main: build mb_communication_info_t, create handle, (master) set descriptor / (slave) set area descriptors, register custom handlers if any, (serial) set UART pin + RS485 mode, start
5ValidateCheck every API signature in resources/api_reference.md; verify mb_size (registers) vs param_size (bytes); verify slave area byte sizes; verify slave IP table ends with NULL
6Buildidf.py set-target <chip> then idf.py build (CMake)
7Flashidf.py -p <PORT> flash monitor
8DebugWatch for ESP_ERR_TIMEOUT (0x107), ESP_ERR_NOT_SUPPORTED (0x106), ESP_ERR_INVALID_RESPONSE (0x108); check CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND; confirm RS485 wiring and direction (RTS) pin
9TeardownCall mbc_master_delete() / mbc_slave_delete(); for TCP also disconnect netif/services

Step 4 Detail — Project Creation Strategy

When the target directory has no existing project:

  1. Pick the closest example under examples/ and copy it wholesale, then edit main/*.c:
    • Serial slave → examples/serial/mb_serial_slave/
    • Serial master → examples/serial/mb_serial_master/
    • TCP slave → examples/tcp/mb_tcp_slave/
    • TCP master → examples/tcp/mb_tcp_master/
  2. Both master and slave examples depend on the shared examples/mb_example_common/ component (defines holding_reg_params_t, input_reg_params_t, coil_reg_params_t, discrete_reg_params_t and their extern instances). Keep it as a component or inline the structs.
  3. Adjust the Data Dictionary / register areas, the UART pins (or netif), and the slave UID to match the device's register map.
  4. Explain what was copied and why.

When the directory already contains a project: edit files in place; do not overwrite unless asked.


Failure Strategies

SituationAction
API not found in resources/api_reference.mdStop; inform the user it does not exist in esp-modbus v2
ESP_ERR_TIMEOUT (0x107) on master readsRaise CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND / per-instance response_tout_ms above worst-case RTT; check RS485 wiring, RTS direction, baud/parity match
ESP_ERR_NOT_SUPPORTED (0x106) from slaveSlave returned an exception — the requested register is not in any registered area; check Data Dictionary / mbc_slave_set_descriptor coverage
ESP_ERR_INVALID_RESPONSE (0x108)Wrong command for register type, or wrong mb_size; verify function-code ↔ mb_param_type pairing
ESP_ERR_INVALID_STATE (0x103)Stack not started, FSM busy, or TCP slave not connected; check init order and connection state
Slave logs "handling time … exceeds slave response time in master"Race condition: reduce slave request processing time or increase master timeout (see docs/en/overview_messaging_and_mapping.rst "The Race Condition")
Extended-type enum / mb_set_float_abcd missing at buildSet CONFIG_FMB_EXT_TYPE_SUPPORT=y in sdkconfig
TCP master cannot resolve mb_slave_tcp_01Either keep CONFIG_FMB_MDNS_INTEGRATION_ENABLE=y and run an mDNS slave, or switch the IP table to literal IP addresses
Old ESP-IDF link error / wrong APIAdd set(EXCLUDE_COMPONENTS freemodbus) to the project CMakeLists.txt

References

  • Scenario recipes → recipes/ directory
  • API reference (real function signatures) → resources/api_reference.md
  • Kconfig / configuration reference → resources/config_reference.md
  • Consolidated pitfalls → resources/pitfalls.md
  • Example project index → resources/example_list.md
  • Source repo: D:/esp-skill/espressif-repos/esp-modbus (docs in docs/en/, headers in modbus/mb_controller/common/include/, examples in examples/)

Fichiers inclus

Le modèle lit ces fichiers à la demande lorsque la compétence est chargée. Ils sont accessibles en lecture et ne sont jamais exécutés.

Foire aux questions

À quoi sert la compétence IA Esp Modbus Skill ?

AI Skill for Espressif esp-modbus (Modbus RTU / ASCII / TCP) firmware development on ESP-IDF. Used when users need to create, modify, or debug Modbus master/slave applications, configure the Data Dictionary and register area descriptors, map CIDs to Modbus registers, register custom function-code handlers, or resolve Modbus communication errors on ESP32 family chips. Trigger words: "Modbus", "RTU", "ASCII", "Modbus TCP", "RS485", "esp-modbus", "freemodbus", "Modbus 主站", "Modbus 从站", "保持寄存器", "输入寄存器", "线圈", "离散输入", "Holding", "Coil", "mbc_master", "mbc_slave", "Data Dictionary", "数据字典"

Pourquoi utiliser Esp Modbus Skill sur TypingMind ?

Parce que vous l’installez une seule fois pour l’utiliser avec n’importe quel modèle. Esp Modbus Skill se compose de simples instructions en Markdown plutôt que de code propre à un fournisseur. La même compétence fonctionne donc avec GPT-5, Claude, Gemini, Grok ou un modèle local, et vous pouvez changer de modèle en cours de discussion sans perturber son fonctionnement. TypingMind utilise vos propres clés API : vous payez donc directement les fournisseurs plutôt qu’un abonnement par siège, et vos compétences et discussions restent dans votre propre espace de stockage.

Comment installer Esp Modbus Skill dans TypingMind ?

Dans TypingMind, ouvrez Plugins → Compétences → Installer depuis GitHub et collez https://github.com/JasonYANG170/esp-dev-skill/tree/main/repos/esp-modbus. TypingMind lit le fichier SKILL.md, regroupe les fichiers associés et installe le tout sous forme de compétence que vous pouvez activer pour chaque discussion.

Quels modèles d’IA peuvent utiliser Esp Modbus Skill ?

N’importe quel modèle que vous connectez dans TypingMind. Les compétences IA sont de simples instructions en Markdown, et non du code propre à un fournisseur. GPT, Claude, Gemini, Grok et les modèles locaux peuvent donc tous charger cette compétence lorsqu’une demande lui correspond.

Combien de modèles d’IA puis-je utiliser avec Esp Modbus Skill ?

Autant que vous le souhaitez. Vous pouvez utiliser Esp Modbus Skill avec tout modèle qui prend en charge les compétences : GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama et bien d’autres, le tout dans TypingMind avec vos propres clés API.

La compétence IA Esp Modbus Skill est-elle gratuite ?

Oui. Cette compétence est publiée sur GitHub par JasonYANG170 sous licence Apache-2.0. Vous ne payez que votre propre fournisseur d’IA pour les tokens utilisés.

Que sont les compétences IA ?

Une compétence IA est un ensemble d’instructions réutilisables qui apprend à un modèle d’IA à accomplir une tâche précise. Elle suit le format ouvert Agent Skills : un fichier SKILL.md contenant un nom et une description, ainsi que les éventuels scripts, gabarits ou fichiers de référence dont le modèle peut avoir besoin. Le modèle ne lit les instructions que lorsque votre demande correspond à la compétence. Une compétence installée ne coûte donc rien tant qu’elle n’est pas utilisée.

En quoi les compétences IA diffèrent-elles des plugins ou des serveurs MCP ?

Un plugin ou un serveur MCP fournit au modèle de nouveaux outils à appeler : du code qui s’exécute quelque part et renvoie un résultat. Une compétence IA lui apporte plutôt des connaissances et une méthode : comment aborder une tâche, quelles étapes suivre et à quoi ressemble un bon résultat. Les compétences sont de simples instructions en Markdown. Elles ne nécessitent donc ni serveur, ni clé API, ni environnement d’exécution, et fonctionnent avec n’importe quel modèle.

Tout voir

Créez votre propre espace de travail IA dès maintenant

Abonnez-vous à notre newsletter pour être informé des nouvelles fonctionnalités et des prochains cadeaux à gagner 👇