Добавлен протокол TCP, но не проверен
This commit is contained in:
@@ -40,16 +40,24 @@
|
|||||||
////////////////////---MODBUS MESSAGE DEFINES---/////////////////////
|
////////////////////---MODBUS MESSAGE DEFINES---/////////////////////
|
||||||
//-------------DEFINES FOR STRUCTURE----------------
|
//-------------DEFINES FOR STRUCTURE----------------
|
||||||
/* defines for structure of modbus message */
|
/* defines for structure of modbus message */
|
||||||
#define MbAddr_SIZE 1 ///< size of (MbAddr)
|
#define ID_Transaction_size 2 ///< size of (ID_Transaction)
|
||||||
#define Func_Code_SIZE 1 ///< size of (Func_Code)
|
#define ID_Protocol_size 2 ///< size of (ID_Protocol)
|
||||||
#define Addr_SIZE 2 ///< size of (Addr)
|
#define PDU_Len_size 2 ///< size of (PDU Length)
|
||||||
#define Qnt_SIZE 2 ///< size of (Qnt)
|
#define MbAddr_SIZE 1 ///< size of (Slave Addr)
|
||||||
#define ByteCnt_SIZE 1 ///< size of (ByteCnt)
|
#define Func_Code_SIZE 1 ///< size of (Function Code)
|
||||||
|
#define Addr_SIZE 2 ///< size of (Address)
|
||||||
|
#define Qnt_SIZE 2 ///< size of (Quantity)
|
||||||
|
#define ByteCnt_SIZE 1 ///< size of (Byte Count)
|
||||||
#define DATA_SIZE 125 ///< maximum number of data: DWORD (NOT MESSAGE SIZE)
|
#define DATA_SIZE 125 ///< maximum number of data: DWORD (NOT MESSAGE SIZE)
|
||||||
#define CRC_SIZE 2 ///< size of (MB_CRC) in bytes
|
#define CRC_SIZE 2 ///< size of (MB_CRC) in bytes
|
||||||
|
|
||||||
/** @brief Size of whole message */
|
#ifndef MODBUS_PROTOCOL_TCP
|
||||||
|
/** @brief Size of whole RTU message */
|
||||||
#define INFO_SIZE_MAX (MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE+ByteCnt_SIZE)
|
#define INFO_SIZE_MAX (MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE+ByteCnt_SIZE)
|
||||||
|
#else
|
||||||
|
/** @brief Size of whole TCP message */
|
||||||
|
#define INFO_SIZE_MAX (ID_Transaction_size+ID_Protocol_size+PDU_Len_size+MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE)
|
||||||
|
#endif
|
||||||
|
|
||||||
/** @brief Size of first part of message that will be received
|
/** @brief Size of first part of message that will be received
|
||||||
first receive info part of message, than defines size of rest message*/
|
first receive info part of message, than defines size of rest message*/
|
||||||
@@ -161,6 +169,12 @@ typedef struct
|
|||||||
/** @brief Structure for modbus messsage */
|
/** @brief Structure for modbus messsage */
|
||||||
typedef struct // RS_MsgTypeDef
|
typedef struct // RS_MsgTypeDef
|
||||||
{
|
{
|
||||||
|
#ifdef MODBUS_PROTOCOL_TCP
|
||||||
|
uint16_t ID_Transaction; ///< Modbus TCP: ID Transaction
|
||||||
|
uint16_t ID_Prot; ///< Modbus TCP: ID Protocol
|
||||||
|
uint16_t PDU_Length; ///< Modbus TCP: PDU_Length
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t MbAddr; ///< Modbus Slave Address
|
uint8_t MbAddr; ///< Modbus Slave Address
|
||||||
MB_FunctonTypeDef Func_Code; ///< Modbus Function Code
|
MB_FunctonTypeDef Func_Code; ///< Modbus Function Code
|
||||||
MB_DevIdMsgTypeDef DevId; ///< Read Device Identifications Header struct
|
MB_DevIdMsgTypeDef DevId; ///< Read Device Identifications Header struct
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ int MB_RespGet_CoilState(RS_MsgTypeDef *modbus_msg, uint16_t coil_addr, int *coi
|
|||||||
if(bit_index < 8)
|
if(bit_index < 8)
|
||||||
*coil_state = (modbus_msg->DATA[data_index] >> (bit_index+8)) & 0x01;
|
*coil_state = (modbus_msg->DATA[data_index] >> (bit_index+8)) & 0x01;
|
||||||
else
|
else
|
||||||
*coil_state = (modbus_msg->DATA[data_index] >> bit_index) & 0x01;
|
*coil_state = ((modbus_msg->DATA[data_index]&0xFF) >> bit_index) & 0x01;
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
#define MODBUS_ENABLE_DEVICE_IDENTIFICATIONS ///< Включить обработку идентификаторы устройства
|
#define MODBUS_ENABLE_DEVICE_IDENTIFICATIONS ///< Включить обработку идентификаторы устройства
|
||||||
#define MODBUS_ENABLE_DIAGNOSTICS ///< Включить обработку диагностики модбас
|
#define MODBUS_ENABLE_DIAGNOSTICS ///< Включить обработку диагностики модбас
|
||||||
|
|
||||||
|
#define MODBUS_PROTOCOL_TCP ///< Включить TCP-протокол, иначе - RTU
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Поменять комманды 0x03 и 0x04 местами (для LabView терминалки от двигателей)
|
* @brief Поменять комманды 0x03 и 0x04 местами (для LabView терминалки от двигателей)
|
||||||
|
|||||||
Reference in New Issue
Block a user