mbed trace
This commit is contained in:
88
Modbus.h
88
Modbus.h
@@ -122,56 +122,56 @@ class Modbus {
|
||||
public:
|
||||
//Function Codes
|
||||
enum FunctionCode {
|
||||
FC_READ_COILS = 0x01, // Read Coils (Output) Status
|
||||
FC_READ_INPUT_STAT = 0x02, // Read Input Status (Discrete Inputs)
|
||||
FC_READ_REGS = 0x03, // Read Holding Registers
|
||||
FC_READ_INPUT_REGS = 0x04, // Read Input Registers
|
||||
FC_WRITE_COIL = 0x05, // Write Single Coil (Output)
|
||||
FC_WRITE_REG = 0x06, // Preset Single Register
|
||||
FC_DIAGNOSTICS = 0x08, // Not implemented. Diagnostics (Serial Line only)
|
||||
FC_WRITE_COILS = 0x0F, // Write Multiple Coils (Outputs)
|
||||
FC_WRITE_REGS = 0x10, // Write block of contiguous registers
|
||||
FC_READ_FILE_REC = 0x14, // Not implemented. Read File Record
|
||||
FC_WRITE_FILE_REC = 0x15, // Not implemented. Write File Record
|
||||
FC_MASKWRITE_REG = 0x16, // Not implemented. Mask Write Register
|
||||
FC_READWRITE_REGS = 0x17 // Not implemented. Read/Write Multiple registers
|
||||
FC_READ_COILS = 0x01U, // Read Coils (Output) Status
|
||||
FC_READ_INPUT_STAT = 0x02U, // Read Input Status (Discrete Inputs)
|
||||
FC_READ_REGS = 0x03U, // Read Holding Registers
|
||||
FC_READ_INPUT_REGS = 0x04U, // Read Input Registers
|
||||
FC_WRITE_COIL = 0x05U, // Write Single Coil (Output)
|
||||
FC_WRITE_REG = 0x06U, // Preset Single Register
|
||||
FC_DIAGNOSTICS = 0x08U, // Not implemented. Diagnostics (Serial Line only)
|
||||
FC_WRITE_COILS = 0x0FU, // Write Multiple Coils (Outputs)
|
||||
FC_WRITE_REGS = 0x10U, // Write block of contiguous registers
|
||||
FC_READ_FILE_REC = 0x14U, // Not implemented. Read File Record
|
||||
FC_WRITE_FILE_REC = 0x15U, // Not implemented. Write File Record
|
||||
FC_MASKWRITE_REG = 0x16U, // Not implemented. Mask Write Register
|
||||
FC_READWRITE_REGS = 0x17U // Not implemented. Read/Write Multiple registers
|
||||
};
|
||||
//Exception Codes
|
||||
//Custom result codes used internally and for callbacks but never used for Modbus responce
|
||||
enum ResultCode {
|
||||
EX_SUCCESS = 0x00, // Custom. No error
|
||||
EX_ILLEGAL_FUNCTION = 0x01, // Function Code not Supported
|
||||
EX_ILLEGAL_ADDRESS = 0x02, // Output Address not exists
|
||||
EX_ILLEGAL_VALUE = 0x03, // Output Value not in Range
|
||||
EX_SLAVE_FAILURE = 0x04, // Slave or Master Device Fails to process request
|
||||
EX_ACKNOWLEDGE = 0x05, // Not used
|
||||
EX_SLAVE_DEVICE_BUSY = 0x06, // Not used
|
||||
EX_MEMORY_PARITY_ERROR = 0x08, // Not used
|
||||
EX_PATH_UNAVAILABLE = 0x0A, // Not used
|
||||
EX_DEVICE_FAILED_TO_RESPOND = 0x0B, // Not used
|
||||
EX_GENERAL_FAILURE = 0xE1, // Custom. Unexpected master error
|
||||
EX_DATA_MISMACH = 0xE2, // Custom. Inpud data size mismach
|
||||
EX_UNEXPECTED_RESPONSE = 0xE3, // Custom. Returned result doesn't mach transaction
|
||||
EX_TIMEOUT = 0xE4, // Custom. Operation not finished within reasonable time
|
||||
EX_CONNECTION_LOST = 0xE5, // Custom. Connection with device lost
|
||||
EX_CANCEL = 0xE6 // Custom. Transaction/request canceled
|
||||
EX_SUCCESS = 0x00U, // Custom. No error
|
||||
EX_ILLEGAL_FUNCTION = 0x01U, // Function Code not Supported
|
||||
EX_ILLEGAL_ADDRESS = 0x02U, // Output Address not exists
|
||||
EX_ILLEGAL_VALUE = 0x03U, // Output Value not in Range
|
||||
EX_SLAVE_FAILURE = 0x04U, // Slave or Master Device Fails to process request
|
||||
EX_ACKNOWLEDGE = 0x05U, // Not used
|
||||
EX_SLAVE_DEVICE_BUSY = 0x06U, // Not used
|
||||
EX_MEMORY_PARITY_ERROR = 0x08U, // Not used
|
||||
EX_PATH_UNAVAILABLE = 0x0AU, // Not used
|
||||
EX_DEVICE_FAILED_TO_RESPOND = 0x0BU, // Not used
|
||||
EX_GENERAL_FAILURE = 0xE1U, // Custom. Unexpected master error
|
||||
EX_DATA_MISMACH = 0xE2U, // Custom. Inpud data size mismach
|
||||
EX_UNEXPECTED_RESPONSE = 0xE3U, // Custom. Returned result doesn't mach transaction
|
||||
EX_TIMEOUT = 0xE4U, // Custom. Operation not finished within reasonable time
|
||||
EX_CONNECTION_LOST = 0xE5U, // Custom. Connection with device lost
|
||||
EX_CANCEL = 0xE6U // Custom. Transaction/request canceled
|
||||
};
|
||||
|
||||
~Modbus();
|
||||
|
||||
bool addHreg(uint16_t offset, uint16_t value = 0, uint16_t numregs = 1);
|
||||
bool addHreg(uint16_t offset, uint16_t value = 0U, uint16_t numregs = 1U);
|
||||
|
||||
bool Hreg(uint16_t offset, uint16_t value);
|
||||
|
||||
uint16_t Hreg(uint16_t offset);
|
||||
|
||||
uint16_t removeHreg(uint16_t offset, uint16_t numregs = 1);
|
||||
uint16_t removeHreg(uint16_t offset, uint16_t numregs = 1U);
|
||||
|
||||
bool addCoil(uint16_t offset, bool value = false, uint16_t numregs = 1);
|
||||
bool addCoil(uint16_t offset, bool value = false, uint16_t numregs = 1U);
|
||||
|
||||
bool addIsts(uint16_t offset, bool value = false, uint16_t numregs = 1);
|
||||
bool addIsts(uint16_t offset, bool value = false, uint16_t numregs = 1U);
|
||||
|
||||
bool addIreg(uint16_t offset, uint16_t value = 0, uint16_t numregs = 1);
|
||||
bool addIreg(uint16_t offset, uint16_t value = 0U, uint16_t numregs = 1U);
|
||||
|
||||
bool Coil(uint16_t offset, bool value);
|
||||
|
||||
@@ -185,11 +185,11 @@ public:
|
||||
|
||||
uint16_t Ireg(uint16_t offset);
|
||||
|
||||
bool removeCoil(uint16_t offset, uint16_t numregs = 1);
|
||||
bool removeCoil(uint16_t offset, uint16_t numregs = 1U);
|
||||
|
||||
bool removeIsts(uint16_t offset, uint16_t numregs = 1);
|
||||
bool removeIsts(uint16_t offset, uint16_t numregs = 1U);
|
||||
|
||||
bool removeIreg(uint16_t offset, uint16_t numregs = 1);
|
||||
bool removeIreg(uint16_t offset, uint16_t numregs = 1U);
|
||||
|
||||
/*
|
||||
bool Hreg(uint16_t offset, uint16_t* value);
|
||||
@@ -253,19 +253,19 @@ private:
|
||||
protected:
|
||||
//Reply Types
|
||||
enum ReplyCode {
|
||||
REPLY_OFF = 0x01,
|
||||
REPLY_ECHO = 0x02,
|
||||
REPLY_NORMAL = 0x03,
|
||||
REPLY_ERROR = 0x04,
|
||||
REPLY_UNEXPECTED = 0x05
|
||||
REPLY_OFF = 0x01U,
|
||||
REPLY_ECHO = 0x02U,
|
||||
REPLY_NORMAL = 0x03U,
|
||||
REPLY_ERROR = 0x04U,
|
||||
REPLY_UNEXPECTED = 0x05U
|
||||
};
|
||||
#ifndef MB_GLOBAL_REGS
|
||||
std::vector<TRegister> _regs;
|
||||
std::vector<TCallback> _callbacks;
|
||||
#endif
|
||||
uint8_t *_frame = nullptr;
|
||||
uint16_t _len = 0;
|
||||
uint8_t _reply = 0;
|
||||
uint16_t _len = 0U;
|
||||
uint8_t _reply = 0U;
|
||||
bool cbEnabled = true;
|
||||
|
||||
uint16_t mbCallback(TRegister *reg, uint16_t val, TCallback::CallbackType t);
|
||||
|
||||
Reference in New Issue
Block a user