Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

# modbus_defs.h File Reference

## Detailed Description

Example modbus variables define file.

This file defines variables that used by modbus protocol.

History: Date Author Comment 08-01-2005 AceLan Kao. Create it.

Author:
  AceLan Kao.(acelan_kao@moxa.com.tw)

Definition in file modbus_defs.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Defines
#define | MAX_485_NUM 256
#define | MAX_BUFFER_SIZE 256
#define | MB_ASCII_ADU_MAX_LENGTH 512
#define | MB_ASCII_PROTOCOL 1
#define | MB_ERROR_BAD_FD -11
#define | MB_ERROR_BUFFER_TOO_SHORT -7
#define | MB_ERROR_EXECPTION -10
#define | MB_ERROR_FORMAT -1
#define | MB_ERROR_FREE 0
| following error define it is OK
#define | MB_ERROR_FUNCTION -15
#define | MB_ERROR_LENGTH -2
| too short, too long or boudary error
#define | MB_ERROR_MODE -16
#define | MB_ERROR_NET -12
#define | MB_ERROR_NO_FILE_HANDLE -13
#define | MB_ERROR_NO_FRAME -8
#define | MB_ERROR_NOT_OPENED -6
| port has not opened
#define | MB_ERROR_OPEN -4
| open port error
#define | MB_ERROR_PARAMETER -3
| parameter error
#define | MB_ERROR_PROTOCOL -14
| Protocol not define.
#define | MB_ERROR_TCP_NOT_CONNECTED -5
| TCP port doesn't connect.
#define | MB_ERROR_TIMEOUT -9
#define | MB_OK 0
| operating is OK
#define | MB_RTU_ADU_MAX_LENGTH 256
#define | MB_RTU_PROTOCOL 0
#define | MB_TCP_PORT 502
#define | MB_TCP_PROTOCOL 2
#define | MBF_DIAGNOSTIC 0x08
| just for over serial line
#define | MBF_GET_COMM_EVENT_COUNTER 0x0B
| just for over serial line
#define | MBF_GET_COMM_EVENT_LOG 0x0C
| just for over serial line
#define | MBF_HAS_EXCEPTION 0x80
#define | MBF_MASK 0x7F
| mask function code
#define | MBF_MASK_WRITE_REGISTER 0x16
#define | MBF_READ_COILS 0x01
#define | MBF_READ_DECRETE_INPUTS 0x02
| Modbus application function code define.
#define | MBF_READ_DEVICE_IDENTIFICATION 0x2B
#define | MBF_READ_EXCEPTION_STATUS 0x07
| just for over serial line
#define | MBF_READ_FIFO_QUEUE 0x18
#define | MBF_READ_FILE_RECORD 0x14
#define | MBF_READ_HOLDING_REGISTERS 0x03
#define | MBF_READ_INPUT_REGISTERS 0x04
#define | MBF_READ_WRITE_MULTIPLE_REGISTERS 0x17
#define | MBF_REPORT_SLAVE_ID 0x11
| just for over serial line
#define | MBF_WRITE_FILE_RECORD 0x15
#define | MBF_WRITE_MULTIPLE_COILS 0x0F
#define | MBF_WRITE_MULTIPLE_REGISTERS 0x10
#define | MBF_WRITE_SINGLE_COIL 0x05
#define | MBF_WRITE_SINGLE_REGISTER 0x06
#define | NBSF_FILE_RECORD 0x06
#define | U32_MAX_VALUE 0xFFFFFFFF
## Typedefs
typedef unsigned short | u16
typedef unsigned long | u32
typedef unsigned char | u8

## Define Documentation

#define MAX_485_NUM 256

| Definition at line 35 of file modbus_defs.h.

#define MAX_BUFFER_SIZE 256

