
DoLessDesigner (Customer) asked a question.
How to index a memory block in Do-More?
I am new to Do-More Designer. I created a memory block structure to act as a stand-in for arrays from high-level programming languages. I can index it manually by say, calling index 5, but I would like to index it dynamically by say, calling index D0 (to obtain whatever value is at the index that D0 is at: if D0 is 5, it obtains Array[5], and if D0 is 16, it obtains Array[16]). Is it possible to do this in Do-More without manually writing a ton of "if" rungs?
Definitely. You can use V registers (unsigned WORD 0-65535) as the index to ANY block (predefined, user) and use it in Ladder. It even works via communications (but not for intra-scan status).
Array[V42] where V42 equals 5, will return Array5.
You can also do integer constant offsets of 1..63, so
Array[V42+7] where V42 equals 5, will return Array12
The MATH instruction supports FULL EXPRESSIONs for both the RESULT parameter, along with ANY block reference in the EXPRESSION parameter (and even NEST array indexes).
R[SQRT(V42) * D17] + 100.0
or
R[D[V[N13 * 17] + 4] + (100 * D2)] / 1.7
So a Data View could have
R[V42]
and
V42
Just tweak the value of V42 in your Data View and you will get the R[V42] value of whatever is in V42. Realize Comm only gets done at the bottom of the PLC scan, so whatever value is in V42 when that comm is processed, that's what you will see for R[V42]. So you can't really do INTRA-scan array index status via comm, but definitely "bottom of scan" array index status will work!.
You have selected the right PLC, in my opinion. The BRX Do-more has many powerful instructions, including the type you are asking about. I am not sure what you are trying to accomplish, but.
Look at:
There are many other instructions and functions. The Help topics are very thorough.
BUT, many times the PLC has an "more direct" PLC-style of programming to accomplish a task than trying to reproduce a "high-level" computer-style of programming. Arrays and indirect addressing are "powerful", but makes it harder to monitor and trouble-shoot, especially if someone else will be trying to monitor and trouble-shoot. What do you want to accomplish in a more zoom-out, plain-English wording, and less high-level programming wording.
You might also need to utilize "casts" to look at a bit of word or a set of bits as a 16 bit register or...
This video helps explain casting in Do-more
BRX Do-more Designer Casting at AutomationDirect
Casting also works in Communications, not just in logic. So you can look at the 3rd bit in V42 as V42:2 (V42:0 is the first bit)