Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this example, we have two ‘files’ that we implemented as an array of 16-bit integers.

#define     APP_MAX_FILES 2
#define     APP_FILE_MAX_RECORDS   10
#define     APP_FILE_MAX_VALUES   100


CPU_INT16U  AppFile[APP_MAX_FILES][APP_FILE_MAX_RECORDS][APP_FILE_MAX_VALUES];



CPU_INT16U  MB_FileRd (CPU_INT16U   file_nbr, 
                       CPU_INT16U   record_nbr, 
                       CPU_INT16U   ix, 
                       CPU_INT08U   record_len, 
                       CPU_INT16U  *perr)
{
    CPU_INT16U  val;


    *perr = MODBUS_ERR_NONE;
    if (file_nbr >= APP_MAX_FILES) {
        *perr = MODBUS_ERR_FILE;
        return (0);
    }
    if (record_nbr >= APP_FILE_MAX_RECORDS) {
        *perr = MODBUS_ERR_RECORD;
        return (0);
    }
    if (ix >= APP_FILE_MAX_VALUES) {
        *perr = MODBUS_ERR_IX;
        return (0);
    }
    CPU_CRITICAL_ENTER();
    val = AppFile[file_nbr][record_nbr][ix];
    CPU_CRITICAL_EXIT();
    return (val);
}