/** ****************************************************************************** * @file : modbus_implement.h * @brief : Header for modbus_implement.c file. * This file contains the common defines of the application. ****************************************************************************** * @attention * * Copyright (c) 2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MODBUS_IMPLEMENT_H #define __MODBUS_IMPLEMENT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32l4xx_hal.h" #define Cmd_FirmwareVersion (0x0000) #define Cmd_HardwareVersion (0x0008) #define Cmd_DeviceID (0x0009) #define Cmd_DeviceType (0x000B) #define Cmd_Reboot (0x000C) #define Cmd_Reset (0x000D) #define Cmd_Addr (0x0010) #define Cmd_Baudrate (0x0011) #define Cmd_DateTime (0x0012) #define Cmd_IapUpgrade (0xAABB) #define MB_FUNC_03 (0x03) #define MB_FUNC_06 (0x06) #define MB_FUNC_10 (0x10) #define MB_FUNC_42 (0x42) //for iap #define NO_EXCEPTION (0x00) #define INVALID_FUNCTION_CODE (0x01) #define INVALID_COMMAND (0x02) #define INVALID_DATA (0x03) #define DEVICE_FAULT (0x04) /* Exported functions prototypes ---------------------------------------------*/ //读取时返回,数据长度, 如果返回 0, 说明buf_len 不够, 设备故障 uint16_t Read_FirmwareVersion(uint8_t *pBuf, uint16_t buf_len); uint16_t Read_HardwareVersion(uint8_t *pBuf, uint16_t buf_len); uint16_t Read_Deviceid(uint8_t *pBuf, uint16_t buf_len); uint16_t Read_Devicetype(uint8_t *pBuf, uint16_t buf_len); uint16_t Read_Addr(uint8_t *pBuf, uint16_t buf_len); uint16_t Read_Baudrate(uint8_t *pBuf, uint16_t buf_len); #define RET_ERROR_MASK (0xF0) #define RET_OK (0x00) #define RET_NEED_SAVE (0X01) #define RET_NEED_REBOOT (0X02) #define RET_DATAINVALID (0x10) #define RET_CMDINVALID (0x20) //#define RET_DATAINVALID (3) //写入成功时返回 RET_OK //写入不成功时,返回 RET_DATAINVALID uint8_t Write_Addr(uint8_t *pdata, uint8_t len); uint8_t Write_Baudrate(uint8_t *pdata, uint8_t len); uint8_t Write_HardwareVersion(uint8_t *pdata, uint8_t len); uint8_t Write_Deviceid(uint8_t *pdata, uint8_t len); uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len); #ifdef __cplusplus } #endif #endif /* __MODBUS_IMPLEMENT_H */