Modbus 0.3
Библиотека Modbus для STM
Loading...
Searching...
No Matches
Modbus Message Tools

Определения протокола модбас More...

Collaboration diagram for Modbus Message Tools:

Classes

struct  MB_DevIdMsgTypeDef
 Structure for device identifications message type. More...
struct  RS_MsgTypeDef
 Structure for modbus messsage. More...

Macros

#define TransactionID_size   2
 size of (Transaction ID)
#define ProtocolID_size   2
 size of (Protocol ID)
#define PDULength_size   2
 size of (PDU Length)
#define MbAddr_SIZE   1
 size of (Slave Addr)
#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 CRC_SIZE   2
 size of (MbCRC) in bytes
#define INFO_SIZE_MAX   (MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE+ByteCnt_SIZE)
 Size of whole RTU message.
#define RX_FIRST_PART_SIZE   INFO_SIZE_MAX
 Size of first part of message that will be received first receive info part of message, than defines size of rest message.
#define MSG_SIZE_MAX   (INFO_SIZE_MAX + DATA_SIZE*2 + CRC_SIZE)
 Size of buffer: max size of whole message.
#define FC_ERR_VALUES_START   0x80U
 from this value starts error func codes
#define MB_Set_Arr16_Ptr(_arr_)
 Macros to set pointer to 16-bit array.
#define MB_Set_Register_Ptr(_parr_, _addr_)
 Macros to set pointer to register.
#define MB_Set_Coil_Reg_Ptr(_parr_, _coil_)
 Макрос для установки указателя на регистр, содержащий запрашиваемый коил
#define MB_Set_Coil_Mask(_coil_)
 Макрос для установки маски, чтобы выделить запрашиваемый коил из регистра

Enumerations

enum  MB_ExceptionTypeDef {
  ET_NO_ERRORS = 0x00 , ET_ILLEGAL_FUNCTION = 0x01 , ET_ILLEGAL_DATA_ADDRESS = 0x02 , ET_ILLEGAL_DATA_VALUE = 0x03 ,
  ET_SLAVE_DEVICE_FAILURE = 0x04
}
 Enum for modbus exception codes. More...
enum  MB_FunctonTypeDef {
  FC_R_COILS = 0x01 , FC_R_DISC_IN = 0x02 , FC_R_HOLD_REGS = 0x03 , FC_R_IN_REGS = 0x04 ,
  FC_W_COIL = 0x05 , FC_W_HOLD_REG = 0x06 , FC_W_COILS = 0x0F , FC_W_HOLD_REGS = 0x10 ,
  FC_R_DIAGNOSTICS = 0x08 , FC_R_DEVICE_ID = 0x2B , FC_ERR_R_COILS = FC_R_COILS + FC_ERR_VALUES_START , FC_ERR_R_DISC_IN = FC_R_DISC_IN + FC_ERR_VALUES_START ,
  FC_ERR_R_IN_REGS = FC_R_IN_REGS + FC_ERR_VALUES_START , FC_ERR_R_HOLD_REGS = FC_R_HOLD_REGS + FC_ERR_VALUES_START , FC_ERR_W_COIL = FC_W_COIL + FC_ERR_VALUES_START , FC_ERR_W_HOLD_REG = FC_W_HOLD_REG + FC_ERR_VALUES_START ,
  FC_ERR_W_COILS = FC_W_COILS + FC_ERR_VALUES_START , FC_ERR_W_HOLD_REGS = FC_W_HOLD_REGS + FC_ERR_VALUES_START , FC_ERR_R_DIAGNOSTIC = FC_R_DIAGNOSTICS + FC_ERR_VALUES_START , FC_ERR_R_DEVICE_INFO = FC_R_DEVICE_ID + FC_ERR_VALUES_START
}
 Enum for modbus func codes. More...
enum  MB_MEITypeDef { MEI_DEVICE_IDENTIFICATIONS = 0x0E }
 Enum for MEI func codes. More...
enum  ReadDevId { RID_BASIC_IDENTIFICATIONS = 0x01 , RID_REGULAR_IDENTIFICATIONS = 0x02 , RID_EXTENDED_IDENTIFICATIONS = 0x03 , RID_SPEDIFIC_IDENTIFICATIONS = 0x04 }
 Enum for Read Device Id codes. More...

