I am having an issue with setting the portion size of a valve during run time. It appears to always take the values placed in the 'Properties' input boxes as its first/initial portion size. I want to have this value read in from a database during start up (ie. In Main > On Start up).
Attempt 1
If I assign the value that I read in from the database to a variable "parcel_size" and I place the variable name "parcel_size" in the PortionSize input, it tells be that the PortionSize cannot be zero. I assume that means it is trying to assign the value before I read it in from the database. If I give the varaible "parcel_size" a default value, it just takes that value as the first Portion Size.
Attempt 2
I also tried putting in a numerical value in the PortionSize input and then assigning a value during Main > On Start up using:
valve.set_portionSize(parcel_size, TON);
While this successfully assigns the subsequent portion sizes, it still takes the initial numerical value as the initial PortionSize.
I thought it may be possible bypass this issue by setting a very small value as the initial portion size - however it does not work for me as my action is also dependent on the "parcel_size":
valve2.dispense(parcel_size, TON);
So what would happen is that it will trigger dispensing the 'parcel_size' amount but when portion_size passed on valve is small. I need these to be the same amount.
Attempt 3
I then tried un-checking the "Recurrent action on portion" box first and then putting the following code in Main > Startup:
valve.set_portionSize(parcel_size, TON);
valve.actionOnPortion = true;
However this gives me an error of "Volume and mass parameters are incompatible"
Changing the code using cubic meter does not help:
valve.set_portionSize(parcel_size, CUBIC_METER);
valve.actionOnPortion = true;
Is there a way around this?
Can anyone suggest a way around this?
Sorry for the long post, but hope that it has explained my problem properly.
To set this from the DB you need to have code like the following for the value
I tested this and it worked.
Since the parameter is a static parameter - which you can see when you hover the little icon next to the parameter
This means that this value is evaluated once, during creation and never again.
If you want to change during runtime you will need to call valve.set_portionSize(value)
if you want to change the value during model execution.
See below