Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: JeffS on September 01, 2020, 05:52:04 PM

Title: Code Blocks and Memory Pasting
Post by: JeffS on September 01, 2020, 05:52:04 PM
So I have been playing with copying out code blocks from one program and pasting them into another project.  One thing I run into is sometimes user made memory blocks get assigned the wrong index.  In the attached I have 6 memory blocks that I created and they are blocks 234-239. 

Depending on the order that code blocks get pasted into a new project these numbers change.  This causes an issue as it appears that this number is referenced in the code blocks when pasting them in such that if "API" gets pasted into the project before "Nicknames" then "API" will be #235 not #236.  This means when I paste in the blocks containing references to "Nicknames" it now points to "API" and that breaks all manner of things.  In the second picture you can see where I pasted one code block into a new project and now the index started BaleBuffer @ 239 is now NameArrayWrkSpc @ 239.

So far I have just had to be careful to paste my code blocks in the correct order to not break the code.  Is there a better way to handle this?  I figured they all had proper memory block numbers from the original project, but seems these are handed out in a different way when pasting.  Is there a way to export memory configuration so I can import the configuration first so that this isn't an issue?

Along with this, to prevent running over any used memory in an existing program I moved all memory to expanded regions of each built-in memory block.  The problem I run into here is I get an immediate error because the memory is all out of range.  I had thought with the configuration it would automatically expand the existing memory blocks to accommodate the variables used.  This would be another example where exporting a configuration would be handy so I don't have to manually expand all the memory ranges.
Title: Re: Code Blocks and Memory Pasting
Post by: Controls Guy on September 01, 2020, 06:08:52 PM
The memory configuration is exported if you manually do an export or have DMD set to generate one automagically when you save the project.   Here's a copy of one from one of my projects.  Look for a file in your project directory with a name like MyProject_EXPORT_DMD.txt

Code: [Select]
#BEGIN MEM_CONFIG
X BIT decimal 2048 -1
Y BIT decimal 2048 -1
WX SWORD decimal 256 -1
WY SWORD decimal 256 -1
C BIT decimal 2048
V UWORD decimal 4096
N SWORD decimal 4096
D SDWORD decimal 4096
R REAL decimal 4096
T TIMER decimal 256
CT COUNTER decimal 256
SS STRING decimal 128
SL STRING decimal 64
UDT DATETIME decimal 32
PL UWORD decimal 256
DLX BIT octal 01000 -1
DLY BIT octal 01000 -1
DLC BIT octal 01000
DLV UWORD octal 04000
MI BIT decimal 1024
MC BIT decimal 1024
MIR SWORD decimal 2048
MHR SWORD decimal 10000
Drum SDWORD decimal 3000
RelayLocation UWORD decimal 256
RelayFrontDel SWORD decimal 256
RelayBackDel SWORD decimal 256
RelayLookBack SWORD decimal 256
RelayWDCfg BIT decimal 256
RelayFlashCfg BIT decimal 256
RelayPanicCfg BIT decimal 256
WashPkgCfgA SDWORD decimal 256
RelayType SDWORD decimal 256
TODOutputs BIT decimal 256
RelayOrideCfg BIT decimal 256
RelayTypeTire BIT decimal 256
RelayTypeTOD BIT decimal 256
RelayAutoMode BIT decimal 256
RelayManOn BIT decimal 256
RelayTypDuration BIT decimal 256
RelayWinMinCar BIT decimal 256
RelayTypeESign BIT decimal 256
ESignOutputs BIT decimal 256
AlarmMsg STRING320 decimal 64
ActiveAlarm STRING256 decimal 5
DrumA SDWORD decimal 3000
CustomWP BIT decimal 256
LastCustomWP BIT decimal 256
Overrides BIT decimal 256
WashPkgCfgB SDWORD decimal 256
WashPkgCfgC SDWORD decimal 256
WashPkgCfgD SDWORD decimal 256
AlarmTime DATETIME decimal 10
LoopIndex UWORD decimal 64
AlarmExp STRING256 decimal 64
Report STRING1024 decimal 4
EmailAddrList STRING1024 decimal 16
Diag SDWORD decimal 256
RX REAL decimal 256 -1
RY REAL decimal 256 -1
DrumB SDWORD decimal 3000
DrumC SDWORD decimal 3000
POSORidePtrs UBYTE decimal 256
POSBtnLatch BIT decimal 256
POSButtons BIT decimal 256
POSAlaCartePTRs UBYTE decimal 256
POSRetractPTRs UBYTE decimal 256
RelayTBDCfg BIT decimal 256
MSG STRING 0
ERR STRING 0
SysName STRING 0
SysDesc STRING 0
SerialNum STRING 0
PartNum STRING 0
EntEyeFront PROGRAM 0 -1
EntEyeRear PROGRAM 0 -1
WashID PROGRAM 0 -1
HMI PROGRAM 0 -1
Misc PROGRAM 0 -1
TireEyeFront PROGRAM 0 -1
TireEyeRear PROGRAM 0 -1
TimeOfDay PROGRAM 0 -1
RelayData TASK 0 -1
WPData TASK 0 -1
ForceData PROGRAM 0 -1
EMail PROGRAM 0 -1
EntEyeTrig PROGRAM 0 -1
Alarms PROGRAM 0
ESign PROGRAM 0 -1
zInspectDrum PROGRAM 0 -1
Daily PROGRAM 0 -1
EMailData TASK 0 -1
DrumCensus PROGRAM 0
EthernetPOS PROGRAM 0 -1
TruckBed_Scanner PROGRAM 0
#END
Title: Re: Code Blocks and Memory Pasting
Post by: JeffS on September 01, 2020, 07:21:56 PM
How do I import that?  Just copy paste?
Title: Re: Code Blocks and Memory Pasting
Post by: Controls Guy on September 01, 2020, 07:36:16 PM
Someone from Host will have to answer, given that there's some non human-readable stuff in the export file, but it might be as simple as pasting the lines for the desired new memory blocks into an export of the target program, then re-importing or importing into a new project.
Title: Re: Code Blocks and Memory Pasting
Post by: franji1 on September 01, 2020, 09:13:38 PM
Some issues:

Block numbers are not assignable directly by the user.  We could provide a facility for that after any paste or import or merging.  There's a couple scenarios where these need to be static across multiple projects (consistent RX/WX of user blocks between multiple PLCs and 2D arrays).

In the mean time, I recommend creating a "template" system configuration that defines all your blocks that you need fixed (we do this for our automated testing).  Export that and then use that as THE template for all new projects.  You don't actually have to use export, just make a read-only project file that you always open first, then do a Save-As to a different .dmd file and edit THAT one.  Remove any unneeded data blocks based on what you end up with.

Until there is a facility to let you manually tweak the data block #'s, Paste cannot do what you want since the Destination project is "boss" (e.g. destination already has a user data block at #239, and the clipboard has a completely different data block at #239 - you have to resolve that some way, hence the need for the facility).
Title: Re: Code Blocks and Memory Pasting
Post by: JeffS on September 02, 2020, 09:19:30 AM
OK, one last question.  Any reason pasted memory blocks start at 239?  In my original project the memory blocks that would be pasted are #32-38 but when I paste into a new project the first memory block starts at #239 and additional blocks count backwards.
Title: Re: Code Blocks and Memory Pasting
Post by: franji1 on September 02, 2020, 09:23:09 AM
Paste uses a different API to add new blocks.  One goes up from 32, the other goes down from 239.  Paste uses the latter.