Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bolt on December 16, 2020, 03:49:30 PM
-
I'm trying to do something that makes sense in my head, I just can't quite figure it out in DmD. I hope my explanation here makes sense.
I have a FOR/NEXT loop (V0, 0-4) controlling five Units, through a UDT called Unit. When "lead unit on" criteria is met, Unit[V0] is controlled, turned on, etc, say Unit2. Then when "lag unit on" criteria is met, it controls another unit, say Unit3. That all works fine for me.
I would then like to log the data into a UDT called History0-511. I thought I might do this by incrementing a pointer (0-511), and storing that value in V0+10, or V10..V14, corresponding to the five Units. Then, when Unit2 changes a state, I need to copy a start time, stop time, count, error bit, etc to the corresponding field in History[V12]. How do I link my control loop, with V0, to the corresponding V10..V14 range? Like copy to History[V[V0+10]], which isn't allowed. What's a clean work around?
-
If you are sure History[V[V0+10]] is the calculation, use a MATH box. It takes expressions for array indexes for both the Result AND the Expression parameters
-
If you are sure History[V[V0+10]] is the calculation, use a MATH box. It takes expressions for array indexes for both the Result AND the Expression parameters
Exactly what I needed, thank you!
-
Exactly what I needed, thank you!
Funny, when we implemented full expression array indexing inside the MATH box, I never thought about using it this way, but array referencing is just an expression in a MATH box.
So, technically, you do not even have to store your indexes inside a V block, but you could create a separate block called HI (History Index) as UNSIGNED WORD that is 10 long (or however long your history needs to be), and use THAT. One caveat, if you ever need to use one of those HI indexes outside of a MATH box, just do a MOVE HI[V7] V42 to another V (e.g. V42), then use V42 as a true array index inside the non-MATH box.
-
So, technically, you do not even have to store your indexes inside a V block...
Nice, I hadn't thought of that. I can create a field called Unit.HistoryIndex, and put the corresponding references in there, and just call that as index in the MATH result line. Will make the code clearer as to where the data is being put. Thanks for the tips! Please excuse me while I go Do-more!