Variables

RS_MsgTypeDef MODBUS_MSG
 Default Message Struct for Modbus.

Detailed Description

Определения протокола модбас

Macro Definition Documentation

◆ TransactionID_size

#define TransactionID_size   2

size of (Transaction ID)

Definition at line 45 of file modbus_core.h.

◆ ProtocolID_size

#define ProtocolID_size   2

size of (Protocol ID)

Definition at line 46 of file modbus_core.h.

◆ PDULength_size

#define PDULength_size   2

size of (PDU Length)

Definition at line 47 of file modbus_core.h.

◆ MbAddr_SIZE

#define MbAddr_SIZE   1

size of (Slave Addr)

Definition at line 48 of file modbus_core.h.

◆ Func_Code_SIZE

#define Func_Code_SIZE   1

size of (Function Code)

Definition at line 49 of file modbus_core.h.

◆ Addr_SIZE

#define Addr_SIZE   2

size of (Address)

Definition at line 50 of file modbus_core.h.

◆ Qnt_SIZE

#define Qnt_SIZE   2

size of (Quantity)

Definition at line 51 of file modbus_core.h.

◆ ByteCnt_SIZE

#define ByteCnt_SIZE   1

size of (Byte Count)

Definition at line 52 of file modbus_core.h.

◆ DATA_SIZE

#define DATA_SIZE   125

maximum number of data: DWORD (NOT MESSAGE SIZE)

Definition at line 53 of file modbus_core.h.

◆ CRC_SIZE

#define CRC_SIZE   2

size of (MbCRC) in bytes

Definition at line 54 of file modbus_core.h.

◆ INFO_SIZE_MAX

Size of whole RTU message.

Definition at line 58 of file modbus_core.h.

◆ RX_FIRST_PART_SIZE

#define RX_FIRST_PART_SIZE   INFO_SIZE_MAX

Size of first part of message that will be received first receive info part of message, than defines size of rest message.

Definition at line 66 of file modbus_core.h.

◆ MSG_SIZE_MAX

#define MSG_SIZE_MAX   (INFO_SIZE_MAX + DATA_SIZE*2 + CRC_SIZE)

Size of buffer: max size of whole message.

Definition at line 69 of file modbus_core.h.

◆ FC_ERR_VALUES_START

#define FC_ERR_VALUES_START   0x80U

from this value starts error func codes

Definition at line 88 of file modbus_core.h.

◆ MB_Set_Arr16_Ptr

#define MB_Set_Arr16_Ptr ( _arr_)
Value:
((uint16_t*)(&(_arr_)))

Macros to set pointer to 16-bit array.

Parameters
_arr_- массив регистров (16-бит).

Definition at line 209 of file modbus_core.h.

◆ MB_Set_Register_Ptr

#define MB_Set_Register_Ptr ( _parr_,
_addr_ )
Value:
((uint16_t *)(_parr_)+(_addr_))

Macros to set pointer to register.

Parameters
_parr_- массив регистров.
_addr_- Номер регистра (его индекс) от начала массива arr.

Definition at line 215 of file modbus_core.h.

◆ MB_Set_Coil_Reg_Ptr

#define MB_Set_Coil_Reg_Ptr ( _parr_,
_coil_ )
Value:
((uint16_t *)(_parr_)+((_coil_)/16))

Макрос для установки указателя на регистр, содержащий запрашиваемый коил

Parameters
_parr_- массив коилов.
_coil_- Номер коила от начала массива arr.
Note
Используется вместе с MB_Set_Coil_Mask
Пояснение выражений
- (_coil_/16) - индекс регистра, в котором содержится коил по адресу _coil_
Визуальный пример: 30 коил будет в 30/16 = 1 регистре (индексация с 0)
xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxCx
|register[0]----| |register[1]----|
|skip this------| |get this-------|
|shift to 14 bit|

Definition at line 232 of file modbus_core.h.

◆ MB_Set_Coil_Mask

#define MB_Set_Coil_Mask ( _coil_)
Value:
(1 << ( _coil_ - (16*((_coil_)/16)) ))

