API  2.3.0
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Master

Modules

 Master Configuration
 

Typedefs

typedef void * xMBMHandle
 A handle to a MODBUS master instance.
 

Enumerations

enum  eMBMQueryState {
  MBM_STATE_NONE, MBM_STATE_SEND, MBM_STATE_WAITING, MBM_STATE_DISASSEMBLE,
  MBM_STATE_ERROR, MBM_STATE_DONE
}
 States used by the MODBUS stack internally. More...
 

Functions

_DLLEXP eMBErrorCode eMBMSetSlaveTimeout (xMBMHandle xHdl, USHORT usNMilliSeconds)
 Set the slave timeout for the next request. More...
 
_DLLEXP eMBErrorCode eMBMClose (xMBMHandle xHdl)
 Close the stack. More...
 
_DLLEXP eMBErrorCode eMBMGetStatistics (xMBMHandle xHdl, xMBStat *pxMBMCurrentStat)
 Retrieve the current master statistics. More...
 
_DLLEXP eMBErrorCode eMBMResetStatistics (xMBMHandle xHdl)
 Clears the current statistic counters. More...
 
_DLLEXP eMBErrorCode eMBMRegisterProtAnalyzer (xMBMHandle xHdl, void *pvCtxArg, pvMBAnalyzerCallbackCB pvMBAnalyzerCallbackFN)
 Register an protocol analyzer. More...
 
_DLLEXP eMBErrorCode eMBMReadHoldingRegisters (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usRegStartAddress, UBYTE ubNRegs, USHORT arusBufferOut[])
 Read Holding Registers from a slave using the MODBUS function code 0x03 More...
 
_DLLEXP eMBErrorCode eMBMWriteSingleRegister (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usRegAddress, USHORT usValue)
 Write Single Register in a slave using the MODBUS function code 0x06. More...
 
_DLLEXP eMBErrorCode eMBMReadInputRegisters (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usRegStartAddress, UBYTE ubNRegs, USHORT arusBufferOut[])
 Read Input Registers from a slave using the MODBUS function code 0x04. More...
 
_DLLEXP eMBErrorCode eMBMWriteMultipleRegisters (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usRegStartAddress, UBYTE ubNRegs, const USHORT arusBufferIn[])
 Write Multiple Registers from a slave using the MODBUS function code 0x10. More...
 
_DLLEXP eMBErrorCode eMBMReadWriteMultipleRegisters (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usWriteRegStartAddress, UBYTE ubWriteNRegs, const USHORT arusBufferIn[], USHORT usReadRegStartAddress, UBYTE ubReadNRegs, USHORT arusBufferOut[])
 Read/Write Multiple Registers from a slave using the MODBUS function code 0x17 More...
 
_DLLEXP eMBErrorCode eMBMReadDiscreteInputs (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usInputStartAddress, USHORT usNInputs, UBYTE arubBufferOut[])
 Read Discrete Inputs from a slave using the MODBUS function code 0x02 More...
 
_DLLEXP eMBErrorCode eMBMReadCoils (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usCoilStartAddress, USHORT usNCoils, UBYTE arubBufferOut[])
 Read Coils from a slave using the MODBUS function code 0x01 More...
 
_DLLEXP eMBErrorCode eMBMWriteSingleCoil (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usOutputAddress, BOOL bOn)
 Write Coil on slave using the MODBUS function code 0x05 More...
 
_DLLEXP eMBErrorCode eMBMWriteCoils (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usCoilStartAddress, USHORT usNCoils, const UBYTE arubCoilsIn[])
 Write Coils from a slave using the MODBUS function code 0x0F More...
 
_DLLEXP eMBErrorCode eMBMReadWriteRAWPDU (xMBMHandle xHdl, UCHAR ucSlaveAddress, UCHAR ucFunctionCode, const UBYTE arubPayloadIn[], UBYTE ubPayloadInLength, UBYTE arubPayloadOut[], UBYTE ubPayloadOutLengthMax, UBYTE *pubPayloadOutLength)
 A function for sending raw MODBUS PDUs to a MODBUS slave. This function can be used if you want to transport custom data over a MODBUS connection or for briding other protocols. Please note that of course most standard slaves won't know how to deal with these custom data payload and therefore its use should be limited. More...
 
_DLLEXP eMBErrorCode eMBMReportSlaveID (xMBHandle xHdl, UCHAR ucSlaveAddress, UBYTE arubBufferOut[], UBYTE ubBufferMax, UBYTE *pubLength)
 Report slave ID from a MODBUS slave with function code 0x11 More...
 
_DLLEXP eMBErrorCode eMBMReadFileRecord (xMBHandle xHdl, UCHAR ucSlaveAddress, const xMBMFileSubReadReq_t arxSubRequests[], xMBMFileSubReadResp_t arxSubResponses[], USHORT usNSubRequests)
 )Read File Record from a MODBUS slave with function code 0x14 More...
 
