Announcement

REXYGEN forum has been moved. This one is closed.
Head over to the new REXYGEN Community Forum at https://forum.rexygen.com.

Looking forward to meeting you there!
 

#1 2016-06-24 15:57:39

martijnperdaan
Member
Registered: 2016-06-24
Posts: 20

what am I doing wrong

in the script below i want toe calculate sum1 but when i want to (value * weerfactor) divide by value 12 it does not work
but when i (value * weerfactor) + value 12 is works

can someone tell me wat i am doing wrong ?


/***************************************
*
* Minimal REXLANG example
*
****************************************/   

//assigning inputs to variables, these variables are READ-ONLY
long input(0) value1; //mav ventilatie
double input(1) value2; // buitentemp
double input(2) value3; //mintemplaag
double input(3) value4; //mintemphoog
double input(4) value5; //mintempvermenigvuldigen
double input(5) value6; //gemiddeldtemplaag
double input(6) value7; //gemiddeldtemphoog
double input(7) value8; //gemiddeldtempvermenigvuldigen
double input(8) value9; //maxtemplaag
double input(9) value10; //maxtemphoog
double input(10) value11; //maxtempvermenigvuldigen
long input(11) value12; //bandbreete
double input(12) value13; //tempstal
long input(13) value14; //streeftemp
long input(14) value15; // min ventilatie



//assigning variables to outputs, these variables are WRITE-ONLY
double output(2) sum1;
double output(3) weerfactor;

//the init procedure is executed once when the REXLANG function block initializes
long init(void)
{
  return 0;
}

//the main procedure is executed once in each sampling period
long main(void)
{
 
  if (value2 >= value3)
  {
    if (value2 <= value4)
        {
        weerfactor = value5;
        }
  }
 
  if (value2 >= value6)
  {
    if (value2 <= value7)
        {
        weerfactor = value8;
        }
  }
 
  if (value2 >= value9)
  {
    if (value2 <= value10)
        {
        weerfactor = value11;
        }
  }
 
  sum1 = (value1 * weerfactor) / value12;
  return 0;
}

//the exit procedure is executed once when the task is correctly terminated
// (system shutdown, downloading new control algorithm, etc.)
long exit(void)
{
  return 0;
}

Offline

#2 2016-06-24 15:58:40

martijnperdaan
Member
Registered: 2016-06-24
Posts: 20

Re: what am I doing wrong

this is the script of a REXLANG fuction blok

Offline

#3 2016-06-24 22:39:50

tomáš čechura
Administrator
Registered: 2016-02-22
Posts: 371

Re: what am I doing wrong

Hi martijnperdaan,

I tried to run your REXLANG script and it works for me. However when the value12 is zero the REXLANG block sets iE output to"-501: Division by zero" and the sum1 is set to zero as well. This can be the reason why the approach with "+ value12" instead of division works.

You need to ensure that the value12 input is non-zero. This can be done by adding one more if statement in your code:

if (value12 != 0)
{
  sum1 = (value1 * weerfactor) / value12;
} 

I hope the above is useful to you.

Regards, Tomas

Offline

#4 2016-06-25 11:06:25

martijnperdaan
Member
Registered: 2016-06-24
Posts: 20

Re: what am I doing wrong

Thanks it work

Offline

#5 2016-06-25 12:18:28

tomáš čechura
Administrator
Registered: 2016-02-22
Posts: 371

Re: what am I doing wrong

Glad I could help. Good luck with your project!

Cheers, Tomas

Offline

Board footer

Powered by FluxBB