mbfuncholding_m.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
  3. * Copyright (C) 2013 Armink <armink.ztl@gmail.com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. The name of the author may not be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * File: $Id: mbfuncholding_m.c,v 1.60 2013/09/02 14:13:40 Armink Add Master Functions Exp $
  29. */
  30. /* ----------------------- System includes ----------------------------------*/
  31. #include "stdlib.h"
  32. #include "string.h"
  33. /* ----------------------- Platform includes --------------------------------*/
  34. #include "port.h"
  35. /* ----------------------- Modbus includes ----------------------------------*/
  36. #include "mb.h"
  37. #include "mb_m.h"
  38. #include "mbframe.h"
  39. #include "mbproto.h"
  40. #include "mbconfig.h"
  41. /* ----------------------- Defines ------------------------------------------*/
  42. #define MB_PDU_REQ_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
  43. #define MB_PDU_REQ_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
  44. #define MB_PDU_REQ_READ_SIZE ( 4 )
  45. #define MB_PDU_FUNC_READ_REGCNT_MAX ( 0x007D )
  46. #define MB_PDU_FUNC_READ_BYTECNT_OFF ( MB_PDU_DATA_OFF + 0 )
  47. #define MB_PDU_FUNC_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
  48. #define MB_PDU_FUNC_READ_SIZE_MIN ( 1 )
  49. #define MB_PDU_REQ_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 0)
  50. #define MB_PDU_REQ_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
  51. #define MB_PDU_REQ_WRITE_SIZE ( 4 )
  52. #define MB_PDU_FUNC_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 0)
  53. #define MB_PDU_FUNC_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
  54. #define MB_PDU_FUNC_WRITE_SIZE ( 4 )
  55. #define MB_PDU_REQ_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
  56. #define MB_PDU_REQ_WRITE_MUL_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
  57. #define MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF ( MB_PDU_DATA_OFF + 4 )
  58. #define MB_PDU_REQ_WRITE_MUL_VALUES_OFF ( MB_PDU_DATA_OFF + 5 )
  59. #define MB_PDU_REQ_WRITE_MUL_SIZE_MIN ( 5 )
  60. #define MB_PDU_REQ_WRITE_MUL_REGCNT_MAX ( 0x0078 )
  61. #define MB_PDU_FUNC_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
  62. #define MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
  63. #define MB_PDU_FUNC_WRITE_MUL_SIZE ( 4 )
  64. #define MB_PDU_REQ_READWRITE_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
  65. #define MB_PDU_REQ_READWRITE_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
  66. #define MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 4 )
  67. #define MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF ( MB_PDU_DATA_OFF + 6 )
  68. #define MB_PDU_REQ_READWRITE_WRITE_BYTECNT_OFF ( MB_PDU_DATA_OFF + 8 )
  69. #define MB_PDU_REQ_READWRITE_WRITE_VALUES_OFF ( MB_PDU_DATA_OFF + 9 )
  70. #define MB_PDU_REQ_READWRITE_SIZE_MIN ( 9 )
  71. #define MB_PDU_FUNC_READWRITE_READ_BYTECNT_OFF ( MB_PDU_DATA_OFF + 0 )
  72. #define MB_PDU_FUNC_READWRITE_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
  73. #define MB_PDU_FUNC_READWRITE_SIZE_MIN ( 1 )
  74. /* ----------------------- Static functions ---------------------------------*/
  75. eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
  76. /* ----------------------- Start implementation -----------------------------*/
  77. #if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
  78. #if MB_FUNC_WRITE_HOLDING_ENABLED > 0
  79. eMBMasterReqErrCode
  80. eMBMasterReqWriteHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usRegData )
  81. {
  82. UCHAR *ucMBFrame;
  83. eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
  84. if ( xMBMasterGetIsBusy() ) eErrStatus = MB_MRE_MASTER_BUSY;
  85. else if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
  86. else
  87. {
  88. vMBMasterGetPDUSndBuf(&ucMBFrame);
  89. vMBMasterSetDestAddress(ucSndAddr);
  90. ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_REGISTER;
  91. ucMBFrame[MB_PDU_REQ_WRITE_ADDR_OFF] = usRegAddr >> 8;
  92. ucMBFrame[MB_PDU_REQ_WRITE_ADDR_OFF + 1] = usRegAddr;
  93. ucMBFrame[MB_PDU_REQ_WRITE_VALUE_OFF] = usRegData >> 8;
  94. ucMBFrame[MB_PDU_REQ_WRITE_VALUE_OFF + 1] = usRegData ;
  95. vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_WRITE_SIZE );
  96. ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
  97. }
  98. return eErrStatus;
  99. }
  100. eMBException
  101. eMBMasterFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
  102. {
  103. USHORT usRegAddress;
  104. eMBException eStatus = MB_EX_NONE;
  105. eMBErrorCode eRegStatus;
  106. if( *usLen == ( MB_PDU_SIZE_MIN + MB_PDU_FUNC_WRITE_SIZE ) )
  107. {
  108. usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8 );
  109. usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1] );
  110. usRegAddress++;
  111. /* Make callback to update the value. */
  112. eRegStatus = eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF],
  113. usRegAddress, 1, MB_REG_WRITE );
  114. /* If an error occured convert it into a Modbus exception. */
  115. if( eRegStatus != MB_ENOERR )
  116. {
  117. eStatus = prveMBError2Exception( eRegStatus );
  118. }
  119. }
  120. else
  121. {
  122. /* Can't be a valid request because the length is incorrect. */
  123. eStatus = MB_EX_ILLEGAL_DATA_VALUE;
  124. }
  125. return eStatus;
  126. }
  127. #endif
  128. #if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
  129. eMBMasterReqErrCode
  130. eMBMasterReqWriteMultipleHoldingRegister( UCHAR ucSndAddr,
  131. USHORT usRegAddr, USHORT usNRegs, USHORT * pusDataBuffer )
  132. {
  133. UCHAR *ucMBFrame;
  134. USHORT usRegIndex = 0;
  135. eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
  136. if ( xMBMasterGetIsBusy() ) eErrStatus = MB_MRE_MASTER_BUSY;
  137. else if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
  138. else
  139. {
  140. vMBMasterGetPDUSndBuf(&ucMBFrame);
  141. vMBMasterSetDestAddress(ucSndAddr);
  142. ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_MULTIPLE_REGISTERS;
  143. ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF] = usRegAddr >> 8;
  144. ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF + 1] = usRegAddr;
  145. ucMBFrame[MB_PDU_REQ_WRITE_MUL_REGCNT_OFF] = usNRegs >> 8;
  146. ucMBFrame[MB_PDU_REQ_WRITE_MUL_REGCNT_OFF + 1] = usNRegs ;
  147. ucMBFrame[MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF] = usNRegs * 2;
  148. ucMBFrame += MB_PDU_REQ_WRITE_MUL_VALUES_OFF;
  149. while( usNRegs > usRegIndex)
  150. {
  151. *ucMBFrame++ = pusDataBuffer[usRegIndex] >> 8;
  152. *ucMBFrame++ = pusDataBuffer[usRegIndex++] ;
  153. }
  154. vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_WRITE_MUL_SIZE_MIN + 2*usNRegs );
  155. ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
  156. }
  157. return eErrStatus;
  158. }
  159. eMBException
  160. eMBMasterFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
  161. {
  162. UCHAR *ucMBFrame;
  163. USHORT usRegAddress;
  164. USHORT usRegCount;
  165. UCHAR ucRegByteCount;
  166. eMBException eStatus = MB_EX_NONE;
  167. eMBErrorCode eRegStatus;
  168. if( *usLen == MB_PDU_SIZE_MIN + MB_PDU_FUNC_WRITE_MUL_SIZE )
  169. {
  170. vMBMasterGetPDUSndBuf(&ucMBFrame);
  171. usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF] << 8 );
  172. usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF + 1] );
  173. usRegAddress++;
  174. usRegCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_WRITE_MUL_REGCNT_OFF] << 8 );
  175. usRegCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_WRITE_MUL_REGCNT_OFF + 1] );
  176. ucRegByteCount = ucMBFrame[MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF];
  177. if( ucRegByteCount == 2 * usRegCount )
  178. {
  179. /* Make callback to update the register values. */
  180. eRegStatus =
  181. eMBRegHoldingCB( &ucMBFrame[MB_PDU_REQ_WRITE_MUL_VALUES_OFF],
  182. usRegAddress, usRegCount, MB_REG_WRITE );
  183. /* If an error occured convert it into a Modbus exception. */
  184. if( eRegStatus != MB_ENOERR )
  185. {
  186. eStatus = prveMBError2Exception( eRegStatus );
  187. }
  188. }
  189. else
  190. {
  191. eStatus = MB_EX_ILLEGAL_DATA_VALUE;
  192. }
  193. }
  194. else
  195. {
  196. /* Can't be a valid request because the length is incorrect. */
  197. eStatus = MB_EX_ILLEGAL_DATA_VALUE;
  198. }
  199. return eStatus;
  200. }
  201. #endif
  202. #if MB_FUNC_READ_HOLDING_ENABLED > 0
  203. eMBMasterReqErrCode
  204. eMBMasterReqReadHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usNRegs )
  205. {
  206. UCHAR *ucMBFrame;
  207. eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
  208. if ( xMBMasterGetIsBusy() ) eErrStatus = MB_MRE_MASTER_BUSY;
  209. else if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
  210. else
  211. {
  212. vMBMasterGetPDUSndBuf(&ucMBFrame);
  213. vMBMasterSetDestAddress(ucSndAddr);
  214. ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_HOLDING_REGISTER;
  215. ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] = usRegAddr >> 8;
  216. ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] = usRegAddr;
  217. ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF] = usNRegs >> 8;
  218. ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF + 1] = usNRegs;
  219. vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READ_SIZE );
  220. ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
  221. }
  222. return eErrStatus;
  223. }
  224. eMBException
  225. eMBMasterFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
  226. {
  227. UCHAR *ucMBFrame;
  228. USHORT usRegAddress;
  229. USHORT usRegCount;
  230. eMBException eStatus = MB_EX_NONE;
  231. eMBErrorCode eRegStatus;
  232. if( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READ_SIZE_MIN )
  233. {
  234. vMBMasterGetPDUSndBuf(&ucMBFrame);
  235. usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] << 8 );
  236. usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] );
  237. usRegAddress++;
  238. usRegCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF] << 8 );
  239. usRegCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF + 1] );
  240. /* Check if the number of registers to read is valid. If not
  241. * return Modbus illegal data value exception.
  242. */
  243. if( ( usRegCount >= 1 ) && ( 2 * usRegCount == pucFrame[MB_PDU_FUNC_READ_BYTECNT_OFF] ) )
  244. {
  245. /* Make callback to fill the buffer. */
  246. eRegStatus = eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_READ_VALUES_OFF], usRegAddress, usRegCount, MB_REG_READ );
  247. /* If an error occured convert it into a Modbus exception. */
  248. if( eRegStatus != MB_ENOERR )
  249. {
  250. eStatus = prveMBError2Exception( eRegStatus );
  251. }
  252. }
  253. else
  254. {
  255. eStatus = MB_EX_ILLEGAL_DATA_VALUE;
  256. }
  257. }
  258. else
  259. {
  260. /* Can't be a valid request because the length is incorrect. */
  261. eStatus = MB_EX_ILLEGAL_DATA_VALUE;
  262. }
  263. return eStatus;
  264. }
  265. #endif
  266. #if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
  267. eMBMasterReqErrCode
  268. eMBMasterReqReadWriteMultipleHoldingRegister( UCHAR ucSndAddr,
  269. USHORT usReadRegAddr, USHORT usNReadRegs, USHORT * pusDataBuffer,
  270. USHORT usWriteRegAddr, USHORT usNWriteRegs )
  271. {
  272. UCHAR *ucMBFrame;
  273. USHORT usRegIndex = 0;
  274. eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
  275. if ( xMBMasterGetIsBusy() ) eErrStatus = MB_MRE_MASTER_BUSY;
  276. else if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
  277. else
  278. {
  279. vMBMasterGetPDUSndBuf(&ucMBFrame);
  280. vMBMasterSetDestAddress(ucSndAddr);
  281. ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READWRITE_MULTIPLE_REGISTERS;
  282. ucMBFrame[MB_PDU_REQ_READWRITE_READ_ADDR_OFF] = usReadRegAddr >> 8;
  283. ucMBFrame[MB_PDU_REQ_READWRITE_READ_ADDR_OFF + 1] = usReadRegAddr;
  284. ucMBFrame[MB_PDU_REQ_READWRITE_READ_REGCNT_OFF] = usNReadRegs >> 8;
  285. ucMBFrame[MB_PDU_REQ_READWRITE_READ_REGCNT_OFF + 1] = usNReadRegs ;
  286. ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF] = usWriteRegAddr >> 8;
  287. ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF + 1] = usWriteRegAddr;
  288. ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF] = usNWriteRegs >> 8;
  289. ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF + 1] = usNWriteRegs ;
  290. ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_BYTECNT_OFF] = usNWriteRegs * 2;
  291. ucMBFrame += MB_PDU_REQ_READWRITE_WRITE_VALUES_OFF;
  292. while( usNWriteRegs > usRegIndex)
  293. {
  294. *ucMBFrame++ = pusDataBuffer[usRegIndex] >> 8;
  295. *ucMBFrame++ = pusDataBuffer[usRegIndex++] ;
  296. }
  297. vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READWRITE_SIZE_MIN + 2*usNWriteRegs );
  298. ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
  299. }
  300. return eErrStatus;
  301. }
  302. eMBException
  303. eMBMasterFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
  304. {
  305. USHORT usRegReadAddress;
  306. USHORT usRegReadCount;
  307. USHORT usRegWriteAddress;
  308. USHORT usRegWriteCount;
  309. UCHAR *ucMBFrame;
  310. eMBException eStatus = MB_EX_NONE;
  311. eMBErrorCode eRegStatus;
  312. if( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READWRITE_SIZE_MIN)
  313. {
  314. vMBMasterGetPDUSndBuf(&ucMBFrame);
  315. usRegReadAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_READ_ADDR_OFF] << 8U );
  316. usRegReadAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_READ_ADDR_OFF + 1] );
  317. usRegReadAddress++;
  318. usRegReadCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_READ_REGCNT_OFF] << 8U );
  319. usRegReadCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_READ_REGCNT_OFF + 1] );
  320. usRegWriteAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF] << 8U );
  321. usRegWriteAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF + 1] );
  322. usRegWriteAddress++;
  323. usRegWriteCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF] << 8U );
  324. usRegWriteCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF + 1] );
  325. if( ( 2 * usRegReadCount ) == pucFrame[MB_PDU_FUNC_READWRITE_READ_BYTECNT_OFF] )
  326. {
  327. /* Make callback to update the register values. */
  328. eRegStatus = eMBRegHoldingCB( &ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_VALUES_OFF],
  329. usRegWriteAddress, usRegWriteCount, MB_REG_WRITE );
  330. if( eRegStatus == MB_ENOERR )
  331. {
  332. /* Make the read callback. */
  333. eRegStatus = eMBRegHoldingCB(&pucFrame[MB_PDU_FUNC_READWRITE_READ_VALUES_OFF],
  334. usRegReadAddress, usRegReadCount, MB_REG_READ);
  335. }
  336. if( eRegStatus != MB_ENOERR )
  337. {
  338. eStatus = prveMBError2Exception( eRegStatus );
  339. }
  340. }
  341. else
  342. {
  343. eStatus = MB_EX_ILLEGAL_DATA_VALUE;
  344. }
  345. }
  346. return eStatus;
  347. }
  348. #endif
  349. #endif