What kind of variable to use to change a port reference?

Do you have a question on how to do something.
Ask in here.
Post Reply
gaberosenfield
Posts: 89
Joined: Thu Mar 08, 2012 5:11 pm
Location: Redwood City, California

What kind of variable to use to change a port reference?

Post by gaberosenfield »

Hi RA users and admins,

I am in the process of writing code to control my new setup, in which automation is the name of the game. I am programming in an "acclimation mode" as an option that I can turn on when I want to drip acclimate a new arrival. Basically, all that will change during acclimation mode is that instead of my ATO pumping in RODI water when the low float switch in my sump is triggered, my automatic water change pump will pump in saltwater to replace the water lost from my main system that is dripping into my acclimation tank. I already know how to use the #define command, but this can only be run once when the code is loaded. What I want to know is what kind of variable I can use to refer to a certain port that can be changed while my program is running. Will a string work? I want to be able to do something like this:

Code: Select all

#define AWCFillPump Box1_Port2
#define ATOPump Box1_Port3

boolean acclimationMode = false;

int ATOTimeOut = 300;  //ATO timeout in seconds

string fillPump = ATOPump;

if (acclimationMode == true)
{
  ATOTimeOut = 60;
  
  fillPump = AWCFillPump;
}

if(acclimationMode == false)
{
  ATOTimeOut = 300;

  fillPump = ATOPump;
}

ReefAngel.StandardATO(fillPump, ATOTimeOut);
Will the above code work? Or is there any other variable type that can make it work? Or, if not, is there another way I can accomplish the same thing?

Thanks in advance!
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: What kind of variable to use to change a port reference?

Post by lnevo »

Ports are bytes. Just change it to a byte and you can do

byte fillPump = ATOPump;
gaberosenfield
Posts: 89
Joined: Thu Mar 08, 2012 5:11 pm
Location: Redwood City, California

Re: What kind of variable to use to change a port reference?

Post by gaberosenfield »

Exactly what I wanted to know. Thanks Inevo!
Post Reply