Răsfoiți Sursa

Отладку функции 0x14 с ВУ.

TelenkovDmitry 9 luni în urmă
părinte
comite
d7cd6d0e46

+ 8 - 0
fw/modules/log/log_api.c

@@ -49,3 +49,11 @@ int log_get_entry(uint32_t index, struct ringfs *fs)
     
     return 0;
 }
+
+//
+int mb_log_get_entry(uint8_t *buf, uint16_t entry_index)
+{
+    *buf = 77;
+    
+    return 0;
+}

+ 2 - 0
fw/modules/log/log_api.h

@@ -12,5 +12,7 @@ void log_get_entry_count(void);
 //
 int log_get_entry(uint32_t index, struct ringfs *fs);
 
+//
+int mb_log_get_entry(uint8_t *buf, uint16_t entry_index);
 
 #endif /* __LOG_API_H */

+ 45 - 0
fw/modules/modbus/modbus.c

@@ -11,6 +11,7 @@
 #include "modbus_params.h"
 #include "common_gpio.h"
 #include "io_utils.h"
+#include "log_api.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdbool.h>
@@ -19,6 +20,9 @@
 #define REG_HOLDING_NREGS		( 5 )
 
 
+#undef DBG
+#define DBG if(1)
+
 
 static USHORT	usRegHoldingStart = REG_HOLDING_START;
 extern UCHAR    rcvAddress;
@@ -426,3 +430,44 @@ eMBSetAddrSerialCB( UCHAR * pucFrame, USHORT * usLen )
     return MB_EX_NONE;
 }
 
+eMBException    
+eMBFuncReadFileRecordCB( UCHAR * pucFrame, USHORT * usLen )
+{
+    uint8_t byte_count;
+    uint8_t reference_type;
+    uint16_t file_number = 0;
+    uint16_t record_number = 0;
+    uint16_t record_length = 0;
+  
+    DBG printf("This is Read file record CB !!!!!!!\r\n");    
+    DBG printf("Recived: ");
+    
+    for (int i = 0; i < *usLen; i++)
+    {
+        DBG printf("%X ", pucFrame[i]);
+    }
+    DBG printf("\r\n");
+    
+    byte_count = pucFrame[1];
+    
+    reference_type = pucFrame[2];
+
+    file_number = pucFrame[3] << 8;
+    file_number |= pucFrame[4];
+
+    record_number = pucFrame[5] << 8;
+    record_number |= pucFrame[6];
+    
+    record_length = pucFrame[7] << 8;
+    record_length |= pucFrame[8];
+    
+    DBG printf("Byte count: %u, reference_type: %u, file_number: %u\r\n",
+                byte_count, reference_type, file_number);
+    
+    DBG printf("Record number: %u, record length: %u\r\n", 
+                record_number, record_length);
+    
+    mb_log_get_entry((uint8_t*)pucFrame, record_number);
+    
+    return MB_EX_NONE;
+}

BIN
output/fw.bin


Fișier diff suprimat deoarece este prea mare
+ 401 - 423
project/ewarm/iap/iap.dep


Fișier diff suprimat deoarece este prea mare
+ 524 - 664
project/ewarm/module_universal_io.dep


+ 3 - 0
project/ewarm/module_universal_io.ewp

@@ -2683,6 +2683,9 @@
                 <file>
                     <name>$PROJ_DIR$\..\..\shared\freemodbus\functions\mbfuncdisc.c</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\shared\freemodbus\functions\mbfuncfile.c</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\..\..\shared\freemodbus\functions\mbfuncholding.c</name>
                 </file>

+ 3 - 0
project/ewarm/module_universal_io.ewt

@@ -2894,6 +2894,9 @@
                 <file>
                     <name>$PROJ_DIR$\..\..\shared\freemodbus\functions\mbfuncdisc.c</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\..\..\shared\freemodbus\functions\mbfuncfile.c</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\..\..\shared\freemodbus\functions\mbfuncholding.c</name>
                 </file>

+ 146 - 0
shared/freemodbus/functions/mbfuncfile.c

@@ -0,0 +1,146 @@
+/* 
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* ----------------------- System includes ----------------------------------*/
+#include "stdlib.h"
+#include "string.h"
+
+/* ----------------------- Platform includes --------------------------------*/
+#include "port.h"
+
+/* ----------------------- Modbus includes ----------------------------------*/
+#include "mb.h"
+#include "mbframe.h"
+#include "mbproto.h"
+#include "mbconfig.h"
+
+#include <stdio.h>
+
+
+#undef DBG
+#define DBG if(1)
+
+
+#if  MB_FUNC_READ_FILE_RECORD_ENABLED > 0
+eMBException eMBFuncReadFileRecord( UCHAR * pucFrame, USHORT * usLen )
+{
+    //*usLen += 1;
+    
+    printf("usLen: %u\r\n", *usLen);
+  
+    return eMBFuncReadFileRecordCB(pucFrame, usLen);
+}
+#endif
+
+
+
+// -------------------------------------------------------------------------- //
+
+#if 0
+
+#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
+
+/* ----------------------- Static variables ---------------------------------*/
+static UCHAR    ucMBSlaveID[MB_FUNC_OTHER_REP_SLAVEID_BUF];
+static USHORT   usMBSlaveIDLen;
+
+/* ----------------------- Start implementation -----------------------------*/
+
+eMBErrorCode
+eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning,
+               UCHAR const *pucAdditional, USHORT usAdditionalLen )
+{
+    eMBErrorCode    eStatus = MB_ENOERR;
+
+    /* the first byte and second byte in the buffer is reserved for
+     * the parameter ucSlaveID and the running flag. The rest of
+     * the buffer is available for additional data. */
+    if( usAdditionalLen + 2 < MB_FUNC_OTHER_REP_SLAVEID_BUF )
+    {
+        usMBSlaveIDLen = 0;
+        ucMBSlaveID[usMBSlaveIDLen++] = ucSlaveID;
+        ucMBSlaveID[usMBSlaveIDLen++] = ( UCHAR )( xIsRunning ? 0xFF : 0x00 );
+        if( usAdditionalLen > 0 )
+        {
+            memcpy( &ucMBSlaveID[usMBSlaveIDLen], pucAdditional,
+                    ( size_t )usAdditionalLen );
+            usMBSlaveIDLen += usAdditionalLen;
+        }
+    }
+    else
+    {
+        eStatus = MB_ENORES;
+    }
+    return eStatus;
+}
+/*
+eMBException
+eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen )
+{
+    memcpy( &pucFrame[MB_PDU_DATA_OFF], &ucMBSlaveID[0], ( size_t )usMBSlaveIDLen );
+    *usLen = ( USHORT )( MB_PDU_DATA_OFF + usMBSlaveIDLen );
+    return MB_EX_NONE;
+}
+*/
+#endif
+
+#if MB_FUNC_UPDATE_ENABLED > 0
+
+eMBException
+eMBFuncUpdate( UCHAR * pucFrame, USHORT * usLen )
+{
+	return eMBUpdateCB(pucFrame, usLen);
+}
+
+#endif
+
+
+#if MB_FUNC_SET_ADDR_ID_ENABLED > 0
+
+eMBException
+eMBFuncSetAddrId( UCHAR * pucFrame, USHORT * usLen )
+{
+    return eMBSetAddrIdCB(pucFrame, usLen);
+}
+
+#endif
+
+
+#if MB_FUNC_SET_ADDR_SERIAL_ENABLED > 0
+
+eMBException
+eMBFuncSetAddrSerial( UCHAR * pucFrame, USHORT * usLen )
+{
+    return eMBSetAddrSerialCB(pucFrame, usLen);
+}
+
+#endif
+
+
+#endif

+ 435 - 431
shared/freemodbus/include/mb.h

