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 |
|---|---|
|
Cell array of every registered resource. Observable. |
|
The corresponding names. Not observable - listen to |
|
Shared timer that emits periodic beacons. Devices use it for background polling; the
PMT base class, for example, queries status on |
The resourcesChanged event fires when resources are added or removed.
Finding resources
Method |
Description |
|---|---|
|
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
|
|
Every resource that is an instance of the given class or classes. Accepts a class
name, a |
|
Every resource for which |
|
Every resource currently reserved. |
|
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 |
|---|---|
|
Rescan the system for DAQ hardware, serial ports and VISA instruments. |
|
Refresh only the VISA instruments and COM ports. |
|
Construct every resource declared in a machine data file. |
|
Open the resource configuration editor. |
|
Open the widget bar. |
|
Delete every resource and reset the store. |
|
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()