RecordLists

From Compost Wiki
Revision as of 16:51, 6 May 2015 by Jeffm (talk | contribs)
Jump to navigation Jump to search

Named Record Lists

Overview

Named Record Lists are a convenience feature for Compost4 that were added to GibbsCAM 11.3 (11.2.1) to help post developers store, sort, and retrieve data as needed. This type of storage and retrieval is common for posts that need to build up custom lists such as tool and WFO lists.

Records

Records are a data structure that will store list of named values all associated with a single key.

Records can contain any number of named value fields, and be ether numeric (NUM) or boolean (Flag) types.

Keys

The key for a list record is always a number. The records in the list are always stored in ascending order based on the key. This means that when using a record list to sort items, the key defines the sort order.

Names

Each list has it's own name. These names are shared with the legacy Named Maps system. Names are not case sensitive and can be on any length.

Fields also have names. Field names are used only in conjunction with a named list, so multiple lists can have fields with identical names. Field names are also case insensitive and can be of any length.

Iteration

Record lists can be iterated (processed in a loop). This feature is one that was lacking in Named Maps. The EachRecordListItem loop is used to iterate record lists, as shown bellow.

Implementation

Record lists can be implemented in a manner very similar to Named maps

Saving data in a list

To save data in a record list and associate it with a key, the commands SetRecordListFieldNum or SetRecordListFieldBool are used, depending on the type of data the post wishes to store.

 SetRecordListFieldNum('Tools',TLPosition#,'Diam',TLDia#)
 SetRecordListFieldBool('Tools',TLPosition#,'IsMill', TLMillingTool?)

This example will save the current tool diameter and milling state into the record list "Tools", and associated them with the Tool position as it's key.

Retrieving data from a list

To access the data store in a map, by the key, the command GetMap# is used.

 GetRecordListField#('Tools',ToolPostion#,'Diam')

This example would return the diameter value that was associated with the tool position, in this case.

Clearing a map

If the data in the map is not longer needed, or the record list needs to be reused, the post can call the command ClearRecordList to remove all data in the list.

 ClearRecordList('Tools')

If a post needs to just remove a single entry in a record list it can simply call EraseRecordListItem('N',key#). This command only removes fields for the specified key value.

 EraseRecordListItem('Tools',ToolPostion#)

All record lists are cleared at the start of posting.


Value Storage

A common need is for the operations in flow 2 to need to know some information from flow 1. This is often accomplished by using specialized code in the VMM to store values associated with one or more Sync IDs.

This can now be done in compost by simply doing the following;

In flow 1 when the speed is computed.

 SetMap#('SyncSpeedMap') OpStartSync# SpeedRPM#

In flow 2, when the speed is needed,

 GetMap#('SyncSpeedMap') OpStartSync#


This is a much cleaner way then the older variable implementation where conflicts between key names and other variables would require mathematical tricks to work out.

 Save# Add# OpStartSync# Num#('1000') SpeedRPM#

and

 Recall# Add# OpStartSync# Num#('1000')

Sync Usage

Another common use is when a flow needs to know if a sync has been used before or not. This is also very simple with maps.

To mark the Sync As "used" simply attach some known value to the sync ID.

 SetMap#('SyncMap') OpStartSync# Num#('1')


Then later, to test if the sync has been used, simply test

 IF Equal? GetMap#('SyncMap') OpStartSync# Num#('1')

If the sync is not in the map, the command will return 0, and the post can tell that the sync has not be used before.