Files
433_STM32/Core/Inc/modbus_tcp_client.h

56 lines
1.4 KiB
C
Raw Normal View History

2026-05-09 19:53:47 +08:00
/**
******************************************************************************
* @file modbus_tcp_client.h
* @brief Modbus TCP ( W5500)
******************************************************************************
*/
#ifndef __MODBUS_TCP_CLIENT_H
#define __MODBUS_TCP_CLIENT_H
#include <stdint.h>
#include <stdbool.h>
#include "main.h"
/* Modbus TCP 配置 */
#if TEST_A701
#define MODBUS_SERVER_IP {192, 168, 6, 4} /* A701 测试服务器 */
#else
#define MODBUS_SERVER_IP {192, 168, 0, 1} /* 现场生产服务器 */
#endif
#define MODBUS_SERVER_PORT 502
#define MODBUS_UNIT_ID 1
#define MODBUS_POLL_INTERVAL 2000 /* 轮询间隔 (ms) */
/* 寄存器定义 */
#define TARGET_REG_ADDR 30 /* 逻辑 40031 */
/* 客户端状态枚举 */
typedef enum {
MODBUS_STATE_IDLE,
MODBUS_STATE_CONNECTING,
MODBUS_STATE_SEND_QUERY,
MODBUS_STATE_WAIT_RESPONSE,
MODBUS_STATE_ERROR_RETRY
} modbus_client_state_t;
/**
* @brief Modbus TCP
* @param sn: W5500 Socket
*/
void ModbusTCP_Client_Init(uint8_t sn);
/**
* @brief Modbus TCP ()
*/
void ModbusTCP_Client_Task(void);
2026-05-10 08:57:34 +08:00
/**
* @brief Modbus
* @retval 16 ( 0xFFFF)
*/
uint16_t ModbusTCP_Get_LastRegVal(void);
2026-05-09 19:53:47 +08:00
#endif