_DLLEXP eMBErrorCode eMBMWriteFileRecord (xMBHandle xHdl, UCHAR ucSlaveAddress, const xMBMFileSubWriteReq_t arxSubRequests[], USHORT usNSubRequests)
 )Write File Record to a MODBUS slave with function code 0x15 More...
 
_DLLEXP void vMBMReadHoldingRegistersPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usRegStartAddress, UBYTE ubNRegs, USHORT arusBufferOut[], eMBMQueryState *peState, eMBErrorCode *peStatus)
 Read Holding Registers from a slave using the MODBUS function code 0x03 with the Non-Blocking API. More...
 
_DLLEXP void vMBMWriteSingleRegisterPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usRegAddress, USHORT usValue, eMBMQueryState *peState, eMBErrorCode *peStatus)
 Write Single Register in a slave using the MODBUS function code 0x06 with the Non-Blocking API. More...
 
_DLLEXP void vMBMReadInputRegistersPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usRegStartAddress, UBYTE ubNRegs, USHORT arusBufferOut[], eMBMQueryState *peState, eMBErrorCode *peStatus)
 Read Input Registers from a slave using the MODBUS function code 0x04 with the Non-Blocking API. More...
 
_DLLEXP void vMBMWriteMultipleRegistersPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usRegStartAddress, UBYTE ubNRegs, const USHORT arusBufferIn[], eMBMQueryState *peState, eMBErrorCode *peStatus)
 Write Multiple Registers from a slave using the MODBUS function code 0x10. More...
 
_DLLEXP void vMBMReadWriteMultipleRegistersPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usWriteRegStartAddress, UBYTE ubWriteNRegs, const USHORT arusBufferIn[], USHORT usReadRegStartAddress, UBYTE ubReadNRegs, USHORT arusBufferOut[], eMBMQueryState *peState, eMBErrorCode *peStatus)
 Read/Write Multiple Registers from a slave using the MODBUS function code 0x17 More...
 
_DLLEXP void vMBMReadDiscreteInputsPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usInputStartAddress, USHORT usNInputs, UBYTE arubBufferOut[], eMBMQueryState *peState, eMBErrorCode *peStatus)
 Read Discrete Inputs from a slave using the MODBUS function code 0x02 More...
 
_DLLEXP void vMBMReadCoilsPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usCoilStartAddress, USHORT usNCoils, UBYTE arubBufferOut[], eMBMQueryState *peState, eMBErrorCode *peStatus)
 Read Coils from a slave using the MODBUS function code 0x01 More...
 
_DLLEXP void vMBMWriteSingleCoilPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usOutputAddress, BOOL bOn, eMBMQueryState *peState, eMBErrorCode *peStatus)
 Write Coil on slave using the MODBUS function code 0x06 More...
 
_DLLEXP void vMBMWriteCoilsPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, USHORT usCoilStartAddress, USHORT usNCoils, const UBYTE arubCoilsIn[], eMBMQueryState *peState, eMBErrorCode *peStatus)
 Write Coils from a slave using the MODBUS function code 0x0F More...
 
_DLLEXP void vMBMReadWriteRAWPDUPolled (xMBMHandle xHdl, UCHAR ucSlaveAddress, UCHAR ucFunctionCode, const UBYTE arubPayloadIn[], UBYTE ubPayloadInLength, UBYTE arubPayloadOut[], UBYTE ubPayloadOutLengthMax, UBYTE *pubPayloadOutLength, eMBMQueryState *peState, eMBErrorCode *peStatus)
 A function for sending raw MODBUS PDUs to a MODBUS slave. This function can be used if you want to transport custom data over a MODBUS connection or for briding other protocols. Please note that of course most standard slaves won't know how to deal with these custom data payload and therefore its use should be limited. More...
 
_DLLEXP void vMBMReportSlaveID (xMBHandle xHdl, UCHAR ucSlaveAddress, UBYTE arubBufferOut[], UBYTE ubBufferMax, UBYTE *pubLength, eMBMQueryState *peState, eMBErrorCode *peStatus)
 Report slave ID from a MODBUS slave with function code 0x11 More...
 
void vMBMReadFileRecordPolled (xMBHandle xHdl, UCHAR ucSlaveAddress, const xMBMFileSubReadReq_t arxSubRequests[], xMBMFileSubReadResp_t arxSubResponses[], USHORT usNSubRequests, eMBMQueryState *peState, eMBErrorCode *peStatus)
 )Read File Record from a MODBUS slave with function code 0x14 More...
 
_DLLEXP void vMBMWriteFileRecordPolled (xMBHandle xHdl, UCHAR ucSlaveAddress, const xMBMFileSubWriteReq_t arxSubRequests[], USHORT usNSubRequests, eMBMQueryState *peState, eMBErrorCode *peStatus)
 )Write File Record to a MODBUS slave with function code 0x15 More...
 
