123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #include "stdlib.h"
- #include "string.h"
- #include "port.h"
- #include "mb.h"
- #include "mbframe.h"
- #include "mbproto.h"
- #include "mbconfig.h"
- #define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF )
- #define MB_PDU_FUNC_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
- #define MB_PDU_FUNC_READ_SIZE ( 4 )
- #define MB_PDU_FUNC_READ_REGCNT_MAX ( 0x007D )
- #define MB_PDU_FUNC_READ_RSP_BYTECNT_OFF ( MB_PDU_DATA_OFF )
- eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
- #if MB_FUNC_READ_INPUT_ENABLED > 0
- eMBException
- eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen )
- {
- USHORT usRegAddress;
- USHORT usRegCount;
- UCHAR *pucFrameCur;
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
- if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
- usRegAddress++;
- usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 );
- usRegCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] );
-
- if( ( usRegCount >= 1 )
- && ( usRegCount < MB_PDU_FUNC_READ_REGCNT_MAX ) )
- {
-
- pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
- *usLen = MB_PDU_FUNC_OFF;
-
- *pucFrameCur++ = MB_FUNC_READ_INPUT_REGISTER;
- *usLen += 1;
-
- *pucFrameCur++ = ( UCHAR )( usRegCount * 2 );
- *usLen += 1;
- eRegStatus =
- eMBRegInputCB( pucFrameCur, usRegAddress, usRegCount );
-
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- else
- {
- *usLen += usRegCount * 2;
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
-
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
- }
- #endif
|