Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » [SOLVED] Creating an array and giving it as FB output
[SOLVED] Creating an array and giving it as FB output [message #1791272] Wed, 27 June 2018 12:23 Go to next message
Agostino Mascitti is currently offline Agostino MascittiFriend
Messages: 15
Registered: May 2018
Junior Member
Hello,

I am trying to create an array and give it as FB output. For example, the FB has an output field COUNTER of type ARRAY[3]. You want to assign it the array {1,0,1}.

I have seen in FORTE_SET_AT_INDEX::executeEvent() that you can do:
CIEC_ARRAY &rOutArray = static_cast<CIEC_ARRAY&>(OUT_ARRAY());
rOutArray[INDEX()]->saveAssign(VALUE());



Thus, I have tried something:
int counters[3] = {566,0,1011};

CIEC_ANY *c = 0;
        char temp[12] = "";
        sprintf(temp, "INT#%d", counters[i]);
        printf("%s\n", temp);
        c->fromString(temp);
        printf("c=%d\n", c);
        COUNTER_Array()[static_cast<TForteUInt16>(i)]->saveAssign(*c);



COUNTER_Array().fromString("[556,0,1011]");

but the code CIEC_ARRAY::fromString() has the comment "//TODO: for full compliance support of multiple element-statements must be implemented".

[Updated on: Thu, 28 June 2018 14:10]

Report message to a moderator

Re: Creating an array and giving it as FB output [message #1791273 is a reply to message #1791272] Wed, 27 June 2018 12:26 Go to previous messageGo to next message
Agostino Mascitti is currently offline Agostino MascittiFriend
Messages: 15
Registered: May 2018
Junior Member
No Message Body
Re: Creating an array and giving it as FB output [message #1791275 is a reply to message #1791273] Wed, 27 June 2018 12:33 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1581
Registered: January 2014
Senior Member

Hi,

I'm not sure if I understand the problem. fromString for single arrays definitly works. We have unit tests for that. The comment is that we currently are not supporting arrays of arrays. In ST you can also access in standard ST syntax each array element with the bracket operator (i.e., []).

Alois
Re: Creating an array and giving it as FB output [message #1791279 is a reply to message #1791275] Wed, 27 June 2018 13:38 Go to previous messageGo to next message
Agostino Mascitti is currently offline Agostino MascittiFriend
Messages: 15
Registered: May 2018
Junior Member
Hi, thank you for your reply!

To me the last instruction in the following snippet doesn't work. It should assign the array to the OUTPUT, a field in the bottom-right margin on the FB.
CIEC_ARRAY nTest(3, g_nStringIdINT);
      nTest.fromString("[1,2,3]");
      OUTPUT_Array().setValue(nTest);


Agostino
Re: Creating an array and giving it as FB output [message #1791280 is a reply to message #1791279] Wed, 27 June 2018 14:03 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1581
Registered: January 2014
Senior Member

We have a test for that as well. Just to be clear how did you define your output data type. did you use ARRAY or did you use INT and specifiy the array size of 3 in the interface editor. You have to do the latter.
Re: Creating an array and giving it as FB output [message #1791282 is a reply to message #1791280] Wed, 27 June 2018 14:41 Go to previous messageGo to next message
Agostino Mascitti is currently offline Agostino MascittiFriend
Messages: 15
Registered: May 2018
Junior Member
It seems that this way it works. Thank you!

index.php/fa/33241/0/

#include <stdio.h>
void FORTE_prova::executeEvent(int pa_nEIID){
  DEVLOG_DEBUG("prova.exeEvent()\n");
  switch(pa_nEIID){
    case scm_nEventREQID:
      CIEC_ARRAY nTest(3, g_nStringIdINT);
      nTest.fromString("[1,2,3]");
      OUTPUT_Array().setValue(nTest);

      char val[10] = "";
      OUTPUT()->toString(val, sizeof(val));
      DEVLOG_DEBUG("OUTPUT is %s\n", val);
      break;
  }
}


index.php/fa/33242/0/
  • Attachment: Capture.PNG
    (Size: 10.04KB, Downloaded 242 times)
  • Attachment: 1.PNG
    (Size: 9.39KB, Downloaded 236 times)

[Updated on: Wed, 27 June 2018 14:49]

Report message to a moderator

Re: Creating an array and giving it as FB output [message #1791291 is a reply to message #1791282] Wed, 27 June 2018 16:55 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1581
Registered: January 2014
Senior Member

Great. Using arrays in 4diac is not as easy as it should be.
Re: Creating an array and giving it as FB output [message #1791342 is a reply to message #1791291] Thu, 28 June 2018 08:56 Go to previous message
Agostino Mascitti is currently offline Agostino MascittiFriend
Messages: 15
Registered: May 2018
Junior Member
We can manage it :)
Previous Topic:Export FB networks, FB interfaces and ECCs as PDF or SVG
Next Topic:Check values of BOOL[16]
Goto Forum:
  


Current Time: Tue Apr 16 06:15:55 GMT 2024

Powered by FUDForum. Page generated in 0.06859 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top