_DLLEXP eMBErrorCode eMBMSerialInit (xMBMHandle *pxHdl, eMBSerialMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBSerialParity eParity)
 Create a new instances for a serial MODBUS master instance using either ASCII or RTU transmission mode. More...
 
_DLLEXP eMBErrorCode eMBMSerialInitExt (xMBMHandle *pxHdl, eMBSerialMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBSerialParity eParity, UCHAR ucStopBits)
 Create a new instances for a serial MODBUS master instance using either ASCII or RTU transmission mode. More...
 
_DLLEXP eMBErrorCode eMBMTCPInit (xMBMHandle *pxHdl)
 Create a new instaces for a MODBUS TCP master. More...
 
_DLLEXP eMBErrorCode eMBMTCPConnect (xMBMHandle xHdl, const CHAR *pcTCPClientAddress, USHORT usTCPPort)
 Connect to a new MODBUS TCP slave. More...
 
_DLLEXP eMBErrorCode eMBMTCPDisconnect (xMBMHandle xHdl)
 Disconnects a MODBUS TCP slave. More...
 
_DLLEXP eMBErrorCode eMBMUDPInit (xMBMHandle *pxHdl, const CHAR *pcUDPBindAddress, LONG uUDPListenPort)
 Create a new instaces for a MODBUS UDP master. More...
 
_DLLEXP eMBErrorCode eMBMUDPSetSlave (xMBMHandle xHdl, const CHAR *pcUDPClientAddress, USHORT usUDPSlavePort)
 Set the IP address of the MODBUS UDP slave. More...
 
BOOL bMBMIsHdlValid (const xMBMInternalHandle *pxIntHdl)
 Checks if a handle is valid.
 
void vMBMMasterTransactionPolled (xMBMInternalHandle *pxIntHdl, UCHAR ucSlaveAddress, eMBMQueryState *peState, eMBErrorCode *peStatus)
 The common part of the state machine for a MODBUS transaction.
 

Detailed Description

Enumeration Type Documentation

States used by the MODBUS stack internally.

Note
These values are not important for the user and should not be accessed or used. They are used by the polled versions of the API calls.
Enumerator
MBM_STATE_NONE 

Not yet started.

MBM_STATE_SEND 

Frame will be sent.

MBM_STATE_WAITING 

Waiting for an event.

MBM_STATE_DISASSEMBLE 

Disassembling the frame.

MBM_STATE_ERROR 

An error occurred.

MBM_STATE_DONE 

We are done processing the request.

Function Documentation

eMBErrorCode eMBMClose ( xMBMHandle  xHdl)

Close the stack.

Shutdown the master stack. This function should not be called when there are still pending requests.

Parameters
xHdlA handle for a MODBUS master instances.
Returns
eMBErrorCode::MB_ENOERR if the stack has been shut down.
_DLLEXP eMBErrorCode eMBMGetStatistics ( xMBMHandle  xHdl,
xMBStat pxMBMCurrentStat 
)

Retrieve the current master statistics.

This function populates the argument pxMBMCurrentStat with the current internal counters.

Parameters
xHdlA valid MODBUS master handle.
pxMBMCurrentStatA pointer to an (potentially unitialized) eMBMStat datastructure. When the return value is eMBErrorCode::MB_ENOERR this data structure holds a copy of the internal counters.
Returns
eMBErrorCode::MB_ENOERR if successful. In case of an invalid argument the function returns eMBErrorCode::MB_EINVAL.
_DLLEXP eMBErrorCode eMBMReadCoils ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usCoilStartAddress,
USHORT  usNCoils,
UBYTE  arubBufferOut[] 
)

Read Coils from a slave using the MODBUS function code 0x01

The coils are packed as one coil per bit. Statis is 1=ON and 0=OFF. The LSB of the first data byte contains the coil addressed in the query. The other coils follow toward the high order of the byte. If the input quantity is not a multiple of eight the final data byte is padded with zeros.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usCoilStartAddressAddress of first coil.
usNCoilsNumber of coils to read.
arubBufferOutAn array with a size of at least usNCoils/8 bytes. The size must be rounded up to next integer.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In this case the array arubBufferIn contains the values returned by the slave. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT.
Examples:
modbus_master_rtu.c.
_DLLEXP eMBErrorCode eMBMReadDiscreteInputs ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usInputStartAddress,
USHORT  usNInputs,
UBYTE  arubBufferOut[] 
)

Read Discrete Inputs from a slave using the MODBUS function code 0x02

The discrete inputs are packed as one input per bit. Statis is 1=ON and 0=OFF. The LSB of the first data byte contains the input addressed in the query. The other inputs follow toward the high order of the byte. If the input quantity is not a multiple of eight the final data byte is padded with zeros.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usInputStartAddressAddress of first discrete input.
usNInputsNumber of discrete inputs to read.
arubBufferOutAn array with a size of at least usNInputs/8 bytes. The size must be rounded up to next integer.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In this case the array arubBufferIn contains the values returned by the slave. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT.
_DLLEXP eMBErrorCode eMBMReadFileRecord ( xMBHandle  xHdl,
UCHAR  ucSlaveAddress,
const xMBMFileSubReadReq_t  arxSubRequests[],
xMBMFileSubReadResp_t  arxSubResponses[],
USHORT  usNSubRequests 
)

)Read File Record from a MODBUS slave with function code 0x14

