variable input-, or output port

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

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

variable input-, or output port

Post by Jan Lichtenbelt »

I want to change the port by the flowcode software.

In this example here, for port A. The port number will be determined by the software variable APort.
E.g. value 1 as output to APort. In C-code this will become:
FCP_Set(B, A, 1<<FCV_APort, FCV_Aport, (1));
And input to variable AIn:
FCL_Ain= FCP_Get(B, A, 1<<FCV_APort, FCV_Aport);

Is this correct? Is there an easier way?

By the way, what is B in FCP_Set(B.... and FCP_Get(B....

Kind regards

Jan Lichtenbelt

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

Re: variable input-, or output port

Post by Benj »

Hi Jan,

The easiest way to allow for a dynamic port is using a property. This can be made to be a single digital pin, a digital port or an analogue pin. This is one of the corner stones of component creation.

Here is how to create a property.

https://www.flowcode.co.uk/wikiv7/index. ... a_Property

Then in a calculation icon you can refer to the property variable, for example propvar.

To write a value to the port/pin.
propvar = 0

To read a value from the port/pin.
flowcodevar = propvar

This will then also simulate.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: variable input-, or output port

Post by Jan Lichtenbelt »

Hi Ben

Thanks for your answer.
The easiest way to allow for a dynamic port is using a property.
I'm afraid that is not the easiest way for me. It looks complicated to me. But be never to old to learn something new. I will try.

But does it mean that my C-code solution is not correct?

Kind regards

Jan

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: variable input-, or output port

Post by LeighM »

Hi Jan

Your question about the "B", this ensures that the C "Bit" macro is used.

Your C code will work, but only for a variable pin in a fixed port.
But it's probably not a good idea to use our internal macros like that as they might change.

Using a property to define the port and pin at compile time as Ben suggests is the best way,
unless the question is that you need to change the port and pin based on a variable that can change at run time?

If that is the case, then maybe you could write a function, aka Flowcode macro, say GetInput(x)
that takes a variable as a parameter, then in the GetInput() macro you use a switch to read the port/pin required for that variable value.
Similar for output, SetOutput(x, value)

If all the inputs are on the same port, then it would be easier just to read the port then mask the pin that you want.

All depends on exactly what you are trying to do.
But hope that helps.

Post Reply