@@ -1,431 +1,435 @@
-/* 
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef _MB_H
-#define _MB_H
-
-#include "port.h"
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-
-#include "mbport.h"
-#include "mbproto.h"
-
-/*! \defgroup modbus Modbus
- * \code #include "mb.h" \endcode
- *
- * This module defines the interface for the application. It contains
- * the basic functions and types required to use the Modbus protocol stack.
- * A typical application will want to call eMBInit() first. If the device
- * is ready to answer network requests it must then call eMBEnable() to activate
- * the protocol stack. In the main loop the function eMBPoll() must be called
- * periodically. The time interval between pooling depends on the configured
- * Modbus timeout. If an RTOS is available a separate task should be created
- * and the task should always call the function eMBPoll().
- *
- * \code
- * // Initialize protocol stack in RTU mode for a slave with address 10 = 0x0A
- * eMBInit( MB_RTU, 0x0A, 38400, MB_PAR_EVEN );
- * // Enable the Modbus Protocol Stack.
- * eMBEnable(  );
- * for( ;; )
- * {
- *     // Call the main polling loop of the Modbus protocol stack.
- *     eMBPoll(  );
- *     ...
- * }
- * \endcode
- */
-
-/* ----------------------- Defines ------------------------------------------*/
-
-/*! \ingroup modbus
- * \brief Use the default Modbus TCP port (502)
- */
-#define MB_TCP_PORT_USE_DEFAULT 0   
-
-/* ----------------------- Type definitions ---------------------------------*/
-
-/*! \ingroup modbus
- * \brief Modbus serial transmission modes (RTU/ASCII).
- *
- * Modbus serial supports two transmission modes. Either ASCII or RTU. RTU
- * is faster but has more hardware requirements and requires a network with
- * a low jitter. ASCII is slower and more reliable on slower links (E.g. modems)
- */
-    typedef enum
-{
-    MB_RTU,                     /*!< RTU transmission mode. */
-    MB_ASCII,                   /*!< ASCII transmission mode. */
-    MB_TCP                      /*!< TCP mode. */
-} eMBMode;
-
-/*! \ingroup modbus
- * \brief If register should be written or read.
- *
- * This value is passed to the callback functions which support either
- * reading or writing register values. Writing means that the application
- * registers should be updated and reading means that the modbus protocol
- * stack needs to know the current register values.
- *
- * \see eMBRegHoldingCB( ), eMBRegCoilsCB( ), eMBRegDiscreteCB( ) and 
- *   eMBRegInputCB( ).
- */
-typedef enum
-{
-    MB_REG_READ,                /*!< Read register values and pass to protocol stack. */
-    MB_REG_WRITE                /*!< Update register values. */
-} eMBRegisterMode;
-
-/*! \ingroup modbus
- * \brief Errorcodes used by all function in the protocol stack.
- */
-typedef enum
-{
-    MB_ENOERR,                  /*!< no error. */
-    MB_ENOREG,                  /*!< illegal register address. */
-    MB_EINVAL,                  /*!< illegal argument. */
-    MB_EPORTERR,                /*!< porting layer error. */
-    MB_ENORES,                  /*!< insufficient resources. */
-    MB_EIO,                     /*!< I/O error. */
-    MB_EILLSTATE,               /*!< protocol stack in illegal state. */
-    MB_ETIMEDOUT                /*!< timeout error occurred. */
-} eMBErrorCode;
-
-
-/* ----------------------- Function prototypes ------------------------------*/
-/*! \ingroup modbus
- * \brief Initialize the Modbus protocol stack.
- *
- * This functions initializes the ASCII or RTU module and calls the
- * init functions of the porting layer to prepare the hardware. Please
- * note that the receiver is still disabled and no Modbus frames are
- * processed until eMBEnable( ) has been called.
- *
- * \param eMode If ASCII or RTU mode should be used.
- * \param ucSlaveAddress The slave address. Only frames sent to this
- *   address or to the broadcast address are processed.
- * \param ucPort The port to use. E.g. 1 for COM1 on windows. This value
- *   is platform dependent and some ports simply choose to ignore it.
- * \param ulBaudRate The baudrate. E.g. 19200. Supported baudrates depend
- *   on the porting layer.
- * \param eParity Parity used for serial transmission.
- *
- * \return If no error occurs the function returns eMBErrorCode::MB_ENOERR.
- *   The protocol is then in the disabled state and ready for activation
- *   by calling eMBEnable( ). Otherwise one of the following error codes 
- *   is returned:
- *    - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
- *        slave addresses are in the range 1 - 247.
- *    - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
- */
-eMBErrorCode    eMBInit( eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, 
-                         ULONG ulBaudRate, eMBParity eParity, unsigned int stop_bit );
-
-/*! \ingroup modbus
- * \brief Initialize the Modbus protocol stack for Modbus TCP.
- *
- * This function initializes the Modbus TCP Module. Please note that
- * frame processing is still disabled until eMBEnable( ) is called.
- *
- * \param usTCPPort The TCP port to listen on.
- * \return If the protocol stack has been initialized correctly the function
- *   returns eMBErrorCode::MB_ENOERR. Otherwise one of the following error
- *   codes is returned:
- *    - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
- *        slave addresses are in the range 1 - 247.
- *    - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
- */
-eMBErrorCode    eMBTCPInit( USHORT usTCPPort );
-
-/*! \ingroup modbus
- * \brief Release resources used by the protocol stack.
- *
- * This function disables the Modbus protocol stack and release all
- * hardware resources. It must only be called when the protocol stack 
- * is disabled. 
- *
- * \note Note all ports implement this function. A port which wants to 
- *   get an callback must define the macro MB_PORT_HAS_CLOSE to 1.
- *
- * \return If the resources where released it return eMBErrorCode::MB_ENOERR.
- *   If the protocol stack is not in the disabled state it returns
- *   eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode    eMBClose( void );
-
-/*! \ingroup modbus
- * \brief Enable the Modbus protocol stack.
- *
- * This function enables processing of Modbus frames. Enabling the protocol
- * stack is only possible if it is in the disabled state.
- *
- * \return If the protocol stack is now in the state enabled it returns 
- *   eMBErrorCode::MB_ENOERR. If it was not in the disabled state it 
- *   return eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode    eMBEnable( void );
-
-/*! \ingroup modbus
- * \brief Disable the Modbus protocol stack.
- *
- * This function disables processing of Modbus frames.
- *
- * \return If the protocol stack has been disabled it returns 
- *  eMBErrorCode::MB_ENOERR. If it was not in the enabled state it returns
- *  eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode    eMBDisable( void );
-
-/*! \ingroup modbus
- * \brief The main pooling loop of the Modbus protocol stack.
- *
- * This function must be called periodically. The timer interval required
- * is given by the application dependent Modbus slave timeout. Internally the
- * function calls xMBPortEventGet() and waits for an event from the receiver or
- * transmitter state machines. 
- *
- * \return If the protocol stack is not in the enabled state the function
- *   returns eMBErrorCode::MB_EILLSTATE. Otherwise it returns 
- *   eMBErrorCode::MB_ENOERR.
- */
-eMBErrorCode    eMBPoll( void );
-
-/*! \ingroup modbus
- * \brief Configure the slave id of the device.
- *
- * This function should be called when the Modbus function <em>Report Slave ID</em>
- * is enabled ( By defining MB_FUNC_OTHER_REP_SLAVEID_ENABLED in mbconfig.h ).
- *
- * \param ucSlaveID Values is returned in the <em>Slave ID</em> byte of the
- *   <em>Report Slave ID</em> response.
- * \param xIsRunning If TRUE the <em>Run Indicator Status</em> byte is set to 0xFF.
- *   otherwise the <em>Run Indicator Status</em> is 0x00.
- * \param pucAdditional Values which should be returned in the <em>Additional</em>
- *   bytes of the <em> Report Slave ID</em> response.
- * \param usAdditionalLen Length of the buffer <code>pucAdditonal</code>.
- *
- * \return If the static buffer defined by MB_FUNC_OTHER_REP_SLAVEID_BUF in
- *   mbconfig.h is to small it returns eMBErrorCode::MB_ENORES. Otherwise
- *   it returns eMBErrorCode::MB_ENOERR.
- */
-eMBErrorCode    eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning,
-                               UCHAR const *pucAdditional,
-                               USHORT usAdditionalLen );
-
-/*! \ingroup modbus
- * \brief Registers a callback handler for a given function code.
- *
- * This function registers a new callback handler for a given function code.
- * The callback handler supplied is responsible for interpreting the Modbus PDU and
- * the creation of an appropriate response. In case of an error it should return
- * one of the possible Modbus exceptions which results in a Modbus exception frame
- * sent by the protocol stack. 
- *
- * \param ucFunctionCode The Modbus function code for which this handler should
- *   be registers. Valid function codes are in the range 1 to 127.
- * \param pxHandler The function handler which should be called in case
- *   such a frame is received. If \c NULL a previously registered function handler
- *   for this function code is removed.
- *
- * \return eMBErrorCode::MB_ENOERR if the handler has been installed. If no
- *   more resources are available it returns eMBErrorCode::MB_ENORES. In this
- *   case the values in mbconfig.h should be adjusted. If the argument was not
- *   valid it returns eMBErrorCode::MB_EINVAL.
- */
-eMBErrorCode    eMBRegisterCB( UCHAR ucFunctionCode, 
-                               pxMBFunctionHandler pxHandler );
-
-/* ----------------------- Callback -----------------------------------------*/
-
-/*! \defgroup modbus_registers Modbus Registers
- * \code #include "mb.h" \endcode
- * The protocol stack does not internally allocate any memory for the
- * registers. This makes the protocol stack very small and also usable on
- * low end targets. In addition the values don't have to be in the memory
- * and could for example be stored in a flash.<br>
- * Whenever the protocol stack requires a value it calls one of the callback
- * function with the register address and the number of registers to read
- * as an argument. The application should then read the actual register values
- * (for example the ADC voltage) and should store the result in the supplied
- * buffer.<br>
- * If the protocol stack wants to update a register value because a write
- * register function was received a buffer with the new register values is
- * passed to the callback function. The function should then use these values
- * to update the application register values.
- */
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if the value of a <em>Input Register</em>
- *   is required by the protocol stack. The starting register address is given
- *   by \c usAddress and the last register is given by <tt>usAddress +
- *   usNRegs - 1</tt>.
- *
- * \param pucRegBuffer A buffer where the callback function should write
- *   the current value of the modbus registers to.
- * \param usAddress The starting address of the register. Input registers
- *   are in the range 1 - 65535.
- * \param usNRegs Number of registers the callback function must supply.
- *
- * \return The function must return one of the following error codes:
- *   - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- *       Modbus response is sent.
- *   - eMBErrorCode::MB_ENOREG If the application can not supply values
- *       for registers within this range. In this case a 
- *       <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
- *   - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
- *       currently not available and the application dependent response
- *       timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
- *       exception is sent as a response.
- *   - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
- *       a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
- */
-eMBErrorCode    eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress,
-                               USHORT usNRegs );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Holding Register</em> value is
- *   read or written by the protocol stack. The starting register address
- *   is given by \c usAddress and the last register is given by
- *   <tt>usAddress + usNRegs - 1</tt>.
- *
- * \param pucRegBuffer If the application registers values should be updated the
- *   buffer points to the new registers values. If the protocol stack needs
- *   to now the current values the callback function should write them into
- *   this buffer.
- * \param usAddress The starting address of the register.
- * \param usNRegs Number of registers to read or write.
- * \param eMode If eMBRegisterMode::MB_REG_WRITE the application register 
- *   values should be updated from the values in the buffer. For example
- *   this would be the case when the Modbus master has issued an 
- *   <b>WRITE SINGLE REGISTER</b> command.
- *   If the value eMBRegisterMode::MB_REG_READ the application should copy 
- *   the current values into the buffer \c pucRegBuffer.
- *
- * \return The function must return one of the following error codes:
- *   - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- *       Modbus response is sent.
- *   - eMBErrorCode::MB_ENOREG If the application can not supply values
- *       for registers within this range. In this case a 
- *       <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
- *   - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
- *       currently not available and the application dependent response
- *       timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
- *       exception is sent as a response.
- *   - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
- *       a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
- */
-eMBErrorCode    eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress,
-                                 USHORT usNRegs, eMBRegisterMode eMode );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Coil Register</em> value is
- *   read or written by the protocol stack. If you are going to use
- *   this function you might use the functions xMBUtilSetBits(  ) and
- *   xMBUtilGetBits(  ) for working with bitfields.
- *
- * \param pucRegBuffer The bits are packed in bytes where the first coil
- *   starting at address \c usAddress is stored in the LSB of the
- *   first byte in the buffer <code>pucRegBuffer</code>.
- *   If the buffer should be written by the callback function unused
- *   coil values (I.e. if not a multiple of eight coils is used) should be set
- *   to zero.
- * \param usAddress The first coil number.
- * \param usNCoils Number of coil values requested.
- * \param eMode If eMBRegisterMode::MB_REG_WRITE the application values should
- *   be updated from the values supplied in the buffer \c pucRegBuffer.
- *   If eMBRegisterMode::MB_REG_READ the application should store the current
- *   values in the buffer \c pucRegBuffer.
- *
- * \return The function must return one of the following error codes:
- *   - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- *       Modbus response is sent.
- *   - eMBErrorCode::MB_ENOREG If the application does not map an coils
- *       within the requested address range. In this case a 
- *       <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
- *   - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
- *       currently not available and the application dependent response
- *       timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
- *       exception is sent as a response.
- *   - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
- *       a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
- */
-eMBErrorCode    eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress,
-                               USHORT usNCoils, eMBRegisterMode eMode );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Input Discrete Register</em> value is
- *   read by the protocol stack.
- *
- * If you are going to use his function you might use the functions
- * xMBUtilSetBits(  ) and xMBUtilGetBits(  ) for working with bitfields.
- *
- * \param pucRegBuffer The buffer should be updated with the current
- *   coil values. The first discrete input starting at \c usAddress must be
- *   stored at the LSB of the first byte in the buffer. If the requested number
- *   is not a multiple of eight the remaining bits should be set to zero.
- * \param usAddress The starting address of the first discrete input.
- * \param usNDiscrete Number of discrete input values.
- * \return The function must return one of the following error codes:
- *   - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- *       Modbus response is sent.
- *   - eMBErrorCode::MB_ENOREG If no such discrete inputs exists.
- *       In this case a <b>ILLEGAL DATA ADDRESS</b> exception frame is sent 
- *       as a response.
- *   - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
- *       currently not available and the application dependent response
- *       timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
- *       exception is sent as a response.
- *   - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
- *       a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
- */
-eMBErrorCode    eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress,
-                                  USHORT usNDiscrete );
-
-
-// 0x41
-eMBErrorCode    eMBUpdateCB( UCHAR * pucFrame, USHORT * usLen );
-
-// 0x42
-eMBException    eMBSetAddrIdCB( UCHAR * pucFrame, USHORT * usLen );
-
-// 0x43
-eMBException    eMBSetAddrSerialCB( UCHAR * pucFrame, USHORT * usLen );
-
-
-eMBErrorCode    eMBCheckSlaveAddr(UCHAR ucSlaveAddress);
-
-eMBErrorCode    eMBSetSlaveAddr(UCHAR ucSlaveAddress);
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
+/* 
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MB_H
+#define _MB_H
+
+#include "port.h"
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+
+#include "mbport.h"
+#include "mbproto.h"
+
+/*! \defgroup modbus Modbus
+ * \code #include "mb.h" \endcode
+ *
+ * This module defines the interface for the application. It contains
+ * the basic functions and types required to use the Modbus protocol stack.
+ * A typical application will want to call eMBInit() first. If the device
+ * is ready to answer network requests it must then call eMBEnable() to activate
+ * the protocol stack. In the main loop the function eMBPoll() must be called
+ * periodically. The time interval between pooling depends on the configured
+ * Modbus timeout. If an RTOS is available a separate task should be created
+ * and the task should always call the function eMBPoll().
+ *
+ * \code
+ * // Initialize protocol stack in RTU mode for a slave with address 10 = 0x0A
+ * eMBInit( MB_RTU, 0x0A, 38400, MB_PAR_EVEN );
+ * // Enable the Modbus Protocol Stack.
+ * eMBEnable(  );
+ * for( ;; )
+ * {
+ *     // Call the main polling loop of the Modbus protocol stack.
+ *     eMBPoll(  );
+ *     ...
+ * }
+ * \endcode
+ */
+
+/* ----------------------- Defines ------------------------------------------*/
+
+/*! \ingroup modbus
+ * \brief Use the default Modbus TCP port (502)
+ */
+#define MB_TCP_PORT_USE_DEFAULT 0   
+
+/* ----------------------- Type definitions ---------------------------------*/
+
+/*! \ingroup modbus
+ * \brief Modbus serial transmission modes (RTU/ASCII).
+ *
+ * Modbus serial supports two transmission modes. Either ASCII or RTU. RTU
+ * is faster but has more hardware requirements and requires a network with
+ * a low jitter. ASCII is slower and more reliable on slower links (E.g. modems)
+ */
+    typedef enum
+{
+    MB_RTU,                     /*!< RTU transmission mode. */
+    MB_ASCII,                   /*!< ASCII transmission mode. */
+    MB_TCP                      /*!< TCP mode. */
+} eMBMode;
+
+/*! \ingroup modbus
+ * \brief If register should be written or read.
+ *
+ * This value is passed to the callback functions which support either
+ * reading or writing register values. Writing means that the application
+ * registers should be updated and reading means that the modbus protocol
+ * stack needs to know the current register values.
+ *
+ * \see eMBRegHoldingCB( ), eMBRegCoilsCB( ), eMBRegDiscreteCB( ) and 
+ *   eMBRegInputCB( ).
+ */
+typedef enum
+{
+    MB_REG_READ,                /*!< Read register values and pass to protocol stack. */
+    MB_REG_WRITE                /*!< Update register values. */
+} eMBRegisterMode;
+
+/*! \ingroup modbus
+ * \brief Errorcodes used by all function in the protocol stack.
+ */
+typedef enum
+{
+    MB_ENOERR,                  /*!< no error. */
+    MB_ENOREG,                  /*!< illegal register address. */
+    MB_EINVAL,                  /*!< illegal argument. */
+    MB_EPORTERR,                /*!< porting layer error. */
+    MB_ENORES,                  /*!< insufficient resources. */
+    MB_EIO,                     /*!< I/O error. */
+    MB_EILLSTATE,               /*!< protocol stack in illegal state. */
+    MB_ETIMEDOUT                /*!< timeout error occurred. */
+} eMBErrorCode;
+
+
+/* ----------------------- Function prototypes ------------------------------*/
+/*! \ingroup modbus
+ * \brief Initialize the Modbus protocol stack.
+ *
+ * This functions initializes the ASCII or RTU module and calls the
+ * init functions of the porting layer to prepare the hardware. Please
+ * note that the receiver is still disabled and no Modbus frames are
+ * processed until eMBEnable( ) has been called.
+ *
+ * \param eMode If ASCII or RTU mode should be used.
+ * \param ucSlaveAddress The slave address. Only frames sent to this
+ *   address or to the broadcast address are processed.
+ * \param ucPort The port to use. E.g. 1 for COM1 on windows. This value
+ *   is platform dependent and some ports simply choose to ignore it.
+ * \param ulBaudRate The baudrate. E.g. 19200. Supported baudrates depend
+ *   on the porting layer.
+ * \param eParity Parity used for serial transmission.
+ *
+ * \return If no error occurs the function returns eMBErrorCode::MB_ENOERR.
+ *   The protocol is then in the disabled state and ready for activation
+ *   by calling eMBEnable( ). Otherwise one of the following error codes 
+ *   is returned:
+ *    - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
+ *        slave addresses are in the range 1 - 247.
+ *    - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
+ */
+eMBErrorCode    eMBInit( eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, 
+                         ULONG ulBaudRate, eMBParity eParity, unsigned int stop_bit );
+
+/*! \ingroup modbus
+ * \brief Initialize the Modbus protocol stack for Modbus TCP.
+ *
+ * This function initializes the Modbus TCP Module. Please note that
+ * frame processing is still disabled until eMBEnable( ) is called.
+ *
+ * \param usTCPPort The TCP port to listen on.
+ * \return If the protocol stack has been initialized correctly the function
+ *   returns eMBErrorCode::MB_ENOERR. Otherwise one of the following error
+ *   codes is returned:
+ *    - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
+ *        slave addresses are in the range 1 - 247.
+ *    - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
+ */
+eMBErrorCode    eMBTCPInit( USHORT usTCPPort );
+
+/*! \ingroup modbus
+ * \brief Release resources used by the protocol stack.
+ *
+ * This function disables the Modbus protocol stack and release all
+ * hardware resources. It must only be called when the protocol stack 
+ * is disabled. 
+ *
+ * \note Note all ports implement this function. A port which wants to 
+ *   get an callback must define the macro MB_PORT_HAS_CLOSE to 1.
+ *
+ * \return If the resources where released it return eMBErrorCode::MB_ENOERR.
+ *   If the protocol stack is not in the disabled state it returns
+ *   eMBErrorCode::MB_EILLSTATE.
+ */
+eMBErrorCode    eMBClose( void );
+
+/*! \ingroup modbus
+ * \brief Enable the Modbus protocol stack.
+ *
+ * This function enables processing of Modbus frames. Enabling the protocol
+ * stack is only possible if it is in the disabled state.
+ *
+ * \return If the protocol stack is now in the state enabled it returns 
+ *   eMBErrorCode::MB_ENOERR. If it was not in the disabled state it 
+ *   return eMBErrorCode::MB_EILLSTATE.
+ */
+eMBErrorCode    eMBEnable( void );
+
+/*! \ingroup modbus
+ * \brief Disable the Modbus protocol stack.
+ *
+ * This function disables processing of Modbus frames.
+ *
+ * \return If the protocol stack has been disabled it returns 
+ *  eMBErrorCode::MB_ENOERR. If it was not in the enabled state it returns
+ *  eMBErrorCode::MB_EILLSTATE.
+ */
+eMBErrorCode    eMBDisable( void );
+
+/*! \ingroup modbus
+ * \brief The main pooling loop of the Modbus protocol stack.
+ *
+ * This function must be called periodically. The timer interval required
+ * is given by the application dependent Modbus slave timeout. Internally the
+ * function calls xMBPortEventGet() and waits for an event from the receiver or
+ * transmitter state machines. 
+ *
+ * \return If the protocol stack is not in the enabled state the function
+ *   returns eMBErrorCode::MB_EILLSTATE. Otherwise it returns 
+ *   eMBErrorCode::MB_ENOERR.
+ */
+eMBErrorCode    eMBPoll( void );
+
+/*! \ingroup modbus
+ * \brief Configure the slave id of the device.
+ *
+ * This function should be called when the Modbus function <em>Report Slave ID</em>
+ * is enabled ( By defining MB_FUNC_OTHER_REP_SLAVEID_ENABLED in mbconfig.h ).
+ *
+ * \param ucSlaveID Values is returned in the <em>Slave ID</em> byte of the
+ *   <em>Report Slave ID</em> response.
+ * \param xIsRunning If TRUE the <em>Run Indicator Status</em> byte is set to 0xFF.
+ *   otherwise the <em>Run Indicator Status</em> is 0x00.
+ * \param pucAdditional Values which should be returned in the <em>Additional</em>
+ *   bytes of the <em> Report Slave ID</em> response.
+ * \param usAdditionalLen Length of the buffer <code>pucAdditonal</code>.
+ *
+ * \return If the static buffer defined by MB_FUNC_OTHER_REP_SLAVEID_BUF in
+ *   mbconfig.h is to small it returns eMBErrorCode::MB_ENORES. Otherwise
+ *   it returns eMBErrorCode::MB_ENOERR.
+ */
+eMBErrorCode    eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning,
+                               UCHAR const *pucAdditional,
+                               USHORT usAdditionalLen );
+
+/*! \ingroup modbus
+ * \brief Registers a callback handler for a given function code.
+ *
+ * This function registers a new callback handler for a given function code.
+ * The callback handler supplied is responsible for interpreting the Modbus PDU and
+ * the creation of an appropriate response. In case of an error it should return
+ * one of the possible Modbus exceptions which results in a Modbus exception frame
+ * sent by the protocol stack. 
+ *
+ * \param ucFunctionCode The Modbus function code for which this handler should
+ *   be registers. Valid function codes are in the range 1 to 127.
+ * \param pxHandler The function handler which should be called in case
+ *   such a frame is received. If \c NULL a previously registered function handler
+ *   for this function code is removed.
+ *
+ * \return eMBErrorCode::MB_ENOERR if the handler has been installed. If no
+ *   more resources are available it returns eMBErrorCode::MB_ENORES. In this
+ *   case the values in mbconfig.h should be adjusted. If the argument was not
+ *   valid it returns eMBErrorCode::MB_EINVAL.
+ */
+eMBErrorCode    eMBRegisterCB( UCHAR ucFunctionCode, 
+                               pxMBFunctionHandler pxHandler );
+
+/* ----------------------- Callback -----------------------------------------*/
+
+/*! \defgroup modbus_registers Modbus Registers
+ * \code #include "mb.h" \endcode
+ * The protocol stack does not internally allocate any memory for the
+ * registers. This makes the protocol stack very small and also usable on
+ * low end targets. In addition the values don't have to be in the memory
+ * and could for example be stored in a flash.<br>
+ * Whenever the protocol stack requires a value it calls one of the callback
+ * function with the register address and the number of registers to read
+ * as an argument. The application should then read the actual register values
+ * (for example the ADC voltage) and should store the result in the supplied
+ * buffer.<br>
+ * If the protocol stack wants to update a register value because a write
+ * register function was received a buffer with the new register values is
+ * passed to the callback function. The function should then use these values
+ * to update the application register values.
+ */
+
+/*! \ingroup modbus_registers
+ * \brief Callback function used if the value of a <em>Input Register</em>
+ *   is required by the protocol stack. The starting register address is given
+ *   by \c usAddress and the last register is given by <tt>usAddress +
+ *   usNRegs - 1</tt>.
+ *
+ * \param pucRegBuffer A buffer where the callback function should write
+ *   the current value of the modbus registers to.
+ * \param usAddress The starting address of the register. Input registers
+ *   are in the range 1 - 65535.
+ * \param usNRegs Number of registers the callback function must supply.
+ *
+ * \return The function must return one of the following error codes:
+ *   - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
+ *       Modbus response is sent.
+ *   - eMBErrorCode::MB_ENOREG If the application can not supply values
+ *       for registers within this range. In this case a 
+ *       <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
+ *   - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
+ *       currently not available and the application dependent response
+ *       timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
+ *       exception is sent as a response.
+ *   - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
+ *       a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
+ */
+eMBErrorCode    eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress,
+                               USHORT usNRegs );
+
+/*! \ingroup modbus_registers
+ * \brief Callback function used if a <em>Holding Register</em> value is
+ *   read or written by the protocol stack. The starting register address
+ *   is given by \c usAddress and the last register is given by
+ *   <tt>usAddress + usNRegs - 1</tt>.
+ *
+ * \param pucRegBuffer If the application registers values should be updated the
+ *   buffer points to the new registers values. If the protocol stack needs
+ *   to now the current values the callback function should write them into
+ *   this buffer.
+ * \param usAddress The starting address of the register.
+ * \param usNRegs Number of registers to read or write.
+ * \param eMode If eMBRegisterMode::MB_REG_WRITE the application register 
+ *   values should be updated from the values in the buffer. For example
+ *   this would be the case when the Modbus master has issued an 
+ *   <b>WRITE SINGLE REGISTER</b> command.
+ *   If the value eMBRegisterMode::MB_REG_READ the application should copy 
+ *   the current values into the buffer \c pucRegBuffer.
+ *
+ * \return The function must return one of the following error codes:
+ *   - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
+ *       Modbus response is sent.
+ *   - eMBErrorCode::MB_ENOREG If the application can not supply values
+ *       for registers within this range. In this case a 
+ *       <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
+ *   - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
+ *       currently not available and the application dependent response
+ *       timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
+ *       exception is sent as a response.
+ *   - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
+ *       a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
+ */
+eMBErrorCode    eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress,
+                                 USHORT usNRegs, eMBRegisterMode eMode );
+
+/*! \ingroup modbus_registers
+ * \brief Callback function used if a <em>Coil Register</em> value is
+ *   read or written by the protocol stack. If you are going to use
+ *   this function you might use the functions xMBUtilSetBits(  ) and
+ *   xMBUtilGetBits(  ) for working with bitfields.
+ *
+ * \param pucRegBuffer The bits are packed in bytes where the first coil
+ *   starting at address \c usAddress is stored in the LSB of the
+ *   first byte in the buffer <code>pucRegBuffer</code>.
+ *   If the buffer should be written by the callback function unused
+ *   coil values (I.e. if not a multiple of eight coils is used) should be set
+ *   to zero.
+ * \param usAddress The first coil number.
+ * \param usNCoils Number of coil values requested.
+ * \param eMode If eMBRegisterMode::MB_REG_WRITE the application values should
+ *   be updated from the values supplied in the buffer \c pucRegBuffer.
+ *   If eMBRegisterMode::MB_REG_READ the application should store the current
+ *   values in the buffer \c pucRegBuffer.
+ *
+ * \return The function must return one of the following error codes:
+ *   - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
+ *       Modbus response is sent.
+ *   - eMBErrorCode::MB_ENOREG If the application does not map an coils
+ *       within the requested address range. In this case a 
+ *       <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
+ *   - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
+ *       currently not available and the application dependent response
+ *       timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
+ *       exception is sent as a response.
+ *   - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
+ *       a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
+ */
+eMBErrorCode    eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress,
+                               USHORT usNCoils, eMBRegisterMode eMode );
+
+/*! \ingroup modbus_registers
+ * \brief Callback function used if a <em>Input Discrete Register</em> value is
+ *   read by the protocol stack.
+ *
+ * If you are going to use his function you might use the functions
+ * xMBUtilSetBits(  ) and xMBUtilGetBits(  ) for working with bitfields.
+ *
+ * \param pucRegBuffer The buffer should be updated with the current
+ *   coil values. The first discrete input starting at \c usAddress must be
+ *   stored at the LSB of the first byte in the buffer. If the requested number
+ *   is not a multiple of eight the remaining bits should be set to zero.
+ * \param usAddress The starting address of the first discrete input.
+ * \param usNDiscrete Number of discrete input values.
+ * \return The function must return one of the following error codes:
+ *   - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
+ *       Modbus response is sent.
+ *   - eMBErrorCode::MB_ENOREG If no such discrete inputs exists.
+ *       In this case a <b>ILLEGAL DATA ADDRESS</b> exception frame is sent 
+ *       as a response.
+ *   - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
+ *       currently not available and the application dependent response
+ *       timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
+ *       exception is sent as a response.
+ *   - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
+ *       a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
+ */
+eMBErrorCode    eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress,
+                                  USHORT usNDiscrete );
+
+
+// 0x41
+eMBErrorCode    eMBUpdateCB( UCHAR * pucFrame, USHORT * usLen );
+
+// 0x42
+eMBException    eMBSetAddrIdCB( UCHAR * pucFrame, USHORT * usLen );
+
+// 0x43
+eMBException    eMBSetAddrSerialCB( UCHAR * pucFrame, USHORT * usLen );
+
+//
+eMBErrorCode    eMBCheckSlaveAddr(UCHAR ucSlaveAddress);
+
+eMBErrorCode    eMBSetSlaveAddr(UCHAR ucSlaveAddress);
+
+// 0x14
+eMBException    eMBFuncReadFileRecordCB( UCHAR * pucFrame, USHORT * usLen );
+
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif

+ 144 - 142
shared/freemodbus/include/mbconfig.h

@@ -1,142 +1,144 @@
-/* 
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef _MB_CONFIG_H
-#define _MB_CONFIG_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-/* ----------------------- Defines ------------------------------------------*/
-/*! \defgroup modbus_cfg Modbus Configuration
- *
- * Most modules in the protocol stack are completly optional and can be
- * excluded. This is specially important if target resources are very small
- * and program memory space should be saved.<br>
- *
- * All of these settings are available in the file <code>mbconfig.h</code>
- */
-/*! \addtogroup modbus_cfg
- *  @{
- */
-/*! \brief If Modbus ASCII support is enabled. */
-#define MB_ASCII_ENABLED                        (  0 )
-
-/*! \brief If Modbus RTU support is enabled. */
-#define MB_RTU_ENABLED                          (  1 )
-
-/*! \brief If Modbus TCP support is enabled. */
-#define MB_TCP_ENABLED                          (  0 )
-
-/*! \brief The character timeout value for Modbus ASCII.
- *
- * The character timeout value is not fixed for Modbus ASCII and is therefore
- * a configuration option. It should be set to the maximum expected delay
- * time of the network.
- */
-#define MB_ASCII_TIMEOUT_SEC                    (  1 )
-
-/*! \brief Timeout to wait in ASCII prior to enabling transmitter.
- *
- * If defined the function calls vMBPortSerialDelay with the argument
- * MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS to allow for a delay before
- * the serial transmitter is enabled. This is required because some
- * targets are so fast that there is no time between receiving and
- * transmitting the frame. If the master is to slow with enabling its 
- * receiver then he will not receive the response correctly.
- */
-#ifndef MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS
-#define MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS    ( 0 )
-#endif
-
-/*! \brief Maximum number of Modbus functions codes the protocol stack
- *    should support.
- *
- * The maximum number of supported Modbus functions must be greater than
- * the sum of all enabled functions in this file and custom function
- * handlers. If set to small adding more functions will fail.
- */
-#define MB_FUNC_HANDLERS_MAX                    ( 13 )//( 16 )
-
-/*! \brief Number of bytes which should be allocated for the <em>Report Slave ID
- *    </em>command.
- *
- * This number limits the maximum size of the additional segment in the
- * report slave id function. See eMBSetSlaveID(  ) for more information on
- * how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
- * is set to <code>1</code>.
- */
-#define MB_FUNC_OTHER_REP_SLAVEID_BUF           ( 32 )
-
-/*! \brief If the <em>Report Slave ID</em> function should be enabled. */
-#define MB_FUNC_OTHER_REP_SLAVEID_ENABLED       (  1 )
-
-/*! \brief If the <em>Read Input Registers</em> function should be enabled. */
-#define MB_FUNC_READ_INPUT_ENABLED              (  1 )
-
-/*! \brief If the <em>Read Holding Registers</em> function should be enabled. */
-#define MB_FUNC_READ_HOLDING_ENABLED            (  1 )
-
-/*! \brief If the <em>Write Single Register</em> function should be enabled. */
-#define MB_FUNC_WRITE_HOLDING_ENABLED           (  1 )
-
-/*! \brief If the <em>Write Multiple registers</em> function should be enabled. */
-#define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED  (  1 )
-
-/*! \brief If the <em>Read Coils</em> function should be enabled. */
-#define MB_FUNC_READ_COILS_ENABLED              (  1 )
-
-/*! \brief If the <em>Write Coils</em> function should be enabled. */
-#define MB_FUNC_WRITE_COIL_ENABLED              (  1 )
-
-/*! \brief If the <em>Write Multiple Coils</em> function should be enabled. */
-#define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED    (  1 )
-
-/*! \brief If the <em>Read Discrete Inputs</em> function should be enabled. */
-#define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED    (  1 )
-
-/*! \brief If the <em>Read/Write Multiple Registers</em> function should be enabled. */
-#define MB_FUNC_READWRITE_HOLDING_ENABLED       (  1 )
-
-/*! \brief If the <em>Update</em> function should be enabled. */
-#define MB_FUNC_UPDATE_ENABLED                  (  1 )
-
-/*! \brief If the <em>Set modbus address by STM ID</em> function should be enabled. */   
-#define MB_FUNC_SET_ADDR_ID_ENABLED             (  1 )
-
-/*! \brief If the <em>Set modbus address by serial number</em> function should be enabled. */   
-#define MB_FUNC_SET_ADDR_SERIAL_ENABLED         (  1 )
-
-
-   
-/*! @} */
-#ifdef __cplusplus
-    PR_END_EXTERN_C
-#endif
-#endif
+/* 
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MB_CONFIG_H
+#define _MB_CONFIG_H
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+/* ----------------------- Defines ------------------------------------------*/
+/*! \defgroup modbus_cfg Modbus Configuration
+ *
+ * Most modules in the protocol stack are completly optional and can be
+ * excluded. This is specially important if target resources are very small
+ * and program memory space should be saved.<br>
+ *
+ * All of these settings are available in the file <code>mbconfig.h</code>
+ */
+/*! \addtogroup modbus_cfg
+ *  @{
+ */
+/*! \brief If Modbus ASCII support is enabled. */
+#define MB_ASCII_ENABLED                        (  0 )
+
+/*! \brief If Modbus RTU support is enabled. */
+#define MB_RTU_ENABLED                          (  1 )
+
+/*! \brief If Modbus TCP support is enabled. */
+#define MB_TCP_ENABLED                          (  0 )
+
+/*! \brief The character timeout value for Modbus ASCII.
+ *
+ * The character timeout value is not fixed for Modbus ASCII and is therefore
+ * a configuration option. It should be set to the maximum expected delay
+ * time of the network.
+ */
+#define MB_ASCII_TIMEOUT_SEC                    (  1 )
+
+/*! \brief Timeout to wait in ASCII prior to enabling transmitter.
+ *
+ * If defined the function calls vMBPortSerialDelay with the argument
+ * MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS to allow for a delay before
+ * the serial transmitter is enabled. This is required because some
+ * targets are so fast that there is no time between receiving and
+ * transmitting the frame. If the master is to slow with enabling its 
+ * receiver then he will not receive the response correctly.
+ */
+#ifndef MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS
+#define MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS    ( 0 )
+#endif
+
+/*! \brief Maximum number of Modbus functions codes the protocol stack
+ *    should support.
+ *
+ * The maximum number of supported Modbus functions must be greater than
+ * the sum of all enabled functions in this file and custom function
+ * handlers. If set to small adding more functions will fail.
+ */
+#define MB_FUNC_HANDLERS_MAX                    ( 14 )//( 16 )
+
+/*! \brief Number of bytes which should be allocated for the <em>Report Slave ID
+ *    </em>command.
+ *
+ * This number limits the maximum size of the additional segment in the
+ * report slave id function. See eMBSetSlaveID(  ) for more information on
+ * how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
+ * is set to <code>1</code>.
+ */
+#define MB_FUNC_OTHER_REP_SLAVEID_BUF           ( 32 )
+
+/*! \brief If the <em>Report Slave ID</em> function should be enabled. */
+#define MB_FUNC_OTHER_REP_SLAVEID_ENABLED       (  1 )
+
+/*! \brief If the <em>Read Input Registers</em> function should be enabled. */
+#define MB_FUNC_READ_INPUT_ENABLED              (  1 )
+
+/*! \brief If the <em>Read Holding Registers</em> function should be enabled. */
+#define MB_FUNC_READ_HOLDING_ENABLED            (  1 )
+
+/*! \brief If the <em>Write Single Register</em> function should be enabled. */
+#define MB_FUNC_WRITE_HOLDING_ENABLED           (  1 )
+
+/*! \brief If the <em>Write Multiple registers</em> function should be enabled. */
+#define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED  (  1 )
+
+/*! \brief If the <em>Read Coils</em> function should be enabled. */
+#define MB_FUNC_READ_COILS_ENABLED              (  1 )
+
+/*! \brief If the <em>Write Coils</em> function should be enabled. */
+#define MB_FUNC_WRITE_COIL_ENABLED              (  1 )
+
+/*! \brief If the <em>Write Multiple Coils</em> function should be enabled. */
+#define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED    (  1 )
+
+/*! \brief If the <em>Read Discrete Inputs</em> function should be enabled. */
+#define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED    (  1 )
+
+/*! \brief If the <em>Read/Write Multiple Registers</em> function should be enabled. */
+#define MB_FUNC_READWRITE_HOLDING_ENABLED       (  1 )
+
+/*! \brief If the <em>Update</em> function should be enabled. */
+#define MB_FUNC_UPDATE_ENABLED                  (  1 )
+
+/*! \brief If the <em>Set modbus address by STM ID</em> function should be enabled. */   
+#define MB_FUNC_SET_ADDR_ID_ENABLED             (  1 )
+
+/*! \brief If the <em>Set modbus address by serial number</em> function should be enabled. */   
+#define MB_FUNC_SET_ADDR_SERIAL_ENABLED         (  1 )
+   
+#define MB_FUNC_READ_FILE_RECORD_ENABLED        (  1 )
+   
+/*! @} */
+#ifdef __cplusplus
+    PR_END_EXTERN_C
+#endif
+#endif
+
+      