| Definition at line 34 of file modbus_defs.h. Referenced by MBSerialDiagnostic(), MBSerialGetCommEventCounter(), MBSerialGetCommEventLog(), MBSerialMaskWriteRegister(), MBSerialReadCoils(), MBSerialReadDecreteInputs(), MBSerialReadExceptionStatus(), MBSerialReadFIFOQueue(), MBSerialReadHoldingRegisters(), MBSerialReadInputRegisters(), MBSerialReadWriteMultipleRegisters(), MBSerialReportSlaveID(), MBSerialSendDiagnostic(), MBSerialSendGetCommEventCounter(), MBSerialSendGetCommEventLog(), MBSerialSendReadCoils(), MBSerialSendReadDecreteInputs(), MBSerialSendReadExecptionStatus(), MBSerialSendReadFIFOueue(), MBSerialSendReadHoldingRegisters(), MBSerialSendReadInputRegisters(), MBSerialSendWriteMultipleRegisters(), MBSerialSendWriteSingleCoil(), MBSerialSendWriteSingleRegister(), MBSerialWriteMultipleCoils(), MBSerialWriteMultipleRegisters(), MBSerialWriteSingleCoil(), MBSerialWriteSingleRegister(), MBTCPMaskwWriteRegister(), MBTCPReadCoils(), MBTCPReadDecreteInputs(), MBTCPReadFIFOQueue(), MBTCPReadHoldingRegisters(), MBTCPReadInputRegisters(), MBTCPReadWriteMultipleRegisters(), MBTCPSendReadCoils(), MBTCPSendReadDecreteInputs(), MBTCPSendReadFIFOQueue(), MBTCPSendReadHoldingRegisters(), MBTCPSendReadInputRegisters(), MBTCPSendWriteMultipleRegisters(), MBTCPSendWriteSingleCoil(), MBTCPSendWriteSingleRegister(), MBTCPWriteMultipleCoils(), MBTCPWriteMultipleRegisters(), MBTCPWriteSingleCoil(), MBTCPWriteSingleRegister(), serial_master(), serial_master_child(), serial_slave(), and serial_slave_child().

#define MB_ASCII_ADU_MAX_LENGTH 512

| Definition at line 28 of file modbus_defs.h. Referenced by MBASCIIToData(), MBMakeADU(), MBSerialDiagnostic(), MBSerialGetCommEventCounter(), MBSerialGetCommEventLog(), MBSerialMaskWriteRegister(), MBSerialReadASCII(), MBSerialReadCoils(), MBSerialReadDecreteInputs(), MBSerialReadExceptionStatus(), MBSerialReadFIFOQueue(), MBSerialReadHoldingRegisters(), MBSerialReadInputRegisters(), MBSerialReadWriteMultipleRegisters(), MBSerialReportSlaveID(), MBSerialSendAndWaitResponse(), MBSerialWrite(), MBSerialWriteMultipleCoils(), MBSerialWriteMultipleRegisters(), MBSerialWriteSingleCoil(), MBSerialWriteSingleRegister(), MBTCPMaskwWriteRegister(), MBTCPReadCoils(), MBTCPReadDecreteInputs(), MBTCPReadFIFOQueue(), MBTCPReadHoldingRegisters(), MBTCPReadInputRegisters(), MBTCPReadWriteMultipleRegisters(), MBTCPWriteMultipleCoils(), MBTCPWriteMultipleRegisters(), MBTCPWriteSingleCoil(), and MBTCPWriteSingleRegister().

#define MB_ASCII_PROTOCOL 1

| Definition at line 31 of file modbus_defs.h. Referenced by MBMakeADU(), MBSerialBlockRead(), MBSerialOpen(), and MBSerialSendAndWaitResponse().

#define MB_ERROR_BAD_FD -11

| Definition at line 74 of file modbus_defs.h.

#define MB_ERROR_BUFFER_TOO_SHORT -7

| Definition at line 70 of file modbus_defs.h.

#define MB_ERROR_EXECPTION -10

| Definition at line 73 of file modbus_defs.h. Referenced by MBSerialDiagnostic(), MBSerialMaskWriteRegister(), MBSerialReadWriteMultipleRegisters(), MBSerialWriteMultipleCoils(), MBSerialWriteMultipleRegisters(), MBSerialWriteSingleCoil(), MBSerialWriteSingleRegister(), MBTCPMaskwWriteRegister(), MBTCPReadWriteMultipleRegisters(), MBTCPSendAndWaitResponse(), MBTCPWriteMultipleCoils(), MBTCPWriteMultipleRegisters(), MBTCPWriteSingleCoil(), and MBTCPWriteSingleRegister().

