Skip to content

Synchronized HTTP GET Access on Array (REST)

Hi,

I fill an array in the execute method of a C ++ program (cyclic task 100 ms).
In a IEC 61131-3 program, I copy the array into a global variable with HMI tag (cyclic task 100ms).
Both programs are located in the ESM1.
If I now access the array via HTTP GET command, it happens that the output consists half of old and half of new values.
How can I synchronize access, so that the array is not changed while the GET request is executed?

Example:
The array should be filled alternately with values from 0 to 9 or from 9 to 0, i.e. {0,1,2,3,4,5,6,7,8,9} or {9,8,7,6,5,4,3,2,1,0}.
Sometimes I get e.g. {0,1,2,3,5,4,3,2,1,0}.
(The real array contains of 2000 int values)

Best regards,
Fenja

Comments

  • Hi Fenja,

    I am wondering if this is something to do with the global variable.

    Can you please try the same thing, but in the IEC 61131-3 program, please copy the array into a local OUT port variable, marked with the HMI tag. And then read the data from that program instance variable, rather than from the global variable. In fact you can read from both variables and compare the result.

    If you see the same behaviour from a Port variable on a program instance, then we will need to investigate this further.
  • Hi Martin,

    the behavior still occurs with a local OUT port variable. I have also tried a direct link between the port array from the C ++ program and a local port variable (with HMI tag). Then, too, the problem occurred.
    Is it possible to use something like a mutex to avoid changing the array during the GET request? So a possibility to synchronize the access?

    Thanks for your help,
    Fenja
  • Hmm, I would expect that the data from an OUT port variable should not change while it is being read by another process - the idea behind the Global Data Space is that data should always be consistent.

    I will attempt to reproduce this error here.

    1) Can you confirm that the complete array is written during a single task execution cycle?

    2) Does the error still happen when you remove the C++ program from the equation, and simply fill the array from the IEC program?
  • In the C++ program, the array is filled with int values in a for loop, which should be done in a single task. So I really suspect the problem is with reading and writing at the same time.
    If I remove the C++ from execution and fill the array in the same way in the IEC program, the problem still occurs...

    Have you been able to reproduce the problem with you? Or should I send you any more information about my project?

    Regards,
    Fenja
  • Thanks for the extra information.
    I will discuss this with our REST experts here and get back to you.
  • Hi Fenja,
    I have discussed this with the developers of the REST interface, and it turns out that we do not guarantee the consistency of data in REST transactions.
    The background to this is that the REST interface was designed primarily for eHMI applications (i.e. data visualisation), and momentary data inconsistencies are not considered a big problem for visual displays.
    Sorry that there isn't better news in this case. If your application allows, you could consider using another interface (e.g. OPC UA) to exchange the array data with clients.
  • Okay. Thank you for your effort.
Sign In or Register to comment.