This function issues a read file record request. The caller of this function is required to provide an (possibly unitialized) array of arxSubResponses. The size of this array must be equal or larger than the number of sub requests within arxSubRequests.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
arxSubRequestsSub requests for file records.
arxSubResponsesA sub response for every requested arxSubRequests.
usNSubRequestsSize of the arxSubRequests arrays.
Returns
eMBErrorCode::MB_ENOERR if the read file record command was successfull. If the arguments are not valid, e.g the number of sub requests would exceed the maximum length of a MODBUS frame, the function returns eMBErrorCode::MB_EINVAL. In case of an exception returned by the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT.
_DLLEXP eMBErrorCode eMBMReadHoldingRegisters ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usRegStartAddress,
UBYTE  ubNRegs,
USHORT  arusBufferOut[] 
)

Read Holding Registers from a slave using the MODBUS function code 0x03

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address. Note that a broadcast address is not allowed for a function which expects a response.
usRegStartAddressThe first holding register to be read. We use protocol addresses starting at zero.
ubNRegsNumber of registers to read.
arusBufferOutAn array of USHORT values of at least ubNRegs elements.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In this case the array arusBufferOut contains the values returned by the slave. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT. Any other errors are IO errors.
_DLLEXP eMBErrorCode eMBMReadInputRegisters ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usRegStartAddress,
UBYTE  ubNRegs,
USHORT  arusBufferOut[] 
)

Read Input Registers from a slave using the MODBUS function code 0x04.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address. Not that a broadcast address is not allowed.
usRegStartAddressFirst register to read.
ubNRegsNumer of registers to read.
arusBufferOutAn array of USHORT values of at least ubNRegs elements.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In this case the array arusBufferOut contains the values returned by the slave. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT. Any other errors are IO errors.
Examples:
modbus_master_rtu.c.
_DLLEXP eMBErrorCode eMBMReadWriteMultipleRegisters ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usWriteRegStartAddress,
UBYTE  ubWriteNRegs,
const USHORT  arusBufferIn[],
USHORT  usReadRegStartAddress,
UBYTE  ubReadNRegs,
USHORT  arusBufferOut[] 
)

Read/Write Multiple Registers from a slave using the MODBUS function code 0x17

Note
The pointers arusBufferIn and arusBufferOut can point to the same memory location. In this case the old contents is overwritten with the returned registers values.
Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usWriteRegStartAddressFirst register to write on the slave.
ubWriteNRegsNumber of registers to write.
arusBufferInAn Array of USHORT values of ubWriteNRegs elements which should be written on the slave.
usReadRegStartAddressFirst register to read from the slave.
ubReadNRegsNumber of registers to read.
arusBufferOutAn Array of ubReadNRegs elements where the registers values returned by the slave should be stored.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In this case the array arusBufferOut contains the values returned by the slave. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT. Any other errors are IO errors.
_DLLEXP eMBErrorCode eMBMReadWriteRAWPDU ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
UCHAR  ucFunctionCode,
const UBYTE  arubPayloadIn[],
UBYTE  ubPayloadInLength,
UBYTE  arubPayloadOut[],
UBYTE  ubPayloadOutLengthMax,
UBYTE *  pubPayloadOutLength 
)

A function for sending raw MODBUS PDUs to a MODBUS slave. This function can be used if you want to transport custom data over a MODBUS connection or for briding other protocols. Please note that of course most standard slaves won't know how to deal with these custom data payload and therefore its use should be limited.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
ucFunctionCodeMODBUS function code used for transport. Must be between 1 and 127. Recommend values are between 65-72 and 100-110.
arubPayloadInMODBUS request which will be sent to the slave.
ubPayloadInLengthLength of MODBUS request. Maximum is 252 bytes.
arubPayloadOutHolds the MODBUS response sent by the slave. arubPayloadOut can be NULL is ubPayloadOutLengthMax is set to zero.
ubPayloadOutLengthMaxSize of the buffer arubPayloadOut in bytes. If the slave response exceeds the number of bytes available in the buffer the function returns eMBErrorCode::MB_EINVAL.
pubPayloadOutLengthActual number of bytes returned by the slave.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. If the input arguments are invalid, for example arubPayloadIn is a NULL pointer, the function returns eMBErrorCode::MB_EINVAL. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT.
_DLLEXP eMBErrorCode eMBMRegisterProtAnalyzer ( xMBMHandle  xHdl,
void *  pvCtxArg,
pvMBAnalyzerCallbackCB  pvMBAnalyzerCallbackFN 
)

Register an protocol analyzer.

If a protocol analyzer has been registered a callback is made whenever a frame has been sent or received.