#define MB_ERROR_FORMAT -1

| Definition at line 64 of file modbus_defs.h. Referenced by MBASCIIToData(), MBSerialReadASCII(), and MBSerialReadRTU().

#define MB_ERROR_FREE 0

| following error define it is OK Definition at line 62 of file modbus_defs.h.

#define MB_ERROR_FUNCTION -15

| Definition at line 78 of file modbus_defs.h. Referenced by MBGetDiagnostic(), MBGetMaskWriteRegister(), MBGetReadCoils(), MBGetReadDecreteInputs(), MBGetReadFIFOQueue(), MBGetReadHoldingRegisters(), MBGetReadInputRegisters(), MBGetReadWriteMultipleRegisters(), MBGetResponseDiagnostic(), MBGetResponseGetCommEventCounter(), MBGetResponseGetCommEventLog(), MBGetResponseMaskWriteRegister(), MBGetResponseReadCoils(), MBGetResponseReadDecreteInputs(), MBGetResponseReadExceptionStatus(), MBGetResponseReadFIFOQueue(), MBGetResponseReadHoldingRegisters(), MBGetResponseReadInputRegisters(), MBGetResponseReadWriteMultipleRegisters(), MBGetResponseReportSlaveID(), MBGetResponseWriteMultipleCoils(), MBGetResponseWriteMultipleRegisters(), MBGetResponseWriteSingleCoil(), MBGetResponseWriteSingleRegister(), MBGetWriteMultipleCoils(), MBGetWriteMultipleRegisters(), MBGetWriteSingleCoil(), and MBGetWriteSingleRegister().

#define MB_ERROR_LENGTH -2

| too short, too long or boudary error Definition at line 65 of file modbus_defs.h. Referenced by MBASCIIToData().

#define MB_ERROR_MODE -16

| Definition at line 79 of file modbus_defs.h. Referenced by MBSerialSetMode().

#define MB_ERROR_NET -12

| Definition at line 75 of file modbus_defs.h.

#define MB_ERROR_NO_FILE_HANDLE -13

| Definition at line 76 of file modbus_defs.h.

#define MB_ERROR_NO_FRAME -8

| Definition at line 71 of file modbus_defs.h.

#define MB_ERROR_NOT_OPENED -6

| port has not opened Definition at line 69 of file modbus_defs.h.

#define MB_ERROR_OPEN -4

| open port error Definition at line 67 of file modbus_defs.h. Referenced by MBSerialOpen().

#define MB_ERROR_PARAMETER -3

| parameter error Definition at line 66 of file modbus_defs.h. Referenced by CRC16(), and LRC().

#define MB_ERROR_PROTOCOL -14

| Protocol not define. Definition at line 77 of file modbus_defs.h. Referenced by MBMakeADU(), MBSerialBlockRead(), MBSerialOpen(), and MBSerialSendAndWaitResponse().

#define MB_ERROR_TCP_NOT_CONNECTED -5

| TCP port doesn't connect. Definition at line 68 of file modbus_defs.h. Referenced by MBTCPServerWaitConnection().

#define MB_ERROR_TIMEOUT -9

| Definition at line 72 of file modbus_defs.h.

#define MB_OK 0