Макрос для установки маски, чтобы выделить запрашиваемый коил из регистра

Parameters
_coil_- Номер коила от начала массива arr.
Note
Используется вместе с MB_Set_Coil_Reg_Ptr
Пояснение выражений
- (16*(_coil_/16) - сколько коилов нужно пропустить. прим. (16*30/16) - первые 16 коилов находятся вне регистра
- _coil_-(16*(_coil_/16)) - сдвинуть бит на место запрашиваемого коила в регистре
Визуальный пример: 30 коил будет регистре[1], на 14 бите:
register = 30/16 = 1
bit = 30 - (16*30/16) = 30 - 16 = 14
xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxCx
|register[0]----| |register[1]----|
|skip this------| |get this-------|
|shift to 14 bit|

Definition at line 251 of file modbus_core.h.

Enumeration Type Documentation

◆ MB_ExceptionTypeDef

Enum for modbus exception codes.

Prefix ET for Error Type

Enumerator
ET_NO_ERRORS 

no errors

ET_ILLEGAL_FUNCTION 

Принятый код функции не может быть обработан

ET_ILLEGAL_DATA_ADDRESS 

Адрес данных, указанный в запросе, недоступен

ET_ILLEGAL_DATA_VALUE 

Значение, содержащееся в поле данных запроса, является недопустимой величиной

ET_SLAVE_DEVICE_FAILURE 

Невосстанавливаемая ошибка имела место, пока ведомое устройство пыталось выполнить затребованное действие

Definition at line 75 of file modbus_core.h.

◆ MB_FunctonTypeDef

Enum for modbus func codes.

Prefix FC for Function Code

Enumerator
FC_R_COILS 

Чтение битовых ячеек

FC_R_DISC_IN 

Чтение дискретных входов

FC_R_HOLD_REGS 

Чтение входных регистров

FC_R_IN_REGS 

Чтение регистров хранения

FC_W_COIL 

Запись битовой ячейки

FC_W_HOLD_REG 

Запись одиночного регистра

FC_W_COILS 

Запись нескольких битовых ячеек

FC_W_HOLD_REGS 

Запись нескольких регистров

FC_R_DIAGNOSTICS 

Чтение диагностической информации устройства

FC_R_DEVICE_ID 

Чтение информации об устройстве

FC_ERR_R_COILS 

Ошибка чтения битовых ячеек

FC_ERR_R_DISC_IN 

Ошибка чтения дискретных входов

FC_ERR_R_IN_REGS 

Ошибка чтения регистров хранения

FC_ERR_R_HOLD_REGS 

Ошибка чтения входных регистров

FC_ERR_W_COIL 

Ошибка записи битовой ячейки

FC_ERR_W_HOLD_REG 

Ошибка записи одиночного регистра

FC_ERR_W_COILS 

Ошибка записи нескольких битовых ячеек

FC_ERR_W_HOLD_REGS 

Ошибка записи нескольких регистров

FC_ERR_R_DIAGNOSTIC 

Ошибка чтения диагностической информации устройства

FC_ERR_R_DEVICE_INFO 

Ошибка чтения информации об устройстве

Definition at line 93 of file modbus_core.h.

◆ MB_MEITypeDef

Enum for MEI func codes.

Definition at line 134 of file modbus_core.h.

◆ ReadDevId

enum ReadDevId

Enum for Read Device Id codes.

Prefix RID for Read ID

Enumerator
RID_BASIC_IDENTIFICATIONS 

Basic Device Identifications.

All objects of this category are mandatory: VendorName, Product code, and revision number

RID_REGULAR_IDENTIFICATIONS 

Regular Device Identifications.

The device provides additional and optional identifications and description data objects

RID_EXTENDED_IDENTIFICATIONS 

Extended Device Identifications.

The device provides additional and optional identifications and description private data about the physical device itself. All of these data are device dependent.

RID_SPEDIFIC_IDENTIFICATIONS 

Specific Device Identifications.

The device provides one specific identifications object.

Definition at line 143 of file modbus_core.h.

Variable Documentation

◆ MODBUS_MSG

RS_MsgTypeDef MODBUS_MSG
extern

Default Message Struct for Modbus.

Definition at line 25 of file modbus.c.