Parameters
xHdlA valid MODBUS master handle.
pvMBAnalyzerCallbackFNA valid pointer to a callback handler or NULL if the analyzer should be removed.
pvCtxArgA user defined context. Can be NULL.
Returns
eMBErrorCode::MB_ENOERR if the analyzer has been added or removed. eMBErrorCode::MB_EINVAL in case of an invalid MODBUS handle.
_DLLEXP eMBErrorCode eMBMReportSlaveID ( xMBHandle  xHdl,
UCHAR  ucSlaveAddress,
UBYTE  arubBufferOut[],
UBYTE  ubBufferMax,
UBYTE *  pubLength 
)

Report slave ID from a MODBUS slave with function code 0x11

This function issues the report slave id command to a MODBUS slave. The response is then stored in the buffer provided by arubBufferOut where the caller has to allocate sufficient space. The maximum amount of space available is determined by ubBufferMax. If there is not enough space available the function returns eMBErrorCode::MB_ENORES.

There is no chance for the MODBUS stack to tell something about the content since the content is vendor specific.

Note
There are some non vendor specific fields but most vendors do not implement them correctly. Therefore we have completely avoided interpreting the data.
Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
arubBufferOutBuffer which can hold ubBufferMax bytes.
ubBufferMaxSize of buffer.
pubLengthIf the call succeeds contains the number of bytes written to the buffer.
Returns
eMBErrorCode::MB_ENOERR if the slave report command succeeded. If the buffer does not have enough space the function returns eMBErrorCode::MB_ENORES. If any of the input arguments are invalid or the buffer are NULL the function return eMBErrorCode::MB_EINVAL. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT.
_DLLEXP eMBErrorCode eMBMResetStatistics ( xMBMHandle  xHdl)

Clears the current statistic counters.

Parameters
xHdlA valid MODBUS master handle.
Returns
eMBErrorCode::MB_ENOERR if successful. In case of an invalid argument the function returns eMBErrorCode::MB_EINVAL.
_DLLEXP eMBErrorCode eMBMSerialInit ( xMBMHandle pxHdl,
eMBSerialMode  eMode,
UCHAR  ucPort,
ULONG  ulBaudRate,
eMBSerialParity  eParity 
)

Create a new instances for a serial MODBUS master instance using either ASCII or RTU transmission mode.

Note
In RTU mode 11 bits are used for each data byte. The coding system is 8bit binary.
  • 1 start bit.
  • 8 data bits with LSB sent first.
  • 1 bit for parity (Even, Odd)
  • 1 or 2 stop bits (Two stopbits if no parity is used).

In ASCII mode 10 bits are used. The coding system uses the hexadecimal ASCII characters 0-8 and A-F. One hexadecimal characters contains 4-bits of data.

  • 1 start bit
  • 7 data bits with LSB sent first.
  • 1 bit for parity (Even, Odd)
  • 1 or 2 stop bits (Two stopbits if no parity is used).
Parameters
pxHdlA pointer to a MODBUS handle. If the function returns MB_ENOERR the handle is updated to hold a new and valid master handle. This handle should never be modified by the user.
eModeThe serial transmission mode to use. Either MB_RTU or MB_ASCII.
ucPortThe serial port to use. The meaning of this value depends on the porting layer.
ulBaudRateThe baudrate. For example 38400.
eParityThe parity to use.
Returns
eMBErrorCode::MB_ENOERR if a new MASTER instances is ready.
Examples:
modbus_master_rtu.c.
_DLLEXP eMBErrorCode eMBMSerialInitExt ( xMBMHandle pxHdl,
eMBSerialMode  eMode,
UCHAR  ucPort,
ULONG  ulBaudRate,
eMBSerialParity  eParity,
UCHAR  ucStopBits 
)

Create a new instances for a serial MODBUS master instance using either ASCII or RTU transmission mode.

Identical to eMBMSerialInit with the exception that the number of stopbits can be set. Note that this can result in non standard conforming behavior.

Parameters
pxHdlA pointer to a MODBUS handle. If the function returns MB_ENOERR the handle is updated to hold a new and valid master handle. This handle should never be modified by the user.
eModeThe serial transmission mode to use. Either MB_RTU or MB_ASCII.
ucPortThe serial port to use. The meaning of this value depends on the porting layer.
ulBaudRateThe baudrate. For example 38400.
eParityThe parity to use.
ucStopBitsNumber of stopbits to use.
Returns
eMBErrorCode::MB_ENOERR if a new MASTER instances is ready.
eMBErrorCode eMBMSetSlaveTimeout ( xMBMHandle  xHdl,
USHORT  usNMilliSeconds 
)

Set the slave timeout for the next request.

Parameters
xHdlA valid MODBUS master handle.
usNMilliSecondsThe new slave device timeout. If no response is received within this time window after a MODBUS request has been sent to the slave the API functions will return eMBErrorCode::MB_ETIMEDOUT to indicate an timeout error.
Returns
eMBErrorCode::MB_ENOERR if the new slave timeout will be used on the next request.
_DLLEXP eMBErrorCode eMBMTCPConnect ( xMBMHandle  xHdl,
const CHAR *  pcTCPClientAddress,
USHORT  usTCPPort 
)

Connect to a new MODBUS TCP slave.

If a connection is already open the old connection is closed.

Parameters
xHdlA valid MODBUS master handle.
pcTCPClientAddressA TCP client address. This address is directly passed to the porting layer and therefore its meaning is platform dependent.
usTCPPortThe TCP port to use. 502 is standard.
Returns
eMBErrorCode::MB_ENOERR if a connection has been opened. In case of a connection error eMBErrorCode::MB_EIO.
_DLLEXP eMBErrorCode eMBMTCPDisconnect ( xMBMHandle  xHdl)

Disconnects a MODBUS TCP slave.

Parameters
xHdlA valid MODBUS master handle.
_DLLEXP eMBErrorCode eMBMTCPInit ( xMBMHandle pxHdl)

Create a new instaces for a MODBUS TCP master.

Parameters
pxHdlA pointer to a MODBUS handle. If the function returns MB_ENOERR the handle is updated to hold a new and valid master handle. This handle should never be modified by the user.
Returns
eMBErrorCode::MB_ENOERR if a new MASTER instances is ready.
_DLLEXP eMBErrorCode eMBMUDPInit ( xMBMHandle pxHdl,
const CHAR *  pcUDPBindAddress,
LONG  uUDPListenPort 
)

Create a new instaces for a MODBUS UDP master.

Parameters
pxHdlA pointer to a MODBUS handle. If the function returns MB_ENOERR the handle is updated to hold a new and valid master handle. This handle should never be modified by the user.
pcUDPBindAddressNot used within the stack but passed to the porting layer. This argument can be used to bind only to a specific IP address.
uUDPListenPortUse -1 if the listing port should be allocated dynamically by the porting layer. Otherwise pass a valid port number between 0 and 65535.
Returns
eMBErrorCode::MB_ENOERR if a new MASTER instances is ready.
_DLLEXP eMBErrorCode eMBMUDPSetSlave ( xMBMHandle  xHdl,
const CHAR *  pcUDPClientAddress,
USHORT  usUDPSlavePort 
)

Set the IP address of the MODBUS UDP slave.

Not data is actually sent by specifying the client address. All future data sent by any of the read/write registers calls will be directed to this client address. The previous client address is overwritten.

Parameters
xHdlA valid MODBUS master handle.
pcUDPClientAddressA UDP client address. This address is directly passed to the porting layer and therefore its meaning is platform dependent.
usUDPSlavePortThe UDP port to use. 502 is standard.
Returns
eMBErrorCode::MB_ENOERR if a connection has been opened. In case of a connection error eMBErrorCode::MB_EIO.
Warning
A reference to pcUDPClientAddress is stored internally. As long as this instance is used the data where pcUDPClientAddress points to must not change. This specially implies that extra care has to be taken when the address is stored on the stack.
_DLLEXP eMBErrorCode eMBMWriteCoils ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usCoilStartAddress,
USHORT  usNCoils,
const UBYTE  arubCoilsIn[] 
)

Write Coils from a slave using the MODBUS function code 0x0F

The coils are packed as one coil per bit. Statis is 1=ON and 0=OFF. The LSB of the first data byte contains the coil addressed in the query. The other coils follow toward the high order of the byte.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usCoilStartAddressAddress of first coil.
usNCoilsNumber of coils to read.
arubCoilsInAn array with a size of at least usNCoils/8 bytes. The size must be rounded up to next integer. A
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In this case the array arubBufferIn contains the values returned by the slave. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT.
_DLLEXP eMBErrorCode eMBMWriteFileRecord ( xMBHandle  xHdl,
UCHAR  ucSlaveAddress,
const xMBMFileSubWriteReq_t  arxSubRequests[],
USHORT  usNSubRequests 
)

)Write File Record to a MODBUS slave with function code 0x15

This function issues a write file record request. The caller of this function is required to provide an array of arxSubRequests.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
arxSubRequestsSub requests for file records.
usNSubRequestsSize of the arxSubRequests arrays.
Returns
eMBErrorCode::MB_ENOERR if the write file record command was successfull. If the arguments are not valid, e.g the number of sub requests would exceed the maximum length of a MODBUS frame, the function returns eMBErrorCode::MB_EINVAL. In case of an exception returned by the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT.
_DLLEXP eMBErrorCode eMBMWriteMultipleRegisters ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usRegStartAddress,
UBYTE  ubNRegs,
const USHORT  arusBufferIn[] 
)

Write Multiple Registers from a slave using the MODBUS function code 0x10.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usRegStartAddressFirst register to write to.
ubNRegsNumber of registers to write.
arusBufferInAn Array of USHORT values of at least ubNRegs elements.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In this case the array arusBufferOut contains the values returned by the slave. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT. Any other errors are IO errors.
_DLLEXP eMBErrorCode eMBMWriteSingleCoil ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usOutputAddress,
BOOL  bOn 
)