| operating is OK Definition at line 63 of file modbus_defs.h. Referenced by MBGetDiagnostic(), MBGetMaskWriteRegister(), MBGetReadCoils(), MBGetReadDecreteInputs(), MBGetReadFIFOQueue(), MBGetReadHoldingRegisters(), MBGetReadInputRegisters(), MBGetReadWriteMultipleRegisters(), MBGetResponseDiagnostic(), MBGetResponseGetCommEventCounter(), MBGetResponseGetCommEventLog(), MBGetResponseMaskWriteRegister(), MBGetResponseReadCoils(), MBGetResponseReadDecreteInputs(), MBGetResponseReadExceptionStatus(), MBGetResponseReadFIFOQueue(), MBGetResponseReadHoldingRegisters(), MBGetResponseReadInputRegisters(), MBGetResponseReadWriteMultipleRegisters(), MBGetResponseReportSlaveID(), MBGetResponseWriteMultipleCoils(), MBGetResponseWriteMultipleRegisters(), MBGetResponseWriteSingleCoil(), MBGetResponseWriteSingleRegister(), MBGetWriteMultipleCoils(), MBGetWriteMultipleRegisters(), MBGetWriteSingleCoil(), MBGetWriteSingleRegister(), MBSerialDiagnostic(), MBSerialGetCommEventCounter(), MBSerialGetCommEventLog(), MBSerialMaskWriteRegister(), MBSerialOpen(), MBSerialReadExceptionStatus(), MBSerialReadFIFOQueue(), MBSerialReadWriteMultipleRegisters(), MBSerialReportSlaveID(), MBSerialSendDiagnostic(), MBSerialSendGetCommEventCounter(), MBSerialSendGetCommEventLog(), MBSerialSendReadCoils(), MBSerialSendReadDecreteInputs(), MBSerialSendReadExecptionStatus(), MBSerialSendReadFIFOueue(), MBSerialSendReadHoldingRegisters(), MBSerialSendReadInputRegisters(), MBSerialSendWriteMultipleRegisters(), MBSerialSendWriteSingleCoil(), MBSerialSendWriteSingleRegister(), MBSerialSetMode(), MBSerialWriteMultipleCoils(), MBSerialWriteMultipleRegisters(), MBSerialWriteSingleCoil(), MBSerialWriteSingleRegister(), MBTCPGetMBAP(), MBTCPMakeMBAP(), MBTCPMaskwWriteRegister(), MBTCPReadFIFOQueue(), MBTCPReadWriteMultipleRegisters(), MBTCPSendReadCoils(), MBTCPSendReadDecreteInputs(), MBTCPSendReadFIFOQueue(), MBTCPSendReadHoldingRegisters(), MBTCPSendReadInputRegisters(), MBTCPSendWriteMultipleRegisters(), MBTCPSendWriteSingleCoil(), MBTCPSendWriteSingleRegister(), MBTCPWriteMultipleCoils(), MBTCPWriteMultipleRegisters(), MBTCPWriteSingleCoil(), and MBTCPWriteSingleRegister().

#define MB_RTU_ADU_MAX_LENGTH 256

| Definition at line 27 of file modbus_defs.h. Referenced by MBSerialSendAndWaitResponse(), MBTCPSendAndWaitResponse(), and MBTCPWrite().

#define MB_RTU_PROTOCOL 0

| Definition at line 30 of file modbus_defs.h. Referenced by MBMakeADU(), MBSerialBlockRead(), MBSerialOpen(), MBSerialSendAndWaitResponse(), serial_master(), and serial_slave().

#define MB_TCP_PORT 502

| Definition at line 26 of file modbus_defs.h.

#define MB_TCP_PROTOCOL 2

| Definition at line 32 of file modbus_defs.h. Referenced by MBMakeADU(), and MBSerialOpen().

#define MBF_DIAGNOSTIC 0x08

| just for over serial line Definition at line 53 of file modbus_defs.h. Referenced by MBDiagnostic(), MBGetDiagnostic(), MBGetResponseDiagnostic(), and MBResponseDiagnostic().

#define MBF_GET_COMM_EVENT_COUNTER 0x0B

| just for over serial line Definition at line 54 of file modbus_defs.h. Referenced by MBGetCommEventCounter(), MBGetResponseGetCommEventCounter(), and MBResponseGetCommEventCounter().

#define MBF_GET_COMM_EVENT_LOG 0x0C

| just for over serial line Definition at line 55 of file modbus_defs.h. Referenced by MBGetCommEventLog(), MBGetResponseGetCommEventLog(), and MBResponseGetCommEventLog().

#define MBF_HAS_EXCEPTION 0x80

| Definition at line 58 of file modbus_defs.h.

#define MBF_MASK 0x7F

| mask function code Definition at line 59 of file modbus_defs.h.

#define MBF_MASK_WRITE_REGISTER 0x16

| Definition at line 47 of file modbus_defs.h. Referenced by MBGetMaskWriteRegister(), MBGetResponseMaskWriteRegister(), and MBMaskWriteRegister().