+ 95 - 91
shared/freemodbus/include/mbfunc.h

@@ -1,91 +1,95 @@
-/* 
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- 
-#ifndef _MB_FUNC_H
-#define _MB_FUNC_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-#if MB_FUNC_OTHER_REP_SLAVEID_BUF > 0
-    eMBException eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READ_INPUT_ENABLED > 0
-eMBException    eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READ_HOLDING_ENABLED > 0
-eMBException    eMBFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
-eMBException    eMBFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
-eMBException    eMBFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READ_COILS_ENABLED > 0
-eMBException    eMBFuncReadCoils( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_WRITE_COIL_ENABLED > 0
-eMBException    eMBFuncWriteCoil( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
-eMBException    eMBFuncWriteMultipleCoils( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
-eMBException    eMBFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
-eMBException    eMBFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_UPDATE_ENABLED > 0
-eMBException    eMBFuncUpdate( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_SET_ADDR_ID_ENABLED > 0
-eMBException    eMBFuncSetAddrId( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_SET_ADDR_SERIAL_ENABLED > 0
-eMBException    eMBFuncSetAddrSerial( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
+/* 
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+ 
+#ifndef _MB_FUNC_H
+#define _MB_FUNC_H
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+#if MB_FUNC_OTHER_REP_SLAVEID_BUF > 0
+    eMBException eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_READ_INPUT_ENABLED > 0
+eMBException    eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_READ_HOLDING_ENABLED > 0
+eMBException    eMBFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
+eMBException    eMBFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
+eMBException    eMBFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_READ_COILS_ENABLED > 0
+eMBException    eMBFuncReadCoils( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_WRITE_COIL_ENABLED > 0
+eMBException    eMBFuncWriteCoil( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
+eMBException    eMBFuncWriteMultipleCoils( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
+eMBException    eMBFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
+eMBException    eMBFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_UPDATE_ENABLED > 0
+eMBException    eMBFuncUpdate( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_SET_ADDR_ID_ENABLED > 0
+eMBException    eMBFuncSetAddrId( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_SET_ADDR_SERIAL_ENABLED > 0
+eMBException    eMBFuncSetAddrSerial( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#if MB_FUNC_READ_FILE_RECORD_ENABLED > 0
+eMBException    eMBFuncReadFileRecord( UCHAR * pucFrame, USHORT * usLen );
+#endif
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif

+ 87 - 86
shared/freemodbus/include/mbproto.h

@@ -1,86 +1,87 @@
-/* 
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef _MB_PROTO_H
-#define _MB_PROTO_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_ADDRESS_BROADCAST    ( 0 )   /*! Modbus broadcast address. */
-#define MB_ADDRESS_MIN          ( 1 )   /*! Smallest possible slave address. */
-#define MB_ADDRESS_MAX          ( 247 ) /*! Biggest possible slave address. */
-#define MB_FUNC_NONE                          (  0 )
-#define MB_FUNC_READ_COILS                    (  1 )
-#define MB_FUNC_READ_DISCRETE_INPUTS          (  2 )
-#define MB_FUNC_WRITE_SINGLE_COIL             (  5 )
-#define MB_FUNC_WRITE_MULTIPLE_COILS          ( 15 )
-#define MB_FUNC_READ_HOLDING_REGISTER         (  3 )
-#define MB_FUNC_READ_INPUT_REGISTER           (  4 )
-#define MB_FUNC_WRITE_REGISTER                (  6 )
-#define MB_FUNC_WRITE_MULTIPLE_REGISTERS      ( 16 )
-#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS  ( 23 )
-#define MB_FUNC_DIAG_READ_EXCEPTION           (  7 )
-#define MB_FUNC_DIAG_DIAGNOSTIC               (  8 )
-#define MB_FUNC_DIAG_GET_COM_EVENT_CNT        ( 11 )
-#define MB_FUNC_DIAG_GET_COM_EVENT_LOG        ( 12 )
-#define MB_FUNC_OTHER_REPORT_SLAVEID          ( 17 )
-#define MB_FUNC_UPDATE                        ( 65 )
-#define MB_FUNC_SET_ADDR_ID                   ( 66 )
-#define MB_FUNC_SET_ADDR_SERIAL               ( 67 )
-#define MB_FUNC_ERROR                         ( 128 )
-
-/* ----------------------- Type definitions ---------------------------------*/
-    typedef enum
-{
-    MB_EX_NONE = 0x00,
-    MB_EX_ILLEGAL_FUNCTION = 0x01,
-    MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
-    MB_EX_ILLEGAL_DATA_VALUE = 0x03,
-    MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
-    MB_EX_ACKNOWLEDGE = 0x05,
-    MB_EX_SLAVE_BUSY = 0x06,
-    MB_EX_MEMORY_PARITY_ERROR = 0x08,
-    MB_EX_GATEWAY_PATH_FAILED = 0x0A,
-    MB_EX_GATEWAY_TGT_FAILED = 0x0B
-} eMBException;
-
-typedef         eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );
-
-typedef struct
-{
-    UCHAR           ucFunctionCode;
-    pxMBFunctionHandler pxHandler;
-} xMBFunctionHandler;
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
+/* 
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _MB_PROTO_H
+#define _MB_PROTO_H
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+/* ----------------------- Defines ------------------------------------------*/
+#define MB_ADDRESS_BROADCAST    ( 0 )   /*! Modbus broadcast address. */
+#define MB_ADDRESS_MIN          ( 1 )   /*! Smallest possible slave address. */
+#define MB_ADDRESS_MAX          ( 247 ) /*! Biggest possible slave address. */
+#define MB_FUNC_NONE                          (  0 )
+#define MB_FUNC_READ_COILS                    (  1 )
+#define MB_FUNC_READ_DISCRETE_INPUTS          (  2 )
+#define MB_FUNC_WRITE_SINGLE_COIL             (  5 )
+#define MB_FUNC_READ_FILE_RECORD              ( 20 )
+#define MB_FUNC_WRITE_MULTIPLE_COILS          ( 15 )
+#define MB_FUNC_READ_HOLDING_REGISTER         (  3 )
+#define MB_FUNC_READ_INPUT_REGISTER           (  4 )
+#define MB_FUNC_WRITE_REGISTER                (  6 )
+#define MB_FUNC_WRITE_MULTIPLE_REGISTERS      ( 16 )
+#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS  ( 23 )
+#define MB_FUNC_DIAG_READ_EXCEPTION           (  7 )
+#define MB_FUNC_DIAG_DIAGNOSTIC               (  8 )
+#define MB_FUNC_DIAG_GET_COM_EVENT_CNT        ( 11 )
+#define MB_FUNC_DIAG_GET_COM_EVENT_LOG        ( 12 )
+#define MB_FUNC_OTHER_REPORT_SLAVEID          ( 17 )
+#define MB_FUNC_UPDATE                        ( 65 )
+#define MB_FUNC_SET_ADDR_ID                   ( 66 )
+#define MB_FUNC_SET_ADDR_SERIAL               ( 67 )
+#define MB_FUNC_ERROR                         ( 128 )
+
+/* ----------------------- Type definitions ---------------------------------*/
+    typedef enum
+{
+    MB_EX_NONE = 0x00,
+    MB_EX_ILLEGAL_FUNCTION = 0x01,
+    MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
+    MB_EX_ILLEGAL_DATA_VALUE = 0x03,
+    MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
+    MB_EX_ACKNOWLEDGE = 0x05,
+    MB_EX_SLAVE_BUSY = 0x06,
+    MB_EX_MEMORY_PARITY_ERROR = 0x08,
+    MB_EX_GATEWAY_PATH_FAILED = 0x0A,
+    MB_EX_GATEWAY_TGT_FAILED = 0x0B
+} eMBException;
+
+typedef         eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );
+
+typedef struct
+{
+    UCHAR           ucFunctionCode;
+    pxMBFunctionHandler pxHandler;
+} xMBFunctionHandler;
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif

