How to pass array as parameter to macro

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

How to pass array as parameter to macro

Postby Steven_SS » Tue Oct 16, 2018 3:32 pm

Hello!
I need help on passing an array as a parameter. It seems real simple, but I can't figure it out on flowcode at the moment. The array is set as a global byte msg[255].
I have one call needing to go as "crc_out(msg[], timeout, true)" but I cant get the array(msg[]) to pass.

Then the next should go as "crc = CalcCRC(msg_len + 2, &msg[1])" but the "&msg[1]" wont go through. Neither would "msg[1]" if I tried.
And finally, the CalcCRC macro should read in those parameters as "crc = CalcCRC(LEN, *u8Buf)".

How can I make flowcode macros understand passing arrays or address/pointer of arrays through?? Please help and thank you in advance.
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

User avatar
Benj
Matrix Staff
Posts: 14671
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4655 times
Been thanked: 4280 times
Contact:

Re: How to pass array as parameter to macro

Postby Benj » Tue Oct 16, 2018 4:56 pm

Hello,

Here's an example.
ArrayDemo.fcfx
(6.37 KiB) Downloaded 77 times


If you're still having trouble then please post what you have so far then we might be able to help directly with your project file.
These users thanked the author Benj for the post:
Steven_SS (Tue Oct 16, 2018 5:11 pm)
Rating: 5%
 

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

Re: How to pass array as parameter to macro

Postby Steven_SS » Tue Oct 16, 2018 5:13 pm

Thank you! That does help, but not quite. I'll send the project over in a private message.
Thanks again Benj!

-Steven
These users thanked the author Steven_SS for the post:
Benj (Tue Oct 16, 2018 5:28 pm)
Rating: 5%
 
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven

User avatar
Benj
Matrix Staff
Posts: 14671
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4655 times
Been thanked: 4280 times
Contact:

Re: How to pass array as parameter to macro

Postby Benj » Tue Oct 16, 2018 5:23 pm

I think I see what you need you're trying to pass a sub part of an array.

Flowcode won't currently let you do this so you might have to do it like this.

CalcCRC(MsgLength, DataArray, ArrayOffset)

The ArrayOffset basically tells you to start from location 1 of the data array.


Arduino uses arrays all over the place to work with their C++ philosophy and avoid variable naming clashes when using multiple instances of a library.

With Flowcode you can simply have a global array and access this globally, this will significantly cut down on all the overhead of passing arrays around as parameters. Flowcode components allow the variable to get intelligently renamed so there won't be a clash. Therefore Arduino hacks are not required in Flowcode. Whenever I'm porting an Arduino library to a Flowcode component I get rid of any arrays as parameters and simply have a global array. This also gets away from the user having to create the unique array to drive the component, the variables required by the component are supplied by the component.

Steven_SS
Posts: 46
Joined: Wed Jul 18, 2018 6:33 pm
Has thanked: 18 times
Been thanked: 3 times
Contact:

Re: How to pass array as parameter to macro

Postby Steven_SS » Tue Oct 16, 2018 5:48 pm

I definitely understand that Benj! We just figured that out as well. So that gets rid of the first issue. Thank you on that. I believe the 2 & 3 go together with address/pointer.
I'm just trying to keep learning & growing in a infinite loop... unless I wanna break. Cheers :)
Steven