ResourceStore

dabs.resources.ResourceStore is a singleton holding every instantiated resource in the MATLAB process. Constructing it returns the existing instance, so it is safe - and normal - to call the constructor wherever you need it.

hRS = dabs.resources.ResourceStore();

The store is what makes ScanImage’s configuration by name work: the machine data file refers to devices and terminals by name, and every property setter that takes a device resolves that name through the store.


Properties

Property

Description

hResources

Cell array of every registered resource. Observable.

names

The corresponding names. Not observable - listen to hResources instead.

hSystemTimer

Shared timer that emits periodic beacons. Devices use it for background polling; the PMT base class, for example, queries status on beacon_1Hz.

The resourcesChanged event fires when resources are added or removed.


Finding resources

Method

Description

[v,valid] = hRS.filterByName(name)

Look up one resource by name. Accepts a char array, a cell array of names, or a resource (returned unchanged). An unresolved name yields an empty dabs.resources.InvalidResource and valid = false rather than an error.

[v,names] = hRS.filterByClass(classNames)

Every resource that is an instance of the given class or classes. Accepts a class name, a meta.class, an object, or a cell array of any of these. Backed by a cached superclass map, so it is fast enough to call in a loop.

[v,names] = hRS.filter(filterFcn)

Every resource for which filterFcn(hResource) is true.

[v,names] = hRS.filterReserved()

Every resource currently reserved.

[v,names] = hRS.filterUsed()

Every resource with registered users.

Static convenience forms exist for all three main filters, so you do not have to construct the store first:

h  = dabs.resources.ResourceStore.filterByNameStatic('vDAQ0');
hs = dabs.resources.ResourceStore.filterByClassStatic('dabs.resources.devices.PMT');
hs = dabs.resources.ResourceStore.filterStatic(@(h)~isempty(h.errorMsg));
% which devices are in an error state?
hRS = dabs.resources.ResourceStore();
hBad = hRS.filter(@(h)~isempty(h.errorMsg));
cellfun(@(h)fprintf('%s: %s\n',h.name,h.errorMsg),hBad);

% every motor controller on the system
hMotors = hRS.filterByClass('dabs.resources.devices.MotorController');

Note

filterByClass returns a cell array, filterByName returns a scalar resource for a char argument. Mixing the two up is the most common mistake when scripting against the store.


System level operations

Method

Description

dabs.resources.ResourceStore.scanSystem()

Rescan the system for DAQ hardware, serial ports and VISA instruments.

dabs.resources.ResourceStore.scanSystemQuick()

Refresh only the VISA instruments and COM ports.

dabs.resources.ResourceStore.instantiateFromMdf(mdfPath,hWaitbar)

Construct every resource declared in a machine data file.

dabs.resources.ResourceStore.showConfig()

Open the resource configuration editor.

dabs.resources.ResourceStore.showWidgetBar()

Open the widget bar.

dabs.resources.ResourceStore.clear()

Delete every resource and reset the store.

dabs.resources.ResourceStore.isInstantiated()

Whether the singleton exists yet.

Warning

clear() deletes every device object in the process, including the ones ScanImage is using. It is a teardown operation, not a refresh - use scanSystem to pick up newly connected hardware.


Display

The store implements a custom display, so simply evaluating it in the command window prints a readable inventory of the system:

>> dabs.resources.ResourceStore()