#define MBF_READ_COILS 0x01

| Definition at line 39 of file modbus_defs.h. Referenced by MBGetReadCoils(), MBGetResponseReadCoils(), MBReadCoils(), and MBResponseReadCoils().

#define MBF_READ_DECRETE_INPUTS 0x02

| Modbus application function code define. Definition at line 38 of file modbus_defs.h. Referenced by MBGetReadDecreteInputs(), MBGetResponseReadDecreteInputs(), MBReadDecreteInputs(), and MBResponseReadDecreteInputs().

#define MBF_READ_DEVICE_IDENTIFICATION 0x2B

| Definition at line 57 of file modbus_defs.h.

#define MBF_READ_EXCEPTION_STATUS 0x07

| just for over serial line Definition at line 52 of file modbus_defs.h. Referenced by MBGetResponseReadExceptionStatus(), MBReadExceptionStatus(), and MBResponseReadExceptionStatus().

#define MBF_READ_FIFO_QUEUE 0x18

| Definition at line 48 of file modbus_defs.h. Referenced by MBGetReadFIFOQueue(), MBGetResponseReadFIFOQueue(), MBReadFIFOQueue(), and MBResponseReadFIFOQueue().

#define MBF_READ_FILE_RECORD 0x14

| Definition at line 49 of file modbus_defs.h.

#define MBF_READ_HOLDING_REGISTERS 0x03

| Definition at line 43 of file modbus_defs.h. Referenced by MBGetReadHoldingRegisters(), MBGetResponseReadHoldingRegisters(), MBReadHoldingRegisters(), and MBResponseReadHoldingRegisters().

#define MBF_READ_INPUT_REGISTERS 0x04

| Definition at line 42 of file modbus_defs.h. Referenced by MBGetReadInputRegisters(), MBGetResponseReadInputRegisters(), MBReadInputRegisters(), and MBResponseReadInputRegisters().

#define MBF_READ_WRITE_MULTIPLE_REGISTERS 0x17

| Definition at line 46 of file modbus_defs.h. Referenced by MBGetReadWriteMultipleRegisters(), MBGetResponseReadWriteMultipleRegisters(), and MBReadWriteMultipleRegisters().

#define MBF_REPORT_SLAVE_ID 0x11

| just for over serial line Definition at line 56 of file modbus_defs.h. Referenced by MBGetResponseReportSlaveID(), and MBReportSlaveID().

#define MBF_WRITE_FILE_RECORD 0x15

| Definition at line 50 of file modbus_defs.h.

#define MBF_WRITE_MULTIPLE_COILS 0x0F

| Definition at line 41 of file modbus_defs.h. Referenced by MBGetResponseWriteMultipleCoils(), MBGetWriteMultipleCoils(), and MBWriteMultipleCoils().

#define MBF_WRITE_MULTIPLE_REGISTERS 0x10

| Definition at line 45 of file modbus_defs.h. Referenced by MBGetResponseWriteMultipleRegisters(), MBGetWriteMultipleRegisters(), MBResponseWriteMultipleRegisters(), and MBWriteMultipleRegisters().

#define MBF_WRITE_SINGLE_COIL 0x05

| Definition at line 40 of file modbus_defs.h. Referenced by MBGetResponseWriteSingleCoil(), MBGetWriteSingleCoil(), MBResponseWriteSingleCoil(), and MBWriteSingleCoil().

#define MBF_WRITE_SINGLE_REGISTER 0x06

| Definition at line 44 of file modbus_defs.h. Referenced by MBGetResponseWriteSingleRegister(), MBGetWriteSingleRegister(), MBResponseWriteSingleRegister(), and MBWriteSingleRegister().

#define NBSF_FILE_RECORD 0x06

| Definition at line 51 of file modbus_defs.h.

#define U32_MAX_VALUE 0xFFFFFFFF

| Definition at line 24 of file modbus_defs.h. Referenced by MBSerialReadRTU().

## Typedef Documentation

typedef unsigned short u16

| Definition at line 21 of file modbus_defs.h.

typedef unsigned long u32

| Definition at line 22 of file modbus_defs.h.

typedef unsigned char u8

| Definition at line 20 of file modbus_defs.h.