tompre
Hi,

the next issue I have found is in the Modbus slave service. The only types accessible over modbus are BOOL, INT, DINT and LINT. Because in a real life we usaualy need to access all variable types. It should be better to bind glue variables and Modbus buffers using size specifier of glue vars. Like here:

const GlueVariable* glue_variables = bindings.glue_variables;

for (size_t index = 0; index < bindings.size; ++index)
{
   IecGlueValueType type = glue_variables[index].type;
   IecLocationDirection dir = glue_variables[index].dir;
   uint16_t msi = glue_variables[index].msi;
   uint16_t size = glue_variables[index].size;

   if (size == IECLST_BIT)
   {
      const GlueBoolGroup* group = reinterpret_cast<const GlueBoolGroup*>(glue_variables[index].value);
      // The first coil index for this variable is always
      // multiplied by the number of booleans in that group
      // If this index is out of range, then skip it.
      if (dir == IECLDT_OUT)
      {
         initialize_mapped_from_group(msi, group, coil_read_buffer);
      }
      else if (dir == IECLDT_IN)
      {
         initialize_mapped_from_group(msi, group, di_read_buffer);
      }
   }
   else if (size == IECLST_WORD)
   {
      if (dir == IECLDT_OUT)
      {
         int_register_read_buffer[msi].init(reinterpret_cast<IEC_INT*>(glue_variables[index].value));  
      }
      else if (dir == IECLDT_MEM && msi < intm_register_read_buffer.size())
      {
         intm_register_read_buffer[msi].init(reinterpret_cast<IEC_INT*>(glue_variables[index].value));
      }
      else if (dir == IECLDT_IN)
      {
         int_input_read_buffer[msi].init(reinterpret_cast<IEC_INT*>(glue_variables[index].value));
      }
   }
   else if (size == IECLST_DOUBLEWORD && dir == IECLDT_MEM && msi < dintm_register_read_buffer.size())
   {
      dintm_register_read_buffer[msi].init(reinterpret_cast<IEC_DINT*>(glue_variables[index].value));
   }
   else if (size == IECLST_LONGWORD && dir == IECLDT_MEM && msi <= MIN_64B_RANGE && msi < MAX_64B_RANGE)
   {
      lintm_register_read_buffer[msi].init(reinterpret_cast<IEC_LINT*>(glue_variables[index].value));
   }
}


Regards
Tomas
Reply 0 0
tompre
Sorry... the snippet of code is from runtime/core/modbusslave/indexed_strategy.cpp
Reply 0 0
Reply