ModbusTCP implicit declaration of function

vydesaster
Posts: 1
Joined: Mon Jul 07, 2025 5:38 pm

ModbusTCP implicit declaration of function

Postby vydesaster » Mon Jul 07, 2025 5:44 pm

I am using Visual Studio Code with ESP-IDF and the ESP Modbus library. I want to create a modbus tcp client. The following code gives me the error "error: implicit declaration of function 'mbc_slave_init_tcp'; did you mean 'mbc_slave_init_iface'?"

Code: Select all

#include <stdio.h>
#include "driver/gpio.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"

#if __has_include("esp_mac.h")
#include "esp_mac.h"
#endif

#include "wifi_manager.h"

#include "mbcontroller.h"

// Modbus server parameters
#define MB_PORT_TCP      502
#define MB_DEVICE_ADDR   1

// Holding registers (read/write)
#define HOLD_REG_START   0
#define HOLD_REG_COUNT   4
uint16_t holding_regs[HOLD_REG_COUNT] = {0, 0, 0, 0};

// Input registers (read only)
#define INPUT_REG_START  0
#define INPUT_REG_COUNT  7
uint16_t input_regs[INPUT_REG_COUNT] = {0, 0, 0, 0, 0, 0, 0};

// Calback function for wifi manager
void cb_connection_ok(void *pvParameter)
{
	ip_event_got_ip_t* param = (ip_event_got_ip_t*)pvParameter;

	/* transform IP to human readable string */
	char str_ip[16];
	esp_ip4addr_ntoa(&param->ip_info.ip, str_ip, IP4ADDR_STRLEN_MAX);

	ESP_LOGI("WIFI Manager", "I have a connection and my IP is %s!", str_ip);
}

//////////////////////////////////////////////////
// Main function
//////////////////////////////////////////////////  
void app_main(void)
{
    // Start wifi manager and set callback function
    wifi_manager_start();
    wifi_manager_set_callback(WM_EVENT_STA_GOT_IP, &cb_connection_ok);
    
    // Start and configure ModbusTCP server
    void* slave_handler = NULL;

    esp_err_t err = mbc_slave_init_tcp(&slave_handler);
    if (slave_handler == NULL || err != ESP_OK)
    {
        ESP_LOGE("ModbusTCP", "ModbusTCP controller initialization fail.");
        return;
    }
    ESP_LOGI("ModbusTCP", "ModbusTCP controller initialized.");

    // Main loop
    while (1)
    {

    }
}
I do not know what causes the problem.

Who is online

Users browsing this forum: ChatGPT-User, PerplexityBot, PetalBot and 2 guests