123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- // modbmst.h :
- //
- #if !defined(AGD_MODBMST_H__7E9090EE_6B4D_4499_8080_03241FAC527B__INCLUDED_)
- #define AGD_MODBMST_H__7E9090EE_6B4D_4499_8080_03241FAC527B__INCLUDED_
- #include <stdint.h>
- #include <stdbool.h>
- #include <gfa/gfamininetmst.h>
- #ifdef __cplusplus
- extern "C" {
- #endif // __cplusplus
- /////////////////////////////////////////////////////////////////////////////
- // modbmst.h - Declarations:
- #define MB_FUNC_READ_COIL_STATUS ((uint8_t)0x01)
- #define MB_FUNC_READ_INPUT_STATUS ((uint8_t)0x02)
- #define MB_FUNC_READ_HOLDING_REGISTERS ((uint8_t)0x03)
- #define MB_FUNC_READ_INPUT_REGISTERS ((uint8_t)0x04)
- #define MB_FUNC_FORCE_SINGLE_COIL ((uint8_t)0x05)
- #define MB_FUNC_PRESET_SINGLE_REGISTER ((uint8_t)0x06)
- #define MB_FUNC_READ_EXCEPTION_STATUS ((uint8_t)0x07)
- #define MB_FUNC_DIAGNOSTIC ((uint8_t)0x08)
- #define MB_FUNC_FETCH_COMM_EVENT_CTR ((uint8_t)0x0B)
- #define MB_FUNC_FETCH_COMM_EVENT_LOG ((uint8_t)0x0C)
- #define MB_FUNC_FORCE_MULTIPLE_COILS ((uint8_t)0x0F)
- #define MB_FUNC_WRITE_MULTIPLE_REGISTERS ((uint8_t)0x10)
- #define MB_FUNC_REPORT_SLAVE_ID ((uint8_t)0x11)
- #define MB_FUNC_READ_GENERAL_REFERENCE ((uint8_t)0x14)
- #define MB_FUNC_WRITE_GENERAL_REFERENCE ((uint8_t)0x15)
- #define MB_FUNC_MASK_WRITE_4X_REGISTER ((uint8_t)0x16)
- #define MB_FUNC_READ_WRITE_4X_REGISTERS ((uint8_t)0x17)
- #define MB_FUNC_READ_FIFO_QUEUE ((uint8_t)0x18)
- #define MB_SUBFUNC_RETURN_QUERY_DATA ((uint16_t)0x00)
- #define MB_SUBFUNC_RESTART_COMM_OPTION ((uint16_t)0x01)
- #define MB_SUBFUNC_RETURN_DIAGNOSTIC_REGISTER ((uint16_t)0x02)
- #define MB_SUBFUNC_FORCE_LISTEN_ONLY_MODE ((uint16_t)0x04)
- #define MB_SUBFUNC_CLEAR_CTRS_AND_DIAGNOSTIC_REG ((uint16_t)0x0A)
- #define MB_SUBFUNC_RETURN_BUS_MESSAGE_COUNT ((uint16_t)0x0B)
- #define MB_SUBFUNC_RETURN_BUS_COMM_ERROR_COUNT ((uint16_t)0x0C)
- #define MB_SUBFUNC_RETURN_BUS_EXCEPTION_ERROR_COUNT ((uint16_t)0x0D)
- #define MB_SUBFUNC_RETURN_SLAVE_MESSAGE_COUNT ((uint16_t)0x0E)
- #define MB_SUBFUNC_RETURN_SLAVE_NO_RESPONSE_COUNT ((uint16_t)0x0F)
- #define MB_SUBFUNC_RETURN_SLAVE_NAK_COUNT ((uint16_t)0x10)
- #define MB_SUBFUNC_RETURN_SLAVE_BUSY_COUNT ((uint16_t)0x11)
- #define MB_SUBFUNC_RETURN_BUS_CHAR_OVERRUN_COUNT ((uint16_t)0x12)
- #define MB_SUBFUNC_RETURN_OVERRUN_ERROR_COUNT ((uint16_t)0x13)
- #define MB_SUBFUNC_CLEAR_OVERRUN_COUNTER_AND_FLAG ((uint16_t)0x14)
- #define MB_FUNC_ERROR_FLAG ((uint8_t)0x80)
- #define MB_ERROR_ILLEGAL_FUNCTION ((uint8_t)0x01)
- #define MB_ERROR_ILLEGAL_DATA_ADDRESS ((uint8_t)0x02)
- #define MB_ERROR_ILLEGAL_DATA_VALUE ((uint8_t)0x03)
- #define MB_ERROR_SLAVE_DEVICE_FAILURE ((uint8_t)0x04)
- #define MB_ERROR_ACKNOWLEDGE ((uint8_t)0x05)
- #define MB_ERROR_SLAVE_DEVICE_BUSY ((uint8_t)0x06)
- #define MB_ERROR_NEGATIVE_ACKNOWLEDGE ((uint8_t)0x07)
- #define MB_ERROR_MEMORY_PARITY_ERROR ((uint8_t)0x08)
- #define MODBUS_BROADCAST_ADDRESS 0
- #define MODBUS_MAX_SLAVE_ID 247
- #define MODBUS_MAX_READ_BITS 2000
- #define MODBUS_MAX_WRITE_BITS 1968
- #define MODBUS_MAX_READ_REGISTERS 125
- #define MODBUS_MAX_WRITE_REGISTERS 123
- #define MODBUS_MAX_RW_WRITE_REGISTERS 121
- #define MODBUS_MAX_DATA_PAYLOAD 252
- #define MODBUS_IS_VALID_SLAVE_ID(id) (((id) != MODBUS_BROADCAST_ADDRESS) && ((id) <= MODBUS_MAX_SLAVE_ID))
- /////////////////////////////////////////////////////////////////////////////
- typedef struct _MODBUS_RTU_ADU
- {
- uint8_t slvID;
- uint8_t func;
- union
- {
- uint8_t b[254];
- uint16_t w[127];
- };
- }__attribute__ ((__aligned__(2),__packed__)) MODBUS_RTU_ADU, *LPMODBUS_RTU_ADU;
- typedef const MODBUS_RTU_ADU *LPCMODBUS_RTU_ADU;
- /////////////////////////////////////////////////////////////////////////////
- typedef void *HGFAMBMST;
- /////////////////////////////////////////////////////////////////////////////
- HGFAMBMST GfaMbMstOpen(HGFAMINEMST hMiNeMst, uint32_t nBaudrate, uint8_t parity, uint16_t nModbusCtrlReg);
- void GfaMbMstClose(HGFAMBMST hMst);
- ssize_t GfaMbMstSendADU(HGFAMBMST hMst, LPCMODBUS_RTU_ADU pAdu, size_t nCbAdu);
- ssize_t GfaMbMstRecvADU(HGFAMBMST hMst, LPMODBUS_RTU_ADU pAdu, size_t nCbAdu);
- ssize_t GfaMbMstReadHoldingRegisters(HGFAMBMST hMst, uint8_t slvID, uint16_t nRegStart, uint16_t nRegCount, void *pRegs);
- ssize_t GfaMbMstWriteMultipleRegisters(HGFAMBMST hMst, uint8_t slvID, uint16_t nRegStart, uint16_t nRegCount, const void *pRegs);
- void GfaMbMstWaitFrameDelay(HGFAMBMST hMst);
- int GfaMbMstPing(HGFAMBMST hMst, uint8_t slvID);
- int GfaMbMstBootloaderExecute(HGFAMBMST hMst, uint8_t slvID);
- int GfaMbMstSetVerbosity(HGFAMBMST hMst, int nVerbosity);
- void GfaMbMstDumpADU(HGFAMBMST hMst, LPCMODBUS_RTU_ADU pAdu, size_t nCbAdu, bool bTX, const char *pszAnnotation);
- ssize_t GfaMbMstCreateADU(uint8_t slvID, uint8_t func, const void *pData, size_t nCbData, LPMODBUS_RTU_ADU pAdu);
- bool GfaMbMstValidateADU(uint8_t slvID, uint8_t func, LPCMODBUS_RTU_ADU pAdu, size_t nCbAdu, int *pnMbErr);
- /////////////////////////////////////////////////////////////////////////////
- #ifdef __cplusplus
- }
- #endif // __cplusplus
- #endif // !defined(AGD_MODBMST_H__7E9090EE_6B4D_4499_8080_03241FAC527B__INCLUDED_)
|