You are not logged in.
Pages: 1
Topic closed
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
this is the script of a REXLANG fuction blok
Offline
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
Thanks it work
Offline
Glad I could help. Good luck with your project!
Cheers, Tomas
Offline
Pages: 1
Topic closed