Nathanael,
You have figured out about the same solution to handling arrays of structures in TBASIC as I did. So I may not be able to reduce the number of define table entries that you desire.
My approach is slightly different. This is an exert from the #Define table for a single structure. My application has an array of 8 of these structures
# #Define Name Value
45 FillerArrayBase 1
46 FillerArraySize 10
47 FillerStatus DM32[y+0]
48 FillerCapacity DM32[y+1]
49 FillerVolume DM32[y+2]
50 FillerUllage DM32[y+3]
51 FillerDvDt DM32[y+4]
52 FillerTtlDvDt DM32[y+5]
53 FillerBOL DM32[y+6]
54 FillerDeliveryVol DM32[y+7]
55 Delivered DM32[y+8]
56 FillerReserved09 DM32[y+9]
FillerArrayBase is the index into DM32[] for the first entry of the first data structure.
FillerArraySize is the size of the data structure in 32-bit words.
There are 8 of these structures in the array. The maximum number of structures is defined as MaxFillerN. This allows me to change the size
of the array without having to change any of the CFs that act on the array of structures (there are no hard-coded values in my code for this sort of thing).
What I do differently that you is the computation of the index into DM32[] to access a individual member of a structure. I compute the index to the the first member
of the structure that I am interested in and assign this to the variable "y". This keeps me from making simple mistakes in my coding that will be hard to find during debug.
The variable "y" is set to the starting address of of the "current" data structure once on each loop through the for..next structure.
' UpdateStatus - Now that all of the tank measurements have been made,
' this function will update the filler status information for each filler.
'
for FillerIndex = 0 to MaxFillerN ' for each fill point
' The variable, "y", is the index into the array of data structures that
' represent the state of an individual filler.
'
y = FillerArrayBase + FillerIndex * FillerArraySize
' a mountain of code was deleted out of this function. The missing code
' assigned values to the XXXXTemp variables based on the state of 16
' fuel tanks that may be connected to the system. the XXXXTemp variables
' are defined as locations in DM32[] with the #Define mechanism.
'
FillerStatus = StatusTemp
FillerVolume = VolumeTemp
FillerUllage = UllageTemp
FillerDvDt = DvDtTemp
FillerTtlDvDt = TotalizerDvDtTemp
FillerCapacity = CapacityTemp
next ' FillerIndex (next filler)
OK. What might I suggest that you do to cut down on the number of #Define entries? It sort of depends on how you have structured your program.
If you have 5 different recipes, do you save all five in the EEP? As you appear to be using a Fx or Tile-based PLC you may have as much as 11K 16-bit words of EEP that you can store the recipes. If this is true, then you only need to access the current active recipe. You could copy the active recipe into a fixed location in DM32[] or you could access the EEP for the active recipe directly. Load_EEP32[(y+n)] ... where y is that stating index into EEP32 for the active structure and n is the offset within the array.
Another thing that you could do to simplify your life is to store all of the data in the same place. I notice that you have some 32-bit float values and some 32-bit integer values. If you have only a few float values you could:
1. Convert them to scaled integers and save them in DM32[]. Lets say that the float value is 32.467 and your system only needs the number to be accurate to +/-0.1 then save the float DM32[n] = round(32.467,1) * 10 This is a scaled integer. When you need to use it covert it to what ever units your system actually uses.
2. Save the float value DM32 as a bit pattern. DM32[n] = Float2Bits(32.467). When you need to use the value as a float convert it back BitsFloat(DM32[n]).
By not having to split your recipes between DM32[] and FP[] might make your life a bit simpler(
).
Oh, and you can delete all uses of "THEN" from your if..else statements. "THEN" is purely optional and is purely useless. Won't save you any execution time or reduce the number of #defines but it might make your .PC7 files a few bytes smaller.
Best regards,
Gary Dickinson