+ 465 - 463
shared/freemodbus/mb.c

@@ -1,463 +1,465 @@
-/* 
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbconfig.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbfunc.h"
-
-#include "mbport.h"
-#if MB_RTU_ENABLED == 1
-#include "mbrtu.h"
-#endif
-#if MB_ASCII_ENABLED == 1
-#include "mbascii.h"
-#endif
-#if MB_TCP_ENABLED == 1
-#include "mbtcp.h"
-#endif
-
-#ifndef MB_PORT_HAS_CLOSE
-#define MB_PORT_HAS_CLOSE 0
-#endif
-
-//#include "tinystdio.h"
-
-UCHAR rcvAddress;
-
-/* ----------------------- Static variables ---------------------------------*/
-
-static UCHAR    ucMBAddress;
-static eMBMode  eMBCurrentMode;
-
-static enum
-{
-    STATE_ENABLED,
-    STATE_DISABLED,
-    STATE_NOT_INITIALIZED
-} eMBState = STATE_NOT_INITIALIZED;
-
-/* Functions pointer which are initialized in eMBInit( ). Depending on the
- * mode (RTU or ASCII) the are set to the correct implementations.
- */
-static peMBFrameSend peMBFrameSendCur;
-static pvMBFrameStart pvMBFrameStartCur;
-static pvMBFrameStop pvMBFrameStopCur;
-static peMBFrameReceive peMBFrameReceiveCur;
-static pvMBFrameClose pvMBFrameCloseCur;
-
-/* Callback functions required by the porting layer. They are called when
- * an external event has happend which includes a timeout or the reception
- * or transmission of a character.
- */
-BOOL( *pxMBFrameCBByteReceived ) ( void );
-BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
-BOOL( *pxMBPortCBTimerExpired ) ( void );
-
-BOOL( *pxMBFrameCBReceiveFSMCur ) ( void );
-BOOL( *pxMBFrameCBTransmitFSMCur ) ( void );
-
-/* An array of Modbus functions handlers which associates Modbus function
- * codes with implementing functions.
- */
-static xMBFunctionHandler xFuncHandlers[MB_FUNC_HANDLERS_MAX] = {
-#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
-    {MB_FUNC_OTHER_REPORT_SLAVEID, eMBFuncReportSlaveID},
-#endif
-#if MB_FUNC_READ_INPUT_ENABLED > 0
-    {MB_FUNC_READ_INPUT_REGISTER, eMBFuncReadInputRegister},
-#endif
-#if MB_FUNC_READ_HOLDING_ENABLED > 0
-    {MB_FUNC_READ_HOLDING_REGISTER, eMBFuncReadHoldingRegister},
-#endif
-#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
-    {MB_FUNC_WRITE_MULTIPLE_REGISTERS, eMBFuncWriteMultipleHoldingRegister},
-#endif
-#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
-    {MB_FUNC_WRITE_REGISTER, eMBFuncWriteHoldingRegister},
-#endif
-#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
-    {MB_FUNC_READWRITE_MULTIPLE_REGISTERS, eMBFuncReadWriteMultipleHoldingRegister},
-#endif
-#if MB_FUNC_READ_COILS_ENABLED > 0
-    {MB_FUNC_READ_COILS, eMBFuncReadCoils},
-#endif
-#if MB_FUNC_WRITE_COIL_ENABLED > 0
-    {MB_FUNC_WRITE_SINGLE_COIL, eMBFuncWriteCoil},
-#endif
-#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
-    {MB_FUNC_WRITE_MULTIPLE_COILS, eMBFuncWriteMultipleCoils},
-#endif
-#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
-    {MB_FUNC_READ_DISCRETE_INPUTS, eMBFuncReadDiscreteInputs},
-#endif
-#if MB_FUNC_UPDATE_ENABLED > 0
-    {MB_FUNC_UPDATE, eMBFuncUpdate},
-#endif
-#if MB_FUNC_SET_ADDR_ID_ENABLED > 0
-    {MB_FUNC_SET_ADDR_ID, eMBFuncSetAddrId},
-#endif
-#if MB_FUNC_SET_ADDR_SERIAL_ENABLED > 0
-    {MB_FUNC_SET_ADDR_SERIAL, eMBFuncSetAddrSerial}
-#endif
-
-};
-
-/* ----------------------- Start implementation -----------------------------*/
-eMBErrorCode
-eMBInit( eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, 
-         eMBParity eParity, unsigned int stop_bit )
-{
-    eMBErrorCode    eStatus = MB_ENOERR;
-
-    /* check preconditions */
-    if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
-        ( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
-    {
-        eStatus = MB_EINVAL;
-    }
-    else
-    {
-        ucMBAddress = ucSlaveAddress;
-
-        switch ( eMode )
-        {
-#if MB_RTU_ENABLED > 0
-        case MB_RTU:
-            pvMBFrameStartCur = eMBRTUStart;
-            pvMBFrameStopCur = eMBRTUStop;
-            peMBFrameSendCur = eMBRTUSend;
-            peMBFrameReceiveCur = eMBRTUReceive;
-            pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBPortClose : NULL;
-            pxMBFrameCBByteReceived = xMBRTUReceiveFSM;
-            pxMBFrameCBTransmitterEmpty = xMBRTUTransmitFSM;
-            pxMBPortCBTimerExpired = xMBRTUTimerT35Expired;
-
-            eStatus = eMBRTUInit( ucMBAddress, ucPort, ulBaudRate, eParity, stop_bit );
-            break;
-#endif
-#if MB_ASCII_ENABLED > 0
-        case MB_ASCII:
-            pvMBFrameStartCur = eMBASCIIStart;
-            pvMBFrameStopCur = eMBASCIIStop;
-            peMBFrameSendCur = eMBASCIISend;
-            peMBFrameReceiveCur = eMBASCIIReceive;
-            pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBPortClose : NULL;
-            pxMBFrameCBByteReceived = xMBASCIIReceiveFSM;
-            pxMBFrameCBTransmitterEmpty = xMBASCIITransmitFSM;
-            pxMBPortCBTimerExpired = xMBASCIITimerT1SExpired;
-
-            eStatus = eMBASCIIInit( ucMBAddress, ucPort, ulBaudRate, eParity );
-            break;
-#endif
-        default:
-            eStatus = MB_EINVAL;
-        }
-
-        if( eStatus == MB_ENOERR )
-        {
-            if( !xMBPortEventInit(  ) )
-            {
-                /* port dependent event module initalization failed. */
-                eStatus = MB_EPORTERR;
-            }
-            else
-            {
-                eMBCurrentMode = eMode;
-                eMBState = STATE_DISABLED;
-            }
-        }
-    }
-    return eStatus;
-}
-
-#if MB_TCP_ENABLED > 0
-eMBErrorCode
-eMBTCPInit( USHORT ucTCPPort )
-{
-    eMBErrorCode    eStatus = MB_ENOERR;
-
-    if( ( eStatus = eMBTCPDoInit( ucTCPPort ) ) != MB_ENOERR )
-    {
-        eMBState = STATE_DISABLED;
-    }
-    else if( !xMBPortEventInit(  ) )
-    {
-        /* Port dependent event module initalization failed. */
-        eStatus = MB_EPORTERR;
-    }
-    else
-    {
-        pvMBFrameStartCur = eMBTCPStart;
-        pvMBFrameStopCur = eMBTCPStop;
-        peMBFrameReceiveCur = eMBTCPReceive;
-        peMBFrameSendCur = eMBTCPSend;
-        pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBTCPPortClose : NULL;
-        ucMBAddress = MB_TCP_PSEUDO_ADDRESS;
-        eMBCurrentMode = MB_TCP;
-        eMBState = STATE_DISABLED;
-    }
-    return eStatus;
-}
-#endif
-
-eMBErrorCode
-eMBRegisterCB( UCHAR ucFunctionCode, pxMBFunctionHandler pxHandler )
-{
-    int             i;
-    eMBErrorCode    eStatus;
-
-    if( ( 0 < ucFunctionCode ) && ( ucFunctionCode <= 127 ) )
-    {
-        ENTER_CRITICAL_SECTION(  );
-        if( pxHandler != NULL )
-        {
-            for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
-            {
-                if( ( xFuncHandlers[i].pxHandler == NULL ) ||
-                    ( xFuncHandlers[i].pxHandler == pxHandler ) )
-                {
-                    xFuncHandlers[i].ucFunctionCode = ucFunctionCode;
-                    xFuncHandlers[i].pxHandler = pxHandler;
-                    break;
-                }
-            }
-            eStatus = ( i != MB_FUNC_HANDLERS_MAX ) ? MB_ENOERR : MB_ENORES;
-        }
-        else
-        {
-            for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
-            {
-                if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
-                {
-                    xFuncHandlers[i].ucFunctionCode = 0;
-                    xFuncHandlers[i].pxHandler = NULL;
-                    break;
-                }
-            }
-            /* Remove can't fail. */
-            eStatus = MB_ENOERR;
-        }
-        EXIT_CRITICAL_SECTION(  );
-    }
-    else
-    {
-        eStatus = MB_EINVAL;
-    }
-    return eStatus;
-}
-
-
-eMBErrorCode
-eMBClose( void )
-{
-    eMBErrorCode    eStatus = MB_ENOERR;
-
-    if( eMBState == STATE_DISABLED )
-    {
-        if( pvMBFrameCloseCur != NULL )
-        {
-            pvMBFrameCloseCur(  );
-        }
-    }
-    else
-    {
-        eStatus = MB_EILLSTATE;
-    }
-    return eStatus;
-}
-
-eMBErrorCode
-eMBEnable( void )
-{
-    eMBErrorCode    eStatus = MB_ENOERR;
-
-    if( eMBState == STATE_DISABLED )
-    {
-        /* Activate the protocol stack. */
-        pvMBFrameStartCur(  );
-        eMBState = STATE_ENABLED;
-    }
-    else
-    {
-        eStatus = MB_EILLSTATE;
-    }
-    return eStatus;
-}
-
-eMBErrorCode
-eMBDisable( void )
-{
-    eMBErrorCode    eStatus;
-
-    if( eMBState == STATE_ENABLED )
-    {
-        pvMBFrameStopCur(  );
-        eMBState = STATE_DISABLED;
-        eStatus = MB_ENOERR;
-    }
-    else if( eMBState == STATE_DISABLED )
-    {
-        eStatus = MB_ENOERR;
-    }
-    else
-    {
-        eStatus = MB_EILLSTATE;
-    }
-    return eStatus;
-}
-
-eMBErrorCode
-eMBPoll( void )
-{
-    static UCHAR   *ucMBFrame;
-    static UCHAR    ucRcvAddress;
-    static UCHAR    ucFunctionCode;
-    static USHORT   usLength;
-    static eMBException eException;
-
-    int             i;
-    eMBErrorCode    eStatus = MB_ENOERR;
-    eMBEventType    eEvent;
-
-    /* Check if the protocol stack is ready. */
-    if( eMBState != STATE_ENABLED )
-    {
-        return MB_EILLSTATE;
-    }
-
-    /* Check if there is a event available. If not return control to caller.
-     * Otherwise we will handle the event. */
-    if( xMBPortEventGet( &eEvent ) == TRUE )
-    {
-        switch ( eEvent )
-        {
-        case EV_READY:
-            break;
-
-        case EV_FRAME_RECEIVED:
-            eStatus = peMBFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
-            if( eStatus == MB_ENOERR )
-            {
-                /* Check if the frame is for us. If not ignore the frame. */
-                if( ( ucRcvAddress == ucMBAddress ) || ( ucRcvAddress == MB_ADDRESS_BROADCAST ) )
-                {
-                    rcvAddress = ucRcvAddress;
-                    ( void )xMBPortEventPost( EV_EXECUTE );
-                    //printf("mb_event: EV_EXECUTE\r\n");
-                }
-            }
-            break;
-
-        case EV_EXECUTE:
-            ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
-            eException = MB_EX_ILLEGAL_FUNCTION;
-            for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
-            {
-                /* No more function handlers registered. Abort. */
-                if( xFuncHandlers[i].ucFunctionCode == 0 )
-                {
-                    break;
-                }
-                else if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
-                {
-                    eException = xFuncHandlers[i].pxHandler( ucMBFrame, &usLength );
-                    break;
-                }
-            }
-
-            /* If the request was not sent to the broadcast address we
-             * return a reply. */
-            if( ucRcvAddress != MB_ADDRESS_BROADCAST )
-            {
-                if( eException != MB_EX_NONE )
-                {
-                    /* An exception occured. Build an error frame. */
-                    usLength = 0;
-                    ucMBFrame[usLength++] = ( UCHAR )( ucFunctionCode | MB_FUNC_ERROR );
-                    ucMBFrame[usLength++] = eException;
-                }
-                if( ( eMBCurrentMode == MB_ASCII ) && MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS )
-                {
-                    vMBPortTimersDelay( MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS );
-                }                
-                eStatus = peMBFrameSendCur( ucMBAddress, ucMBFrame, usLength );
-            }
-            break;
-
-        case EV_FRAME_SENT:
-            //printf("recv event: EV_FRAME_SENT\r\n");
-            break;
-        }
-    }
-    return MB_ENOERR;
-}
-
-
-//
-eMBErrorCode
-eMBCheckSlaveAddr(UCHAR ucSlaveAddress)
-{
-    if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
-        ( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
-    {
-        return MB_EINVAL;
-    }
-    else
-    {
-        return MB_ENOERR;
-    }
-}
-
-
-//
-eMBErrorCode
-eMBSetSlaveAddr(UCHAR ucSlaveAddress)
-{
-    if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
-        ( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
-    {
-        return MB_EINVAL;
-    }
-    else
-    {
-        ucMBAddress = ucSlaveAddress;
-    }
-    return MB_ENOERR;
-}
-  
+/* 
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006-2018 Christian Walter <cwalter@embedded-solutions.at>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* ----------------------- System includes ----------------------------------*/
+#include "stdlib.h"
+#include "string.h"
+
+/* ----------------------- Platform includes --------------------------------*/
+#include "port.h"
+
+/* ----------------------- Modbus includes ----------------------------------*/
+#include "mb.h"
+#include "mbconfig.h"
+#include "mbframe.h"
+#include "mbproto.h"
+#include "mbfunc.h"
+
+#include "mbport.h"
+#if MB_RTU_ENABLED == 1
+#include "mbrtu.h"
+#endif
+#if MB_ASCII_ENABLED == 1
+#include "mbascii.h"
+#endif
+#if MB_TCP_ENABLED == 1
+#include "mbtcp.h"
+#endif
+
+#ifndef MB_PORT_HAS_CLOSE
+#define MB_PORT_HAS_CLOSE 0
+#endif
+
+//#include "tinystdio.h"
+
+UCHAR rcvAddress;
+
+/* ----------------------- Static variables ---------------------------------*/
+
+static UCHAR    ucMBAddress;
+static eMBMode  eMBCurrentMode;
+
+static enum
+{
+    STATE_ENABLED,
+    STATE_DISABLED,
+    STATE_NOT_INITIALIZED
+} eMBState = STATE_NOT_INITIALIZED;
+
+/* Functions pointer which are initialized in eMBInit( ). Depending on the
+ * mode (RTU or ASCII) the are set to the correct implementations.
+ */
+static peMBFrameSend peMBFrameSendCur;
+static pvMBFrameStart pvMBFrameStartCur;
+static pvMBFrameStop pvMBFrameStopCur;
+static peMBFrameReceive peMBFrameReceiveCur;
+static pvMBFrameClose pvMBFrameCloseCur;
+
+/* Callback functions required by the porting layer. They are called when
+ * an external event has happend which includes a timeout or the reception
+ * or transmission of a character.
+ */
+BOOL( *pxMBFrameCBByteReceived ) ( void );
+BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
+BOOL( *pxMBPortCBTimerExpired ) ( void );
+
+BOOL( *pxMBFrameCBReceiveFSMCur ) ( void );
+BOOL( *pxMBFrameCBTransmitFSMCur ) ( void );
+
+/* An array of Modbus functions handlers which associates Modbus function
+ * codes with implementing functions.
+ */
+static xMBFunctionHandler xFuncHandlers[MB_FUNC_HANDLERS_MAX] = {
+#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
+    {MB_FUNC_OTHER_REPORT_SLAVEID, eMBFuncReportSlaveID},
+#endif
+#if MB_FUNC_READ_INPUT_ENABLED > 0
+    {MB_FUNC_READ_INPUT_REGISTER, eMBFuncReadInputRegister},
+#endif
+#if MB_FUNC_READ_HOLDING_ENABLED > 0
+    {MB_FUNC_READ_HOLDING_REGISTER, eMBFuncReadHoldingRegister},
+#endif
+#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
+    {MB_FUNC_WRITE_MULTIPLE_REGISTERS, eMBFuncWriteMultipleHoldingRegister},
+#endif
+#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
+    {MB_FUNC_WRITE_REGISTER, eMBFuncWriteHoldingRegister},
+#endif
+#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
+    {MB_FUNC_READWRITE_MULTIPLE_REGISTERS, eMBFuncReadWriteMultipleHoldingRegister},
+#endif
+#if MB_FUNC_READ_COILS_ENABLED > 0
+    {MB_FUNC_READ_COILS, eMBFuncReadCoils},
+#endif
+#if MB_FUNC_WRITE_COIL_ENABLED > 0
+    {MB_FUNC_WRITE_SINGLE_COIL, eMBFuncWriteCoil},
+#endif
+#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
+    {MB_FUNC_WRITE_MULTIPLE_COILS, eMBFuncWriteMultipleCoils},
+#endif
+#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
+    {MB_FUNC_READ_DISCRETE_INPUTS, eMBFuncReadDiscreteInputs},
+#endif
+#if MB_FUNC_UPDATE_ENABLED > 0
+    {MB_FUNC_UPDATE, eMBFuncUpdate},
+#endif
+#if MB_FUNC_SET_ADDR_ID_ENABLED > 0
+    {MB_FUNC_SET_ADDR_ID, eMBFuncSetAddrId},
+#endif
+#if MB_FUNC_SET_ADDR_SERIAL_ENABLED > 0
+    {MB_FUNC_SET_ADDR_SERIAL, eMBFuncSetAddrSerial},
+#endif
+#if MB_FUNC_READ_FILE_RECORD_ENABLED > 0 
+    {MB_FUNC_READ_FILE_RECORD, eMBFuncReadFileRecord}  
+#endif    
+};
+
+/* ----------------------- Start implementation -----------------------------*/
+eMBErrorCode
+eMBInit( eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, 
+         eMBParity eParity, unsigned int stop_bit )
+{
+    eMBErrorCode    eStatus = MB_ENOERR;
+
+    /* check preconditions */
+    if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
+        ( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
+    {
+        eStatus = MB_EINVAL;
+    }
+    else
+    {
+        ucMBAddress = ucSlaveAddress;
+
+        switch ( eMode )
+        {
+#if MB_RTU_ENABLED > 0
+        case MB_RTU:
+            pvMBFrameStartCur = eMBRTUStart;
+            pvMBFrameStopCur = eMBRTUStop;
+            peMBFrameSendCur = eMBRTUSend;
+            peMBFrameReceiveCur = eMBRTUReceive;
+            pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBPortClose : NULL;
+            pxMBFrameCBByteReceived = xMBRTUReceiveFSM;
+            pxMBFrameCBTransmitterEmpty = xMBRTUTransmitFSM;
+            pxMBPortCBTimerExpired = xMBRTUTimerT35Expired;
+
+            eStatus = eMBRTUInit( ucMBAddress, ucPort, ulBaudRate, eParity, stop_bit );
+            break;
+#endif
+#if MB_ASCII_ENABLED > 0
+        case MB_ASCII:
+            pvMBFrameStartCur = eMBASCIIStart;
+            pvMBFrameStopCur = eMBASCIIStop;
+            peMBFrameSendCur = eMBASCIISend;
+            peMBFrameReceiveCur = eMBASCIIReceive;
+            pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBPortClose : NULL;
+            pxMBFrameCBByteReceived = xMBASCIIReceiveFSM;
+            pxMBFrameCBTransmitterEmpty = xMBASCIITransmitFSM;
+            pxMBPortCBTimerExpired = xMBASCIITimerT1SExpired;
+
+            eStatus = eMBASCIIInit( ucMBAddress, ucPort, ulBaudRate, eParity );
+            break;
+#endif
+        default:
+            eStatus = MB_EINVAL;
+        }
+
+        if( eStatus == MB_ENOERR )
+        {
+            if( !xMBPortEventInit(  ) )
+            {
+                /* port dependent event module initalization failed. */
+                eStatus = MB_EPORTERR;
+            }
+            else
+            {
+                eMBCurrentMode = eMode;
+                eMBState = STATE_DISABLED;
+            }
+        }
+    }
+    return eStatus;
+}
+
+#if MB_TCP_ENABLED > 0
+eMBErrorCode
+eMBTCPInit( USHORT ucTCPPort )
+{
+    eMBErrorCode    eStatus = MB_ENOERR;
+
+    if( ( eStatus = eMBTCPDoInit( ucTCPPort ) ) != MB_ENOERR )
+    {
+        eMBState = STATE_DISABLED;
+    }
+    else if( !xMBPortEventInit(  ) )
+    {
+        /* Port dependent event module initalization failed. */
+        eStatus = MB_EPORTERR;
+    }
+    else
+    {
+        pvMBFrameStartCur = eMBTCPStart;
+        pvMBFrameStopCur = eMBTCPStop;
+        peMBFrameReceiveCur = eMBTCPReceive;
+        peMBFrameSendCur = eMBTCPSend;
+        pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBTCPPortClose : NULL;
+        ucMBAddress = MB_TCP_PSEUDO_ADDRESS;
+        eMBCurrentMode = MB_TCP;
+        eMBState = STATE_DISABLED;
+    }
+    return eStatus;
+}
+#endif
+
+eMBErrorCode
+eMBRegisterCB( UCHAR ucFunctionCode, pxMBFunctionHandler pxHandler )
+{
+    int             i;
+    eMBErrorCode    eStatus;
+
+    if( ( 0 < ucFunctionCode ) && ( ucFunctionCode <= 127 ) )
+    {
+        ENTER_CRITICAL_SECTION(  );
+        if( pxHandler != NULL )
+        {
+            for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
+            {
+                if( ( xFuncHandlers[i].pxHandler == NULL ) ||
+                    ( xFuncHandlers[i].pxHandler == pxHandler ) )
+                {
+                    xFuncHandlers[i].ucFunctionCode = ucFunctionCode;
+                    xFuncHandlers[i].pxHandler = pxHandler;
+                    break;
+                }
+            }
+            eStatus = ( i != MB_FUNC_HANDLERS_MAX ) ? MB_ENOERR : MB_ENORES;
+        }
+        else
+        {
+            for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
+            {
+                if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
+                {
+                    xFuncHandlers[i].ucFunctionCode = 0;
+                    xFuncHandlers[i].pxHandler = NULL;
+                    break;
+                }
+            }
+            /* Remove can't fail. */
+            eStatus = MB_ENOERR;
+        }
+        EXIT_CRITICAL_SECTION(  );
+    }
+    else
+    {
+        eStatus = MB_EINVAL;
+    }
+    return eStatus;
+}
+
+
+eMBErrorCode
+eMBClose( void )
+{
+    eMBErrorCode    eStatus = MB_ENOERR;
+
+    if( eMBState == STATE_DISABLED )
+    {
+        if( pvMBFrameCloseCur != NULL )
+        {
+            pvMBFrameCloseCur(  );
+        }
+    }
+    else
+    {
+        eStatus = MB_EILLSTATE;
+    }
+    return eStatus;
+}
+
+eMBErrorCode
+eMBEnable( void )
+{
+    eMBErrorCode    eStatus = MB_ENOERR;
+
+    if( eMBState == STATE_DISABLED )
+    {
+        /* Activate the protocol stack. */
+        pvMBFrameStartCur(  );
+        eMBState = STATE_ENABLED;
+    }
+    else
+    {
+        eStatus = MB_EILLSTATE;
+    }
+    return eStatus;
+}
+
+eMBErrorCode
+eMBDisable( void )
+{
+    eMBErrorCode    eStatus;
+
+    if( eMBState == STATE_ENABLED )
+    {
+        pvMBFrameStopCur(  );
+        eMBState = STATE_DISABLED;
+        eStatus = MB_ENOERR;
+    }
+    else if( eMBState == STATE_DISABLED )
+    {
+        eStatus = MB_ENOERR;
+    }
+    else
+    {
+        eStatus = MB_EILLSTATE;
+    }
+    return eStatus;
+}
+
+eMBErrorCode
+eMBPoll( void )
+{
+    static UCHAR   *ucMBFrame;
+    static UCHAR    ucRcvAddress;
+    static UCHAR    ucFunctionCode;
+    static USHORT   usLength;
+    static eMBException eException;
+
+    int             i;
+    eMBErrorCode    eStatus = MB_ENOERR;
+    eMBEventType    eEvent;
+
+    /* Check if the protocol stack is ready. */
+    if( eMBState != STATE_ENABLED )
+    {
+        return MB_EILLSTATE;
+    }
+
+    /* Check if there is a event available. If not return control to caller.
+     * Otherwise we will handle the event. */
+    if( xMBPortEventGet( &eEvent ) == TRUE )
+    {
+        switch ( eEvent )
+        {
+        case EV_READY:
+            break;
+
+        case EV_FRAME_RECEIVED:
+            eStatus = peMBFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
+            if( eStatus == MB_ENOERR )
+            {
+                /* Check if the frame is for us. If not ignore the frame. */
+                if( ( ucRcvAddress == ucMBAddress ) || ( ucRcvAddress == MB_ADDRESS_BROADCAST ) )
+                {
+                    rcvAddress = ucRcvAddress;
+                    ( void )xMBPortEventPost( EV_EXECUTE );
+                    //printf("mb_event: EV_EXECUTE\r\n");
+                }
+            }
+            break;
+
+        case EV_EXECUTE:
+            ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
+            eException = MB_EX_ILLEGAL_FUNCTION;
+            for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
+            {
+                /* No more function handlers registered. Abort. */
+                if( xFuncHandlers[i].ucFunctionCode == 0 )
+                {
+                    break;
+                }
+                else if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
+                {
+                    eException = xFuncHandlers[i].pxHandler( ucMBFrame, &usLength );
+                    break;
+                }
+            }
+
+            /* If the request was not sent to the broadcast address we
+             * return a reply. */
+            if( ucRcvAddress != MB_ADDRESS_BROADCAST )
+            {
+                if( eException != MB_EX_NONE )
+                {
+                    /* An exception occured. Build an error frame. */
+                    usLength = 0;
+                    ucMBFrame[usLength++] = ( UCHAR )( ucFunctionCode | MB_FUNC_ERROR );
+                    ucMBFrame[usLength++] = eException;
+                }
+                if( ( eMBCurrentMode == MB_ASCII ) && MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS )
+                {
+                    vMBPortTimersDelay( MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS );
+                }                
+                eStatus = peMBFrameSendCur( ucMBAddress, ucMBFrame, usLength );
+            }
+            break;
+
+        case EV_FRAME_SENT:
+            //printf("recv event: EV_FRAME_SENT\r\n");
+            break;
+        }
+    }
+    return MB_ENOERR;
+}
+
+
+//
+eMBErrorCode
+eMBCheckSlaveAddr(UCHAR ucSlaveAddress)
+{
+    if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
+        ( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
+    {
+        return MB_EINVAL;
+    }
+    else
+    {
+        return MB_ENOERR;
+    }
+}
+
+
+//
+eMBErrorCode
+eMBSetSlaveAddr(UCHAR ucSlaveAddress)
+{
+    if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
+        ( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
+    {
+        return MB_EINVAL;
+    }
+    else
+    {
+        ucMBAddress = ucSlaveAddress;
+    }
+    return MB_ENOERR;
+}
+  

BIN
tools/__pycache__/modbus.cpython-310.pyc


+ 6 - 3
tools/io_module.py

@@ -213,12 +213,13 @@ class IO_Module(Modbus):
     def set_rtc(self, utc):
         self.write_uint32(reg_table['rtc_sinhro'], utc)
 
-    
+    def get_archive_entryes(self, ent_num):
+        return self.read_file_record(6, 3, 1, 2)
 
 def main():
     colorama.init(autoreset=True)
     dev = IO_Module('COM24', 115200, 15)
-    dev.MB_DEBUG = False
+    dev.MB_DEBUG = True
     
     # dev.update('fw.bin')
 
@@ -233,8 +234,10 @@ def main():
     # unix_time = dev.get_rtc()
     # print(f'RTC: {time.ctime(unix_time)}. Unix time stamp:  {unix_time}')
     
+    dev.get_archive_entryes(1)
     
-    
+    return
+
     for i in range(1, 9):
         dev.set_input_mode(i, 1)
         print('Inputs mode [bit field]   :', Fore.GREEN + dev.get_inputs_mode())

+ 10 - 0
tools/modbus.py

@@ -167,6 +167,16 @@ class Modbus(ModbusMixin):
         if request != response:
             raise MBError('Incorrect response payload')
 
+    # 0x14
+    def read_file_record(self, ref_type: int, file_num: int, rec_num: int, rec_len: int):
+        """Read file record"""
+        request = bytearray((self.address,  0x14, 7, ref_type))
+        request += file_num.to_bytes(2, 'big')
+        request += rec_num.to_bytes(2, 'big')
+        request += rec_len.to_bytes(2, 'big')
+        response = self.raw_communicate(request + self._crc(request))
+        return response        
+
     def write_uint32(self, address: int, value: int):
         """Write 32-bit integer to holding register"""
         self.write_holding_registers_raw(address, struct.pack('>I', value))

+ 6 - 0
tools/test_bytes.py

@@ -0,0 +1,6 @@
+# req = bytes((1, 2, 3), encoding='utf-8')
+foo = 12
+req = bytearray((1, 2, 3))
+req += foo.to_bytes(2, 'big')
+print(type(foo.to_bytes(2, 'big')))
+print(req)

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff