EVE 1.0
modbus.h
Go to the documentation of this file.
1 #ifndef MODBUS_H_INCLUDED
2 #define MODBUS_H_INCLUDED
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2016, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  *
32  * The file is partially based on the Christian Walter's FreeModbus Library with
33  * the following copyright notice:
34  *
35  * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
36  * Copyright (c) 2006 Christian Walter <wolti@sil.at>
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  * notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  * notice, this list of conditions and the following disclaimer in the
46  * documentation and/or other materials provided with the distribution.
47  * 3. The name of the author may not be used to endorse or promote products
48  * derived from this software without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
51  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
54  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
55  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
59  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60  */
61 /**
62  * \file
63  * @brief Main public header file for the Modbus client/server/sniffer over
64  * TCP/UART EVE module.
65  *
66  * @author SE, Jetro AS
67  */ /******************************************************************/
68 
69 /**
70  * \defgroup modbus Modbus driver
71  * \ingroup abstract
72  * \{
73  */
74 
75 /**
76  * This module defines the Modbus driver interface for the application.
77  * It contains the basic functions and types required to use the Modbus protocol
78  * stack.
79  * A typical application will want to call MbInit() first. If the device
80  * is ready to answer network requests it must then call MbEnable() to activate
81  * the protocol stack.
82  */
83 
84 #include <sys/process.h>
85 #include <core/uwork.h>
86 #include <core/mwork.h>
87 
88 #define MB_SLAVEID_BUF_LEN 32 //!< Number of bytes which should be allocated for the <em>Report Slave ID </em>command.
89 
90 #define MB_SER_PDU_SIZE_MAX 255 //!< Maximum size of a Modbus RTU frame. 1 byte less than standard because of internal UART limitation.
91 
92 #define MB_TFILE_TARGET_SIZE 31 //!< Length of bit vector of targets for Transfer File function.
93 #define MB_TFILE_FNAMELEN_MAX 32 //!< Length of the buffer holding filename for Transfer File function. As file name is null-terminated, actual filenane length cannot exceed 31.
94 #define MB_TFILE_LAST_PACKET (1 << 31) //!< Bit flag in the packet number field of TransferFilePart frame denoting the last packet (file end).
95 #define MB_TFILE_PART_REGADDR 0xFF00 //!< Server's pseudo-register containing last part number for verification from client (2 registers actually: MB_TFILE_PART_REGADDR and MB_TFILE_PART_REGADDR+1)
96 
97 /**********************************************************************/
98 /**
99  * @brief Modbus server addresses
100  */
101 #define MB_ADDRESS_BROADCAST ( 0 ) //!< Modbus broadcast address.
102 #define MB_ADDRESS_MIN ( 1 ) //!< Smallest possible slave address.
103 #define MB_ADDRESS_MAX ( 247 ) //!< Biggest possible slave address.
104 #define MB_TCP_PSEUDO_ADDRESS ( 255 ) //!< Server address on Modbus over TCP
105 
106 /**********************************************************************/
107 /**
108  * @brief Modbus function codes
109  */
110 #define MB_FUNC_NONE (0x00) //!< Used as "invalid function"
111 #define MB_FUNC_READ_COILS (0x01) //!< Read Coils
112 #define MB_FUNC_READ_DISCRETE_INPUTS (0x02) //!< Read Discrete Inputs
113 #define MB_FUNC_READ_HOLDING_REGISTER (0x03) //!< Read Holding Registers
114 #define MB_FUNC_READ_INPUT_REGISTER (0x04) //!< Read Input Registers
115 #define MB_FUNC_WRITE_SINGLE_COIL (0x05) //!< Write Single Coil
116 #define MB_FUNC_WRITE_REGISTER (0x06) //!< Write Single Register
117 #define MB_FUNC_DIAG_READ_EXCEPTION (0x07) //!< Read Exception Status (Serial Line only)
118 #define MB_FUNC_DIAG_DIAGNOSTIC (0x08) //!< Diagnostics (Serial Line only)
119 #define MB_FUNC_DIAG_GET_COM_EVENT_CNT (0x0B) //!< Get Comm Event Counter (Serial Line only)
120 #define MB_FUNC_DIAG_GET_COM_EVENT_LOG (0x0C) //!< Get Comm Event Log (Serial Line only)
121 #define MB_FUNC_WRITE_MULTIPLE_COILS (0x0F) //!< Write Multiple Coils
122 #define MB_FUNC_WRITE_MULTIPLE_REGISTERS (0x10) //!< Write Multiple registers
123 #define MB_FUNC_REPORT_SERVER_ID (0x11) //!< Report Server ID (Serial Line only)
124 #define MB_FUNC_READ_FILE_RECORD (0x14) //!< Read File Record
125 #define MB_FUNC_WRITE_FILE_RECORD (0x15) //!< Write File Record
126 #define MB_FUNC_READWRITE_MULTIPLE_REGISTERS (0x17) //!< Read/Write Multiple registers
127 #define MB_FUNC_TRANSFER_FILE (0x64) //!< Transfer file - Jetro proprietary
128 #define MB_FUNC_TRANSFER_FILE_COMPLETED (0x65) //!< Transfer file complete - Jetro proprietary
129 #define MB_FUNC_NEW_FILE (0x66) //!< New file arrived - pseudo function, Jetro proprietary
130 #define MB_FUNC_ERROR (0x80) //!< Error flag for responses (ORed with function code)
131 
132 struct modbus_t;
133 
134 /**********************************************************************/
135 /**
136  * @brief Modbus events used in ModbusServerProcess and ModbusClientProcess
137  *
138  ***********************************************************************/
139 typedef enum
140 {
141  EV_MB_READY, //!< Modbus event: Startup finished.
142  EV_MB_FRAME_RECEIVED, //!< Modbus event: Frame received.
143  EV_MB_FRAME_SENT, //!< Modbus event: Frame sent.
144  EV_MB_SEND, //!< Modbus event: Request to send frame
145  EV_MB_CLOSE_SESSION, //!< Modbus event: Data exchange ended.
146  EVT_MB_T35_TIMEOUT, //!< 3.5 chars timeout expired
147  EV_MB_FT_CONTINUE, //!< Continue file transfer procedure
148  EV_MB__LAST,
149 } MbEvent_t;
150 
151 
152 /**********************************************************************/
153 /**
154  * @brief Modbus serial transmission modes (RTU/ASCII/TCP).
155  *
156  ***********************************************************************/
157 typedef enum
158 {
159  MB_RTU, //!< RTU transmission mode.
160  MB_ASCII, //!< ASCII transmission mode.
161  MB_TCP, //!< TCP mode.
162 } MbMode_t;
163 
164 /**********************************************************************/
165 /**
166  * @brief Modbus device role (MASTER/SLAVE/SNIFFER).
167  *
168  ***********************************************************************/
169 typedef enum
170 {
171  MB_SERVER, //!< Server (slave) role.
172  MB_CLIENT, //!< Client (master) role.
173  MB_SNIFFER, //!< Sniffer role.
174 } MbRole_t;
175 
176 /**********************************************************************/
177 /**
178  * @brief Modbus standard exception codes plus internal error codes used
179  * by all function in the protocol stack.
180  *
181  ***********************************************************************/
182 typedef enum
183 {
184  MB_EX_NONE = 0x00, //!< no error.
185  MB_EX_ILLEGAL_FUNCTION = 0x01, //!< The function code received in the query is not an allowable action for the server.
186  MB_EX_ILLEGAL_DATA_ADDRESS = 0x02, //!< illegal register address.
187  MB_EX_ILLEGAL_DATA_VALUE = 0x03, //!< illegal argument.
188  MB_EX_SERVER_DEVICE_FAILURE = 0x04, //!< An unrecoverable error occurred while the server was attempting to perform the requested action.
189  MB_EX_ACKNOWLEDGE = 0x05, //!< The server has accepted the request and is processing it, but a long duration of time will be required to do so. This response is returned to prevent a timeout error from occurring in the client.
190  MB_EX_SERVER_DEVICE_BUSY = 0x06, //!< The client should retransmit the message later when the server is free
191  MB_EX_MEMORY_PARITY_ERROR = 0x08, //!< In conjunction with function codes 20 and 21: The server attempted to read record file, but detected a parity error in the memory.
192  MB_EX_GATEWAY_PATH_FAILED = 0x0A, //!< In conjunction with gateways: indicates that the gateway was unable to allocate an internal communication path from the input port to the output port
193  MB_EX_GATEWAY_TGT_FAILED = 0x0B, //!< In conjunction with gateways: Specialized use in conjunction with gateways, indicates that no response was obtained from the target device
194  MB_EX_BUSY = 0x80, //!< ModbusLib INTERNAL exception: Master is busy (awaiting response) or UART is busy (sending/receiving data).
195  MB_EX_TIMEOUT = 0x81, //!< ModbusLib INTERNAL exception: timeout error occurred.
196  MB_EX_ILLEGAL_STATE = 0x83, //!< ModbusLib INTERNAL exception: protocol stack in illegal state.
197  MB_EX_PROTOCOL_ERROR = 0x84, //!< ModbusLib INTERNAL exception: Communication error (unexpected or invalid frame).
198  MB_EX_FT_DONE = 0x86, //!< ModbusLib INTERNAL exception: Transfer File function is done.
199 } MbException_t;
200 
201 /**********************************************************************/
202 /**
203  * @brief Modbus driver state.
204  *
205  ***********************************************************************/
206 typedef enum
207 {
208  STATE_NOT_INITIALIZED, //!< Modbus instance was not initialised. Use MbInit().
209  STATE_DISABLED, //!< Modbus instance was initialised but currently disabled. Use MbEnable().
210  STATE_ENABLED, //!< Modbus instance is listening remote part and ready for transmission
211  STATE_BUSY, //!< Modbus instance is busy with data transfer, or (for client) awaiting reply.
212 } MbState_t;
213 
214 /**********************************************************************/
215 /**
216  * @brief Structure for holding variables related to Transfer File function.
217  *
218  ***********************************************************************/
219 typedef struct
220 {
221  uint32_t PartNum; //!< Last file part transmitted (for client) or received (for server). It is 0 for file header. Highest bit is a flag of the last part, so 0x8000000A is the 10th and last part of the file.
222  uint8_t Targets[MB_TFILE_TARGET_SIZE]; //!< Bit vector of targets for file transfer. So f.ex. if bit #0 in byte #1 is 1 - it means file transfers (among others) to server with Id 8.
223  uint8_t TargetsTmp[MB_TFILE_TARGET_SIZE]; //!< Temporary copy of targets vector used by client to verify part completion for all targets.
224  uint32_t FileSize; //!< Total file size
225  uint32_t FilePtr; //!< Bytes already transmitted. Used by client to determine the size of the last part.
226  uint32_t FileCrc32; //!< CRC32 of file name (w/o trailing zeroes) + file length + file data. Computed by crc32_compute() function.
227  uint8_t FileName[MB_TFILE_FNAMELEN_MAX]; //!< File name is ASCII null-terminated string of 1-31 chars.
228  uint32_t CurSize; //!< Bytes already received. Used by server to discover possible file size error.
229  uint32_t CurCrc32; //!< CRC32 of file name + file length + part of data received so far. Used by server to discover possible file CRC error. Computed by crc32_compute() function.
230  uint8_t PartLen; //!< Current packet file part length.
231  uint8_t* PartData; //!< Pointer to current part data
232  uint8_t Active; //!< Transfer file operation is in progress (even if the actual function is read reg)
233  struct mwork_t Mwork; //!< Timer for timeouts and transfer abortion. For server: when the next part wasn't arrived. For client: when one of servers still doesn't confirmed part reception.
235 
236 /**********************************************************************/
237 /**
238  * @brief Callback specific to the protocol and called on the protocol start.
239  *
240  * This callback can be implemented in the application for transport layers
241  * other than UART if some special processing required and settled to the
242  * Virtualfunc member of the modbus_t structure.
243  *
244  * @param Mb Modbus driver instance that should be started
245  * @param Error Error code occured while command was processed
246  * @return MbException_t Error code of the operation (MB_EX_NONE on success)
247  *
248  ***********************************************************************/
249 typedef MbException_t (*MbVfuncStart_t)(const struct modbus_t* Mb, void* data);
250 
251 /**********************************************************************/
252 /**
253  * @brief Callback specific to the protocol and called on the protocol stop.
254  *
255  * This callback can be implemented in the application for transport layers
256  * other than UART if some special processing required and settled to the
257  * Virtualfunc member of the modbus_t structure.
258  *
259  * @param Mb Modbus driver instance that should be stopped.
260  * @return MbException_t Error code of the operation (MB_EX_NONE on success)
261  *
262  ***********************************************************************/
263 typedef MbException_t (*MbVfuncStop_t)(const struct modbus_t* Mb);
264 
265 /**********************************************************************/
266 /**
267  * @brief Callbacks specific to the protocol and called when the driver
268  * wants to send data.
269  *
270  * This callback must be implemented in the application for transport layers
271  * other than UART and settled to the Virtualfunc member of the modbus_t
272  * structure.
273  *
274  * Implementation must write Mb->State->MbFrameLen bytes from the
275  * Mb->State->MbFrame pointer to the callback specific interface.
276  *
277  * @param Mb Modbus driver instance which called the callback
278  * @return MbException_t MB_EX_NONE on success, MB_EX_PROTOCOL_ERROR on error
279  *
280  ***********************************************************************/
281 typedef MbException_t (*MbVfuncSend_t)(const struct modbus_t* Mb);
282 
283 /**********************************************************************/
284 /**
285  * @brief Callbacks specific to the protocol and called when the driver
286  * wants to receive data.
287  *
288  * This callback must be implemented in the application for transport layers
289  * other than UART and settled to the Virtualfunc member of the modbus_t
290  * structure.
291  *
292  * Implementation must read all available bytes from the callback specific
293  * interface to the Mb->State->MbFrame pointer.
294  * Mb->State->MbFrameLen must be settled to the received data length.
295  *
296  * @param Mb Modbus driver instance which called the callback
297  * @return MbException_t MB_EX_NONE on success (even if nothing to read,
298  * MB_EX_PROTOCOL_ERROR on error.
299  *
300  ***********************************************************************/
301 typedef MbException_t (*MbVfuncReceive_t)(const struct modbus_t* Mb);
302 
303 /**********************************************************************/
304 /**
305  * @brief Callbacks specific to the Read/Write Holding Register(s) command.
306  * They're called when Modbus command or response requires to read or
307  * write specific register. It could be both command request on the
308  * server side, or command response on the client side.
309  *
310  * These callbacks must be implemented in the application for Read Holding
311  * Register, Write Holding Register, Write Multiple Registers command support
312  * and settled via the FuncHandlers member of the modbus_t structure.
313  *
314  * Implementation must read or write one register.
315  *
316  * @param Mb Modbus driver instance which called the callback
317  * @param SlaveAddr Slave address from the Modbus request/response frame
318  * @param RegAddr Register address to read or write
319  * @param Value Pointer to the value to set / buffer for output value
320  * @return MbException_t MB_EX_NONE on success, MB_EX_PROTOCOL_ERROR on error.
321  *
322  ***********************************************************************/
323 typedef MbException_t (*MbHoldingHandler_t)(const struct modbus_t* Mb, uint16_t SlaveAddr, uint16_t RegAddr, uint16_t* Value);
324 
325 /**********************************************************************/
326 /**
327  * @brief Callback specific to the Transfer File command.
328  * It is called when Modbus command requests to write a file.
329  *
330  * This callback must be implemented in the application for Transfer File
331  * command support and settled via the FuncHandlers member of the modbus_t
332  * structure.
333  *
334  * @param Mb Modbus driver instance which called the callback
335  * @param SlaveAddr Slave address from the Modbus request/response frame
336  * @param TransferFile Structure with information about the file and current part
337  * @return MbException_t MB_EX_NONE on success, MB_EX_PROTOCOL_ERROR on error.
338  *
339  ***********************************************************************/
340 typedef MbException_t (*MbTransferFileHandler_t)(const struct modbus_t* Mb, uint16_t SlaveAddr, mb_transfer_file_t* TransferFile);
341 
342 /**********************************************************************/
343 /**
344  * @brief Callback specific to the Transfer File Completed command.
345 
346  * @param Mb Modbus driver instance which called the callback
347  * @param SlaveAddr Slave address from the Modbus request/response frame
348  * @param PartNumber Reported file part number completed
349  * @return MbException_t MB_EX_NONE on success, MB_EX_PROTOCOL_ERROR on error.
350  *
351  ***********************************************************************/
352 typedef MbException_t (*MbTransferFileCompletedHandler_t)(const struct modbus_t* Mb, uint16_t SlaveAddr, uint32_t PartNumber);
353 
354 /**********************************************************************/
355 /**
356  * @brief Callback specific to the Transfer File command. It is called after
357  * a new file arrives to server or sniffer.
358  *
359  * @param Mb Modbus driver instance which called the callback
360  * @param FileName Name of the new file in file system.
361  *
362  ***********************************************************************/
363 typedef void (*MbNewFileHandler_t)(const struct modbus_t* Mb, uint8_t* FileName);
364 
365 /**********************************************************************/
366 /**
367  * @brief Callback called on the command processing end (reporting
368  * overall success/error)
369  *
370  * This callback should be implemented in the application and settled to the
371  * MbSessionClosedCb member of the modbus_t structure.
372  *
373  * @param Mb Modbus driver instance which called the callback
374  * @param Error Error code occured while command was processed
375  * @return MbException_t Error code to return to the client in the Modbus reply
376  * frame (MB_EX_NONE on success)
377  *
378  ***********************************************************************/
379 typedef MbException_t (*MbSessionClosed_t)(const struct modbus_t* Mb, MbException_t Error);
380 
381 /**********************************************************************/
382 /**
383  * @brief Structure for holding a callback serving one of Modbus commands.
384  * A pointer of array of these structures must be settled as the
385  * FuncHandlers member of the modbus_t structure.
386  *
387  ***********************************************************************/
389 {
390  uint8_t FunctionCode; //!< Modbus command code as per Modbus spec
391  void* FunctionHandler; //!< Function to call. Function type must follow the driver plugin specification for the command. F.ex. MbHoldingHandler_t for Holding Register commands.
392 };
393 
394 /**********************************************************************/
395 /**
396  * @brief Structure for holding a number of protocol specific virtual functions.
397  * UART related functions are the part of Modbus driver. Other protocols
398  * must be implemented on the application level.
399  * It is not necessary to implement MbStart and/or MbStop functions,
400  * if there is nothing to do. Thus functions can be settlet to NULL in
401  * the structure.
402  * However MbSendData/MbReceiveData functions are mandatory.
403  * A pointer of array of these structures must be settled as the
404  * Virtualfunc member of the modbus_t structure.
405  *
406  ***********************************************************************/
408 {
409  MbVfuncStart_t MbStart; //!< Function to call on the protocol start
410  MbVfuncStop_t MbStop; //!< Function to call on the protocol stop
411  MbVfuncSend_t MbSendData; //!< Function to call in order to send data (see MbVfuncSend_t)
412  MbVfuncReceive_t MbReceiveData; //!< Function to call in order to send data (see MbVfuncReceive_t)
413 };
414 
415 /**********************************************************************/
416 /**
417  * @brief modbus_state_t structure holds internal state of the Modbus driver.
418  *
419  ***********************************************************************/
421  const struct modbus_t* Module; //!< Pointer to the Modbus driver instance structure
422  struct process Process; //!< Process running the instance (it starts during the MbInit() function call)
423  struct mwork_t RespTOwork; //!< Client' timeout counter
424  uint32_t RespTO; //!< Client' timeout value in ms
425  struct uwork_t T35work; //!< UART 3.5 chars timeout timer
426  uint32_t TimerT35; //!< UART 3.5 chars timeout value in us
427  MbException_t Exception; //!< Last communication status
428  MbState_t MbState; //!< State of the instance (disables/enabled/busy)
429  uint8_t MyAddress; //!< Slave address of the interface on the Modbus (semistatic, assigned in MbInit() function call)
430  uint8_t RcvAddress; //!< Slave address of the currently processing Modbus frame
431  uint8_t DestAddress; //!< Slave address of the last sent Modbus frame (client only)
432  uint16_t DestReg; //!< First destination register of the last sent Read command (client only)
433  uint8_t* MbFrame; //!< Current pointer to the processing/assembling Modbus frame
434  uint16_t MbFrameLen; //!< Current length of the processing/assembling Modbus frame
435  void* Transport; //!< Pointer to the structure holding transport instance (UART, TCP, TLS...)
436  uint8_t SlaveIdBuf[MB_SLAVEID_BUF_LEN]; //!< Buffer holding the Slave ID string
437  uint16_t SlaveIdLen; //!< Length of the Slave ID string
438  uint8_t SndState; //!< UART send state for RTU and ASCII
439  uint8_t RcvState; //!< UART receive state for RTU and ASCII
440  uint8_t UartBuf[MB_SER_PDU_SIZE_MAX]; //!< Main buffer for assembling the receiving/transmitting Modbus frame
441  uint8_t* UartSndBufCur; //!< Current sending pointer in the UartBuf
442  uint16_t UartSndBufCount; //!< Counter of bytes sent from the UartBuf
443  uint16_t UartRcvBufPos; //!< Counter of bytes received to the UartBuf
444 
445  uint8_t LastFunction; //!< For client only: function of last sent packet
446  mb_transfer_file_t TransferFile; //!< Variables related to Transfer File function
447 };
448 
449 /**********************************************************************/
450 /**
451  * @brief modbus_t structure is used for configuration of Modbus instance.
452  * The structure must be initialized before the Modbus driver may be used.
453  ***********************************************************************/
454 struct modbus_t {
455  struct modbus_state_t* State; //!< Pointer to the Modbus driver instance state structure
456  MbMode_t Protocol; //!< Protocol type for the instance: TCP, RTU or ASCII
457  MbRole_t Role; //!< Instance role on the Modbus: Client, Server or Sniffer
458  uint32_t RespTODefault; //!< Default client' timeout value in ms (can overrides in each command)
459  const struct MbVirtualfunc_t* Virtualfunc; //!< Callbacks specific to the protocol to start/stop the protocol, receive/send data. For UART these functions are embedded in the Modbus driver (const struct MbVirtualfunc_t MbVirtualFuncRtu). For other carriers such as TLS they must be implemented on the application level.
460  const struct MbFunctionDescriptor_t* FuncHandlers; //!< Callbacks specific to the command and being called during the command processing to perform command/unit specific task
461  MbSessionClosed_t MbSessionClosedCb; //!< Callback being called on the command processing end (reporting overall success/error)
462  const struct modbus_t* MbClient; //!< For sniffer only. Modbus client instance on the same device (for confirmations sending)
463 };
464 
465 /**********************************************************************/
466 /**
467  * @brief Virtual functions for the UART protocol. Included in the driver and
468  * ready to be included in modbus_t as an address of this structure.
469  *
470  ***********************************************************************/
471 extern const struct MbVirtualfunc_t MbVirtualFuncRtu;
472 
473 /**********************************************************************/
474 /**
475  * @brief Virtual functions for the standard unsecured TCP protocol (using
476  * socket API). Included in the driver and ready to be included in
477  * modbus_t as an address of this structure.
478  *
479  ***********************************************************************/
480 extern const struct MbVirtualfunc_t MbVirtualFuncTcp;
481 
482 /**********************************************************************/
483 /**
484  * @brief Initialise resources used by the protocol stack instance.
485  *
486  * This function initialises Modbus instance' state (modbus_state_t)
487  * and starts a new OS process for the instance. MbInit() does not allow to
488  * use the instance, MbEnable() call is required after initialisation in order
489  * to send/receive frames.
490  *
491  * @note NB: The function can be called only if the instance is not initialised
492  * (first time after reset, or after had been closed by MbClose()).
493  *
494  * @param Mb Modbus driver instance which called the callback
495  * @param MbAddress Slave address for the instance (ignored for Client role and for TCP protocol)
496  * @return MbException_t MB_EX_NONE on success, some other exception on error.
497  *
498  ***********************************************************************/
499 MbException_t MbInit(const struct modbus_t* Mb, uint8_t MbAddress);
500 
501 /**********************************************************************/
502 /**
503  * @brief Release resources used by the protocol stack instance.
504  *
505  * This function releases all the resources and stops the OS process for
506  * the instance.
507  *
508  * @note NB: The function can be called only if the instance is initialised by
509  * MbInit() and either not yet enabled by MbEnable(), or disabled by
510  * MbDisable().
511  *
512  * @param Mb Modbus driver instance which called the callback
513  * @return MbException_t MB_EX_NONE on success, some other exception on error.
514  *
515  ***********************************************************************/
516 MbException_t MbClose(const struct modbus_t* Mb);
517 
518 /**********************************************************************/
519 /**
520  * @brief Enable the Modbus protocol stack instance.
521  *
522  * This function enables processing of Modbus frames. Enabling the protocol
523  * stack is only possible if it is in the disabled state: after MbInit() or
524  * MbDisable().
525  *
526  * @note NB: Mb->Virtualfunc->MbStart callback is called from within this
527  * function if not NULL.
528  *
529  * @param Mb Modbus driver instance which called the callback
530  * @param Data Pointer to the transport level instance descriptor (uart_t for UART, tls_conn_t for TLS).
531  * @return MbException_t MB_EX_NONE on success, some other exception on error.
532  *
533  ***********************************************************************/
534 MbException_t MbEnable(const struct modbus_t* Mb, void* Data);
535 
536 /***********************************************************************/
537 /**
538  * @brief Disable the Modbus protocol stack instance.
539  *
540  * Enabling the protocol
541  * stack is only possible if it is in the enabled state: after MbEnable().
542  *
543  * @note NB: Mb->Virtualfunc->MbStop callback is called from within this
544  * function if not NULL.
545  *
546  * @param Mb Modbus driver instance which called the callback
547  * @return MbException_t MB_EX_NONE on success, some other exception on error.
548  *
549  ************************************************************************/
550 MbException_t MbDisable(const struct modbus_t* Mb);
551 
552 /**********************************************************************/
553 /**
554  * @brief Request to write holding register.
555  *
556  * Send Modbus command "write holding register" to the bus and set the response
557  * timer. It is impossible to send another request before the current one is
558  * finished (with success, error or timeout): in such case MB_EX_BUSY is
559  * returned.
560  * In the end of command execution the callback Mb->MbSessionClosedCb will be
561  * called with the result.
562  *
563  * @note NB: This function is valid for instances having Client role only.
564  *
565  * @param Mb Modbus driver instance which called the callback
566  * @param DestAddr Slave address to send to (can be MB_ADDRESS_BROADCAST)
567  * @param RegAddr Register to write to
568  * @param RegData Data to write
569  * @param TimeOut Command timeout in ms (if 0, the default for modbus_t is used).
570  * @return MbException_t MB_EX_NONE on success, some other exception on error.
571  *
572  ************************************************************************/
573 MbException_t MbReqWriteHolding(const struct modbus_t* Mb, uint8_t DestAddr,
574  uint16_t RegAddr, uint16_t RegData, int32_t TimeOut);
575 
576 /**********************************************************************/
577 /**
578  * @brief Request to write multiple holding registers.
579  *
580  * Send Modbus command "write multiple registers" to the bus and set the response
581  * timer. It is impossible to send another request before the current one is
582  * finished (with success, error or timeout): in such case MB_EX_BUSY is
583  * returned.
584  * In the end of command execution the callback Mb->MbSessionClosedCb will be
585  * called with the result.
586  *
587  * @note NB: This function is valid for instances having Client role only.
588  *
589  * @param Mb Modbus driver instance which called the callback
590  * @param DestAddr Slave address to send to (can be MB_ADDRESS_BROADCAST)
591  * @param RegAddr First register to write to
592  * @param NRegs Number of registers to write
593  * @param DataBuffer Pointer to the data to write (must be NRegs*2 bytes long).
594  * @param TimeOut Command timeout in ms (if 0, the default for modbus_t is used).
595  * @return MbException_t MB_EX_NONE on success, some other exception on error.
596  *
597  ************************************************************************/
598 MbException_t MbReqWriteMultiple(const struct modbus_t* Mb, uint8_t DestAddr,
599  uint16_t RegAddr, uint16_t NRegs,
600  uint16_t* DataBuffer, int32_t TimeOut);
601 
602 /**********************************************************************/
603 /**
604  * @brief Request to read holding registers.
605  *
606  * Send Modbus command "read holding registers" to the bus and set the response
607  * timer. It is impossible to send another request before the current one is
608  * finished (with success, error or timeout): in such case MB_EX_BUSY is
609  * returned.
610  * In the end of command execution the callback Mb->MbSessionClosedCb will be
611  * called with the result.
612  *
613  * @note NB: This function is valid for instances having Client role only.
614  *
615  * @param Mb Modbus driver instance which called the callback
616  * @param DestAddr Slave address to send to
617  * @param RegAddr First register to read from
618  * @param NRegs Number of registers to read
619  * @param TimeOut Command timeout in ms (if 0, the default for modbus_t is used).
620  * @return MbException_t MB_EX_NONE on success, some other exception on error.
621  *
622  ************************************************************************/
623 MbException_t MbReqReadHolding(const struct modbus_t* Mb, uint8_t DestAddr,
624  uint16_t RegAddr, uint16_t NRegs, int32_t TimeOut);
625 
626 /**********************************************************************/
627 /**
628  * @brief Request to write file.
629  *
630  * Send Modbus command "write file record" to the bus and set the response
631  * timer. It is impossible to send another request before the current one is
632  * finished (with success, error or timeout): in such case MB_EX_BUSY is
633  * returned.
634  * In the end of command execution the callback Mb->MbSessionClosedCb will be
635  * called with the result.
636  *
637  * @note NB: This function is valid for instances having Client role only.
638  *
639  * @param Mb Modbus driver instance which called the callback
640  * @param DestAddr Slave address to send to (can be MB_ADDRESS_BROADCAST)
641  * @param FileNum File number to write to
642  * @param RecNum Record number to write
643  * @param Data Pointer to the data to write.
644  * @param DataLen Data length in bytes.
645  * @param TimeOut Command timeout in ms (if 0, the default for modbus_t is used).
646  * @return MbException_t MB_EX_NONE on success, some other exception on error.
647  *
648  ************************************************************************/
649 MbException_t MbReqWriteFile(const struct modbus_t* Mb, uint8_t DestAddr,
650  uint16_t FileNum, uint16_t RecNum,
651  uint8_t* Data, uint16_t DataLen,
652  int32_t TimeOut);
653 
654 /**********************************************************************/
655 /**
656  * @brief Request to transfer file header.
657  *
658  * Send Jetro proprietary Modbus command "transfer file" with file header
659  * information (the first PDU in file transfer procedure) to the bus and set
660  * the response timer. It is impossible to send another request before the
661  * current one is finished (with success, error or timeout): in such case
662  * MB_EX_BUSY is returned.
663  * In the end of command execution the callback Mb->MbSessionClosedCb will be
664  * called with the result.
665  *
666  * @note NB: This function is valid for instances having Client role only.
667  *
668  * @param Mb Modbus driver instance which called the callback
669  * @param Targets uint8_t[31] is actually 248 bit array of Modbus device addresses the file transfers to.
670  * @param FileSize File size in bytes
671  * @param Crc32 File Crc calculated by crc32_compute() from nRF SDK from 1) file name, 2) file size (4 bytes), 3) file content.
672  * @param FileName Pointer to an ASCII null-terminated string containing file name.
673  * @param TimeOut Command timeout in ms (if 0, the default for modbus_t is used).
674  * @return MbException_t MB_EX_NONE on success, some other exception on error.
675  *
676  ************************************************************************/
677 MbException_t MbReqTransferFile(const struct modbus_t* Mb, uint8_t* Targets,
678  uint32_t FileSize, uint32_t Crc32,
679  uint8_t* FileName, int32_t TimeOut);
680 
681 /**********************************************************************/
682 /**
683  * @brief Request to transfer file data.
684  *
685  * Send Jetro proprietary Modbus command "transfer file" with file data
686  * (all but the first PDU in file transfer procedure) to the bus and set
687  * the response timer. It is impossible to send another request before the
688  * current one is finished (with success, error or timeout): in such case
689  * MB_EX_BUSY is returned.
690  * In the end of command execution the callback Mb->MbSessionClosedCb will be
691  * called with the result.
692  *
693  * @note NB: This function is valid for instances having Client role only.
694  *
695  * @param Mb Modbus driver instance which called the callback
696  * @param PartNumber File part number (1-0x7FFFFFFF). Can't be 0 as 0th part
697  * transfers with MbReqTransferFileHeader() function.\n
698  * Highest bit denotes last part.
699  * @param PartSize Part size in bytes (247 bytes max)
700  * @param Data Pointer to the data to transfer.
701  * @param TimeOut Command timeout in ms (if 0, the default for modbus_t is used).
702  * @return MbException_t MB_EX_NONE on success, some other exception on error.
703  *
704  ************************************************************************/
706  uint32_t PartNumber, uint8_t PartSize,
707  uint8_t* Data, int32_t TimeOut);
708 
709 /**********************************************************************/
710 /**
711  * @brief Request to send "transfer file complete" message.
712  *
713  * Send Jetro proprietary Modbus command "transfer file complete" to the bus
714  * and set the response timer. It is impossible to send another request before
715  * the current one is finished (with success, error or timeout): in such case
716  * MB_EX_BUSY is returned.
717  * In the end of command execution the callback Mb->MbSessionClosedCb will be
718  * called with the result.
719  *
720  * @note NB: This function is valid for instances having Client role only.
721  *
722  * @param Mb Modbus driver instance which called the callback
723  * @param MyAddress Modbus own sniffer address of the device
724  * @param PartNumber Part number received
725  * @param TimeOut Command timeout in ms (if 0, the default for modbus_t is used).
726  * @return MbException_t MB_EX_NONE on success, some other exception on error.
727  *
728  ************************************************************************/
729 MbException_t MbReqTransferFileCompleted(const struct modbus_t* Mb, uint8_t MyAddress,
730  uint32_t PartNumber, int32_t TimeOut);
731 
732 /** @} modbus */
733 
734 #endif // MODBUS_H_INCLUDED
uint32_t RespTODefault
Default client&#39; timeout value in ms (can overrides in each command)
Definition: modbus.h:458
modbus_state_t structure holds internal state of the Modbus driver.
Definition: modbus.h:420
uint8_t * MbFrame
Current pointer to the processing/assembling Modbus frame.
Definition: modbus.h:433
uint8_t Active
Transfer file operation is in progress (even if the actual function is read reg)
Definition: modbus.h:232
Header file for the EVE millisecond-scale work scheduling.
MbException_t(* MbVfuncStart_t)(const struct modbus_t *Mb, void *data)
Callback specific to the protocol and called on the protocol start.
Definition: modbus.h:249
Modbus instance was not initialised. Use MbInit().
Definition: modbus.h:208
ModbusLib INTERNAL exception: Master is busy (awaiting response) or UART is busy (sending/receiving d...
Definition: modbus.h:194
const struct modbus_t * Module
Pointer to the Modbus driver instance structure.
Definition: modbus.h:421
Modbus event: Frame received.
Definition: modbus.h:142
MbException_t MbReqTransferFileData(const struct modbus_t *Mb, uint32_t PartNumber, uint8_t PartSize, uint8_t *Data, int32_t TimeOut)
Request to transfer file data.
MbException_t MbReqWriteHolding(const struct modbus_t *Mb, uint8_t DestAddr, uint16_t RegAddr, uint16_t RegData, int32_t TimeOut)
Request to write holding register.
uint8_t RcvState
UART receive state for RTU and ASCII.
Definition: modbus.h:439
#define MB_SLAVEID_BUF_LEN
Number of bytes which should be allocated for the Report Slave ID command.
Definition: modbus.h:88
MbException_t MbInit(const struct modbus_t *Mb, uint8_t MbAddress)
Initialise resources used by the protocol stack instance.
uint8_t LastFunction
For client only: function of last sent packet.
Definition: modbus.h:445
MbRole_t Role
Instance role on the Modbus: Client, Server or Sniffer.
Definition: modbus.h:457
Modbus event: Frame sent.
Definition: modbus.h:143
Continue file transfer procedure.
Definition: modbus.h:147
illegal argument.
Definition: modbus.h:187
Modbus instance is busy with data transfer, or (for client) awaiting reply.
Definition: modbus.h:211
mb_transfer_file_t TransferFile
Variables related to Transfer File function.
Definition: modbus.h:446
MbState_t
Modbus driver state.
Definition: modbus.h:206
uint16_t UartSndBufCount
Counter of bytes sent from the UartBuf.
Definition: modbus.h:442
MbSessionClosed_t MbSessionClosedCb
Callback being called on the command processing end (reporting overall success/error) ...
Definition: modbus.h:461
MbVfuncStop_t MbStop
Function to call on the protocol stop.
Definition: modbus.h:410
Modbus event: Startup finished.
Definition: modbus.h:141
Structure for holding a number of protocol specific virtual functions. UART related functions are the...
Definition: modbus.h:407
MbException_t(* MbHoldingHandler_t)(const struct modbus_t *Mb, uint16_t SlaveAddr, uint16_t RegAddr, uint16_t *Value)
Callbacks specific to the Read/Write Holding Register(s) command. They&#39;re called when Modbus command ...
Definition: modbus.h:323
Definition: mwork.h:182
ModbusLib INTERNAL exception: Transfer File function is done.
Definition: modbus.h:198
An unrecoverable error occurred while the server was attempting to perform the requested action...
Definition: modbus.h:188
MbException_t MbReqWriteFile(const struct modbus_t *Mb, uint8_t DestAddr, uint16_t FileNum, uint16_t RecNum, uint8_t *Data, uint16_t DataLen, int32_t TimeOut)
Request to write file.
ModbusLib INTERNAL exception: protocol stack in illegal state.
Definition: modbus.h:196
#define MB_SER_PDU_SIZE_MAX
Maximum size of a Modbus RTU frame. 1 byte less than standard because of internal UART limitation...
Definition: modbus.h:90
uint8_t * UartSndBufCur
Current sending pointer in the UartBuf.
Definition: modbus.h:441
The client should retransmit the message later when the server is free.
Definition: modbus.h:190
uint8_t DestAddress
Slave address of the last sent Modbus frame (client only)
Definition: modbus.h:431
uint32_t FileSize
Total file size.
Definition: modbus.h:224
Modbus instance is listening remote part and ready for transmission.
Definition: modbus.h:210
MbException_t(* MbVfuncReceive_t)(const struct modbus_t *Mb)
Callbacks specific to the protocol and called when the driver wants to receive data.
Definition: modbus.h:301
TCP mode.
Definition: modbus.h:161
Client (master) role.
Definition: modbus.h:172
uint16_t SlaveIdLen
Length of the Slave ID string.
Definition: modbus.h:437
uint8_t RcvAddress
Slave address of the currently processing Modbus frame.
Definition: modbus.h:430
uint16_t UartRcvBufPos
Counter of bytes received to the UartBuf.
Definition: modbus.h:443
RTU transmission mode.
Definition: modbus.h:159
MbException_t Exception
Last communication status.
Definition: modbus.h:427
Sniffer role.
Definition: modbus.h:173
MbRole_t
Modbus device role (MASTER/SLAVE/SNIFFER).
Definition: modbus.h:169
The server has accepted the request and is processing it, but a long duration of time will be require...
Definition: modbus.h:189
MbException_t(* MbTransferFileHandler_t)(const struct modbus_t *Mb, uint16_t SlaveAddr, mb_transfer_file_t *TransferFile)
Callback specific to the Transfer File command. It is called when Modbus command requests to write a ...
Definition: modbus.h:340
void * Transport
Pointer to the structure holding transport instance (UART, TCP, TLS...)
Definition: modbus.h:435
MbException_t MbReqWriteMultiple(const struct modbus_t *Mb, uint8_t DestAddr, uint16_t RegAddr, uint16_t NRegs, uint16_t *DataBuffer, int32_t TimeOut)
Request to write multiple holding registers.
In conjunction with gateways: indicates that the gateway was unable to allocate an internal communica...
Definition: modbus.h:192
MbVfuncStart_t MbStart
Function to call on the protocol start.
Definition: modbus.h:409
uint8_t PartLen
Current packet file part length.
Definition: modbus.h:230
void * FunctionHandler
Function to call. Function type must follow the driver plugin specification for the command...
Definition: modbus.h:391
const struct MbVirtualfunc_t MbVirtualFuncRtu
Virtual functions for the UART protocol. Included in the driver and ready to be included in modbus_t ...
uint16_t DestReg
First destination register of the last sent Read command (client only)
Definition: modbus.h:432
uint32_t FilePtr
Bytes already transmitted. Used by client to determine the size of the last part. ...
Definition: modbus.h:225
no error.
Definition: modbus.h:184
const struct MbFunctionDescriptor_t * FuncHandlers
Callbacks specific to the command and being called during the command processing to perform command/u...
Definition: modbus.h:460
MbException_t
Modbus standard exception codes plus internal error codes used by all function in the protocol stack...
Definition: modbus.h:182
Modbus instance was initialised but currently disabled. Use MbEnable().
Definition: modbus.h:209
uint8_t MyAddress
Slave address of the interface on the Modbus (semistatic, assigned in MbInit() function call) ...
Definition: modbus.h:429
MbException_t MbClose(const struct modbus_t *Mb)
Release resources used by the protocol stack instance.
ASCII transmission mode.
Definition: modbus.h:160
#define MB_TFILE_FNAMELEN_MAX
Length of the buffer holding filename for Transfer File function. As file name is null-terminated...
Definition: modbus.h:93
MbException_t(* MbVfuncStop_t)(const struct modbus_t *Mb)
Callback specific to the protocol and called on the protocol stop.
Definition: modbus.h:263
uint32_t PartNum
Last file part transmitted (for client) or received (for server). It is 0 for file header...
Definition: modbus.h:221
void(* MbNewFileHandler_t)(const struct modbus_t *Mb, uint8_t *FileName)
Callback specific to the Transfer File command. It is called after a new file arrives to server or sn...
Definition: modbus.h:363
MbException_t(* MbTransferFileCompletedHandler_t)(const struct modbus_t *Mb, uint16_t SlaveAddr, uint32_t PartNumber)
Callback specific to the Transfer File Completed command.
Definition: modbus.h:352
uint8_t FunctionCode
Modbus command code as per Modbus spec.
Definition: modbus.h:390
The function code received in the query is not an allowable action for the server.
Definition: modbus.h:185
MbMode_t
Modbus serial transmission modes (RTU/ASCII/TCP).
Definition: modbus.h:157
Header file for the EVE microsecond-scale work scheduling.
In conjunction with gateways: Specialized use in conjunction with gateways, indicates that no respons...
Definition: modbus.h:193
struct modbus_state_t * State
Pointer to the Modbus driver instance state structure.
Definition: modbus.h:455
MbException_t(* MbSessionClosed_t)(const struct modbus_t *Mb, MbException_t Error)
Callback called on the command processing end (reporting overall success/error)
Definition: modbus.h:379
const struct modbus_t * MbClient
For sniffer only. Modbus client instance on the same device (for confirmations sending) ...
Definition: modbus.h:462
const struct MbVirtualfunc_t MbVirtualFuncTcp
Virtual functions for the standard unsecured TCP protocol (using socket API). Included in the driver ...
In conjunction with function codes 20 and 21: The server attempted to read record file...
Definition: modbus.h:191
const struct MbVirtualfunc_t * Virtualfunc
Callbacks specific to the protocol to start/stop the protocol, receive/send data. For UART these func...
Definition: modbus.h:459
#define MB_TFILE_TARGET_SIZE
Length of bit vector of targets for Transfer File function.
Definition: modbus.h:92
uint8_t data[USBNET_RX_BUF_SIZE]
Definition: usbnet.h:140
Modbus event: Request to send frame.
Definition: modbus.h:144
uint32_t TimerT35
UART 3.5 chars timeout value in us.
Definition: modbus.h:426
ModbusLib INTERNAL exception: Communication error (unexpected or invalid frame).
Definition: modbus.h:197
MbEvent_t
Modbus events used in ModbusServerProcess and ModbusClientProcess.
Definition: modbus.h:139
Modbus event: Data exchange ended.
Definition: modbus.h:145
uint32_t CurCrc32
CRC32 of file name + file length + part of data received so far. Used by server to discover possible ...
Definition: modbus.h:229
MbException_t MbReqTransferFileCompleted(const struct modbus_t *Mb, uint8_t MyAddress, uint32_t PartNumber, int32_t TimeOut)
Request to send "transfer file complete" message.
uint32_t CurSize
Bytes already received. Used by server to discover possible file size error.
Definition: modbus.h:228
MbException_t MbReqTransferFile(const struct modbus_t *Mb, uint8_t *Targets, uint32_t FileSize, uint32_t Crc32, uint8_t *FileName, int32_t TimeOut)
Request to transfer file header.
uint8_t SndState
UART send state for RTU and ASCII.
Definition: modbus.h:438
Structure for holding a callback serving one of Modbus commands. A pointer of array of these structur...
Definition: modbus.h:388
uint8_t * PartData
Pointer to current part data.
Definition: modbus.h:231
Definition: uwork.h:142
Server (slave) role.
Definition: modbus.h:171
illegal register address.
Definition: modbus.h:186
ModbusLib INTERNAL exception: timeout error occurred.
Definition: modbus.h:195
MbVfuncReceive_t MbReceiveData
Function to call in order to send data (see MbVfuncReceive_t)
Definition: modbus.h:412
uint32_t RespTO
Client&#39; timeout value in ms.
Definition: modbus.h:424
modbus_t structure is used for configuration of Modbus instance. The structure must be initialized be...
Definition: modbus.h:454
3.5 chars timeout expired
Definition: modbus.h:146
MbException_t(* MbVfuncSend_t)(const struct modbus_t *Mb)
Callbacks specific to the protocol and called when the driver wants to send data. ...
Definition: modbus.h:281
uint16_t MbFrameLen
Current length of the processing/assembling Modbus frame.
Definition: modbus.h:434
MbException_t MbReqReadHolding(const struct modbus_t *Mb, uint8_t DestAddr, uint16_t RegAddr, uint16_t NRegs, int32_t TimeOut)
Request to read holding registers.
MbException_t MbDisable(const struct modbus_t *Mb)
Disable the Modbus protocol stack instance.
MbMode_t Protocol
Protocol type for the instance: TCP, RTU or ASCII.
Definition: modbus.h:456
uint32_t FileCrc32
CRC32 of file name (w/o trailing zeroes) + file length + file data. Computed by crc32_compute() funct...
Definition: modbus.h:226
MbException_t MbEnable(const struct modbus_t *Mb, void *Data)
Enable the Modbus protocol stack instance.
MbVfuncSend_t MbSendData
Function to call in order to send data (see MbVfuncSend_t)
Definition: modbus.h:411
MbState_t MbState
State of the instance (disables/enabled/busy)
Definition: modbus.h:428
Structure for holding variables related to Transfer File function.
Definition: modbus.h:219