Write Coil on slave using the MODBUS function code 0x05

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usOutputAddressAddress of coil.
bOnEither TRUE or FALSE.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT.
Examples:
modbus_master_rtu.c.
_DLLEXP eMBErrorCode eMBMWriteSingleRegister ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usRegAddress,
USHORT  usValue 
)

Write Single Register in a slave using the MODBUS function code 0x06.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address. Note that a broadcast address is not allowed for a function which expects a response.
usRegAddressThe register address to write.
usValueThe value which should be written to the register.
Returns
eMBErrorCode::MB_ENOERR if the slave responded within the timeout and the the reply conforms to the MODBUS protocol specification. In this case the array arusBufferOut contains the values returned by the slave. In case of an exception from the slave any of the MODBUS exceptions can be returned. If the slave did not respond within the timeout the function returns eMBErrorCode::MB_ETIMEDOUT. Any other errors are IO errors.
_DLLEXP void vMBMReadCoilsPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usCoilStartAddress,
USHORT  usNCoils,
UBYTE  arubBufferOut[],
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Read Coils from a slave using the MODBUS function code 0x01

The coils are packed as one coil per bit. Statis is 1=ON and 0=OFF. The LSB of the first data byte contains the coil addressed in the query. The other coils follow toward the high order of the byte. If the input quantity is not a multiple of eight the final data byte is padded with zeros.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usCoilStartAddressAddress of first coil.
usNCoilsNumber of coils to read.
arubBufferOutAn array with a size of at least udNInputs/8 bytes. The size must be rounded up to next integer.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMReadDiscreteInputsPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usInputStartAddress,
USHORT  usNInputs,
UBYTE  arubBufferOut[],
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Read Discrete Inputs from a slave using the MODBUS function code 0x02

The discrete inputs are packed as one input per bit. Statis is 1=ON and 0=OFF. The LSB of the first data byte contains the input addressed in the query. The other inputs follow toward the high order of the byte. If the input quantity is not a multiple of eight the final data byte is padded with zeros.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usInputStartAddressAddress of first discrete input.
usNInputsNumber of discrete inputs to read.
arubBufferOutAn array with a size of at least udNInputs/8 bytes. The size must be rounded up to next integer.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
void vMBMReadFileRecordPolled ( xMBHandle  xHdl,
UCHAR  ucSlaveAddress,
const xMBMFileSubReadReq_t  arxSubRequests[],
xMBMFileSubReadResp_t  arxSubResponses[],
USHORT  usNSubRequests,
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

)Read File Record from a MODBUS slave with function code 0x14

This function issues a read file record request. The caller of this function is required to provide an (possibly unitialized) array of arxSubResponses. The size of this array must be equal or larger than the number of sub requests within arxSubRequests.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
arxSubRequestsSub requests for file records.
arxSubResponsesA sub response for every requested arxSubRequests.
usNSubRequestsSize of the arxSubRequests arrays.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version eMBMReadFileRecord.
_DLLEXP void vMBMReadHoldingRegistersPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usRegStartAddress,
UBYTE  ubNRegs,
USHORT  arusBufferOut[],
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Read Holding Registers from a slave using the MODBUS function code 0x03 with the Non-Blocking API.

This function provides the same functionality as the function eMBMReadHoldingRegisters but uses a different interface.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address. Note that a broadcast address is not allowed for a function which expects a response.
usRegStartAddressThe first holding register to be read. We use protocol addresses starting at zero.
ubNRegsNumber of registers to read.
arusBufferOutAn array of USHORT values of at least ubNRegs elements.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMReadInputRegistersPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usRegStartAddress,
UBYTE  ubNRegs,
USHORT  arusBufferOut[],
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Read Input Registers from a slave using the MODBUS function code 0x04 with the Non-Blocking API.

This function provides the same functionality as the function eMBMReadInputRegisters but uses a different interface.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address. Note that a broadcast address is not allowed.
usRegStartAddressThe first holding register to be read starting at zero.
ubNRegsNumber of registers to read.
arusBufferOutAn array of USHORT values of at least ubNRegs elements.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMReadWriteMultipleRegistersPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usWriteRegStartAddress,
UBYTE  ubWriteNRegs,
const USHORT  arusBufferIn[],
USHORT  usReadRegStartAddress,
UBYTE  ubReadNRegs,
USHORT  arusBufferOut[],
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Read/Write Multiple Registers from a slave using the MODBUS function code 0x17

Note
The pointers arusBufferIn and arusBufferOut can point to the same memory location. In this case the old contents is overwritten with the returned registers values.
Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usWriteRegStartAddressFirst register to write on the slave.
ubWriteNRegsNumber of registers to write.
arusBufferInAn Array of USHORT values of ubWriteNRegs elements which should be written on the slave.
usReadRegStartAddressFirst register to read from the slave.
ubReadNRegsNumber of registers to read.
arusBufferOutAn Array of ubReadNRegs elements where the registers values returned by the slave should be stored.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMReadWriteRAWPDUPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
UCHAR  ucFunctionCode,
const UBYTE  arubPayloadIn[],
UBYTE  ubPayloadInLength,
UBYTE  arubPayloadOut[],
UBYTE  ubPayloadOutLengthMax,
UBYTE *  pubPayloadOutLength,
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

A function for sending raw MODBUS PDUs to a MODBUS slave. This function can be used if you want to transport custom data over a MODBUS connection or for briding other protocols. Please note that of course most standard slaves won't know how to deal with these custom data payload and therefore its use should be limited.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
ucFunctionCodeMODBUS function code used for transport. Must be between 1 and 127. Recommend values are between 65-72 and 100-110.
arubPayloadInMODBUS request which will be sent to the slave.
ubPayloadInLengthLength of MODBUS request. Maximum is 252 bytes.
arubPayloadOutHolds the MODBUS response sent by the slave. arubPayloadOut can be NULL is ubPayloadOutLengthMax is set to zero.
ubPayloadOutLengthMaxSize of the buffer arubPayloadOut in bytes. If the slave response exceeds the number of bytes available in the buffer the function set peStatus to eMBErrorCode::MB_EINVAL.
pubPayloadOutLengthActual number of bytes returned by the slave.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMReportSlaveID ( xMBHandle  xHdl,
UCHAR  ucSlaveAddress,
UBYTE  arubBufferOut[],
UBYTE  ubBufferMax,
UBYTE *  pubLength,
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Report slave ID from a MODBUS slave with function code 0x11

This function issues the report slave id command to a MODBUS slave. The response is then stored in the buffer provided by arubBufferOut where the caller has to allocate sufficient space. The maximum amount of space available is determined by ubBufferMax. If there is not enough space available the function returns eMBErrorCode::MB_ENORES.

There is no chance for the MODBUS stack to tell something about the content since the content is vendor specific.

Note
There are some non vendor specific fields but most vendors do not implement them correctly. Therefore we have completely avoided interpreting the data.
Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
arubBufferOutBuffer which can hold ubBufferMax bytes.
ubBufferMaxSize of buffer.
pubLengthIf the call succeeds contains the number of bytes written to the buffer.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMWriteCoilsPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usCoilStartAddress,
USHORT  usNCoils,
const UBYTE  arubCoilsIn[],
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Write Coils from a slave using the MODBUS function code 0x0F

The coils are packed as one coil per bit. Statis is 1=ON and 0=OFF. The LSB of the first data byte contains the coil addressed in the query. The other coils follow toward the high order of the byte.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usCoilStartAddressAddress of first coil.
usNCoilsNumber of coils to read.
arubCoilsInAn array with a size of at least usNCoils/8 bytes. The size must be rounded up to next integer. A
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMWriteFileRecordPolled ( xMBHandle  xHdl,
UCHAR  ucSlaveAddress,
const xMBMFileSubWriteReq_t  arxSubRequests[],
USHORT  usNSubRequests,
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

)Write File Record to a MODBUS slave with function code 0x15

This function issues a write file record request. The caller of this function is required to provide an array of arxSubRequests.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
arxSubRequestsSub requests for file records.
usNSubRequestsSize of the arxSubRequests arrays.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version eMBMWriteFileRecord.
_DLLEXP void vMBMWriteMultipleRegistersPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usRegStartAddress,
UBYTE  ubNRegs,
const USHORT  arusBufferIn[],
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Write Multiple Registers from a slave using the MODBUS function code 0x10.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usRegStartAddressFirst register to write to.
ubNRegsNumber of registers to write.
arusBufferInAn Array of USHORT values of at least ubNRegs elements.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMWriteSingleCoilPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usOutputAddress,
BOOL  bOn,
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Write Coil on slave using the MODBUS function code 0x06

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address.
usOutputAddressAddress of coil.
bOnEither TRUE or FALSE.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.
_DLLEXP void vMBMWriteSingleRegisterPolled ( xMBMHandle  xHdl,
UCHAR  ucSlaveAddress,
USHORT  usRegAddress,
USHORT  usValue,
eMBMQueryState peState,
eMBErrorCode *  peStatus 
)

Write Single Register in a slave using the MODBUS function code 0x06 with the Non-Blocking API.

Parameters
xHdlA valid MODBUS master handle.
ucSlaveAddressSlave address. Note that a broadcast address is not allowed for a function which expects a response.
usRegAddressThe register address to write.
usValueThe value which should be written to the register.
peStateA pointer where the internal state can be stored. This value should be initialized to MBM_STATE_NONE. Violating this rule results in undefined behavior.
peStatusA pointer to a status variable. After the command has finished the status variable contains the final result of the transaction. The error codes are the same as for the blocking version.