codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#define ENABLE_BIT_DEFINITIONS #include "iocan32.h" #include "inavr.h" #include <stdio.h> #include <string.h> #include "fled.h" /* ----------------------- Modbus includes ----------------------------------*/ #include "mb.h" #include "mbport.h" #define TEST_STR "HELLO GODS!\r\n" /* ----------------------- Defines ------------------------------------------*/ #define REG_INPUT_START 1000 #define REG_INPUT_NREGS 4 /* ----------------------- Static variables ---------------------------------*/ static USHORT usRegInputStart = REG_INPUT_START; static USHORT usRegInputBuf[REG_INPUT_NREGS]; static const char testStr[] = TEST_STR; extern BOOL xMBPortSerialPutByte( CHAR ucByte ); /** * @brief mainFunction * * @return */ int main (void) { initFled(); fledGreen(); // invertFled(); const UCHAR ucSlaveID[] = { 0xAA, 0xBB, 0xCC }; eMBErrorCode eStatus; ; if( MB_ENOERR != ( eStatus = eStatus = eMBInit( MB_RTU, 0x02, 0, 19200, MB_PAR_NONE ) ) ) { while(1) { fledGreen(); fledRed(); } } if( MB_ENOERR != ( eStatus = eMBSetSlaveID( 0x02, TRUE, ucSlaveID, 3 ) ) ) { while(1) { fledGreen(); fledRed(); } } if( MB_ENOERR != ( eStatus = eMBEnable( ) ) ) { while(1) { fledGreen(); fledRed(); } } asm("sei"); // for (int i = 0; i < 13; i++) xMBPortSerialPutByte (testStr[i]); while(1) { eStatus = eMBPoll( ); /* Here we simply count the number of poll cycles. */ usRegInputBuf[0]++; } } eMBErrorCode eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs ) { eMBErrorCode eStatus = MB_ENOERR; int iRegIndex; if( ( usAddress >= REG_INPUT_START ) && ( usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS ) ) { iRegIndex = ( int )( usAddress - usRegInputStart ); while( usNRegs > 0 ) { *pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] >> 8 ); *pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] & 0xFF ); iRegIndex++; usNRegs--; } } else { eStatus = MB_ENOERR; } return eStatus; } UCHAR tmp[] = {1,2,3,4,5,6,7,8,0,10}; eMBErrorCode eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode ) { *pucRegBuffer++=tmp[1]; *pucRegBuffer++=tmp[2]; *pucRegBuffer++=tmp[3]; *pucRegBuffer++=tmp[4]; *pucRegBuffer++=tmp[5]; *pucRegBuffer++=tmp[6]; *pucRegBuffer++=tmp[7]; *pucRegBuffer++=tmp[8]; *pucRegBuffer++=tmp[9]; *pucRegBuffer++=tmp[10]; return MB_ENOERR; } eMBErrorCode eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode ) { return MB_ENOERR; } eMBErrorCode eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete ) { return MB_ENOERR; }
Private
[
?
]
Run code
Submit