Avispao
Hi,

I'm testing OpenPLC as soft PLC under Windows, but I'm not able to get or set the values of fixed memory location variables in my test program, because a core dump during post compilation process.

Quote:

Program compiled without errors!

compiling new program...
POUS.c
POUS.h
LOCATED_VARIABLES.h
VARIABLES.csv
Config0.c
Config0.h
Res0.c

Program compiled successfully
moving files...
compiling OpenPLC...
Generating object files...
Generating glueVars.cpp
varName: __MW2 varType: INT
./build_core.sh: línea 7: 9136 Segmentation fault (`core' generado) ./glue_generator.exe
Compiling main program
glueVars.cpp: En la función ‘void glueVars()’:
glueVars.cpp:72:1: error: expected ‘}’ at end of input
{
^
compiled without errors



I have looked for the problem and I found out, code section for memory variable allocation is not  finished.


  findPositions(varName, &pos1, &pos2);
  if (varName[2] == 'I')
  {
    //INPUT
    switch (varName[3])
    {
      case 'X':
        glueVars << "\tbool_input[" << pos1 << "][" << pos2 << "] = " << varName << ";\r\n";
        break;
      case 'W':
        glueVars << "\tint_input[" << pos1 << "][" << pos2 << "] = " << varName << ";\r\n";
        break;
    }
  }
  else if (varName[2] == 'Q')
  {
    //OUTPUT
    switch (varName[3])
    {
      case 'X':
        glueVars << "\tbool_output[" << pos1 << "][" << pos2 << "] = " << varName << ";\r\n";
        break;
      case 'W':
        glueVars << "\tint_output[" << pos1 << "][" << pos2 << "] = " << varName << ";\r\n";
        break;
    }
  }
  else if (varName[2] == 'M')
  {
    //MEMORY
    //pending...
  }
}



I've tried to complete the code, but... [biggrin]

I need some help.
Quote 0 0
thiagoralves
Although the implementation of Memory Vars is not finished, you shouldn't get a core dump. I believe it is more likely that you declared your variables in a wrong way. Aren't you missing a '.' (dot) on your variable? All located variables for the OpenPLC must have the notation %[I/Q/M][X/W]n.n so that your located memory var should be something like %MW0.2. If you just locate your var as %MW2 you might get unpredictable errors. I might take a look at this code in the future to prevent core dumps with bad addressing.

PS: You still can use %M as memory, and it should work fine. The code that is pending is just to attach (glue) it to the modbus module. It means that your memory vars won't be accessible by the modbus calls.
Quote 1 0
Avispao
Thanks for being so fast answering my question.

So, how do you locate two contiguous integer number?



Quote 0 0
thiagoralves
You can use %QW0.0 and %QW0.1. They are accessible by the Modbus Holding Registers (address 0 and 1 respectively) and are also you first two physical analog outputs (if you have any in your system). If you want something that will be still accessible by modbus but is not an analog output, you can try some further register out of the range of your physical analog outputs, something like %QW0.60 and %QW0.61 will probably do. They will be accessible by Modbus Holding Registers at address 60 and 61.
Quote 0 0