[ create a new paste ] login | about

Link: http://codepad.org/mp2vHMbt    [ raw code | output | fork ]

C, pasted on Apr 22:
#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;
}


Output:
Line 20: error: iocan32.h: No such file or directory
Line 18: error: inavr.h: No such file or directory
Line 17: error: fled.h: No such file or directory
Line 15: error: mb.h: No such file or directory
Line 19: error: mbport.h: No such file or directory
Line 20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'usRegInputStart'
Line 21: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'usRegInputBuf'
Line 24: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'xMBPortSerialPutByte'
In function 'main':
Line 36: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ucSlaveID'
Line 36: error: 'ucSlaveID' undeclared (first use in this function)
Line 36: error: (Each undeclared identifier is reported only once
Line 36: error: for each function it appears in.)
Line 36: error: expected expression before ']' token
Line 37: error: 'eMBErrorCode' undeclared (first use in this function)
Line 37: error: expected ';' before 'eStatus'
Line 41: error: 'MB_ENOERR' undeclared (first use in this function)
Line 41: error: 'eStatus' undeclared (first use in this function)
Line 41: error: 'MB_RTU' undeclared (first use in this function)
Line 41: error: 'MB_PAR_NONE' undeclared (first use in this function)
Line 50: error: 'TRUE' undeclared (first use in this function)
Line 77: error: 'usRegInputBuf' undeclared (first use in this function)
t.c: At top level:
Line 83: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'eMBRegInputCB'
Line 110: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'tmp'
Line 113: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'eMBRegHoldingCB'
Line 131: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'eMBRegCoilsCB'
Line 138: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'eMBRegDiscreteCB'


Create a new paste based on this one


Comments: