Resources

All resources must implement the Resource API:

Getting started

All resources are subclasses of the labtronyx.ResourceBase class. Creating a resource is simple:

import labtronyx

class RESOURCE_CLASS_NAME(labtronyx.ResourceBase):
    pass

Attributes

Resources have some attributes that should be defined:

  • interfaceName - str that names the interface that owns the resource. Should match the interfaceName attribute of the corresponding interface.

Errors

Labtronyx has a number of build-in exception types that can be raised from resources. For more information about these exceptions and the proper times to raise them, see Exceptions

Usage Model

When resources are created, they should default to the closed state. This is to prevent any locking issues if multiple instances of Labtronyx are open. Resources should typically only be open if they are actively in use.

When a driver is loaded, the resource object acts as a proxy to access the driver methods. All driver functions are accessed directly from the resource object as if they were a single object. Some things to note:

  • If there is a naming conflict between a method in the resource and a method in the driver, the resource method will take priority
  • Driver functions are inaccessible and cannot be called if the resource is closed

Note

In order to support proper operation using Remote Resources and Instruments, some limitations should be imposed to ensure maximum compatibility. All methods within a resource or driver must return serializable data. Serializable data types include:

  • str
  • unicode
  • int
  • long
  • float
  • bool
  • list
  • tuple
  • dict
  • None

If a method returns an object that is not serializable, an exception will be passed back to the remote host. If the method returns a non-serializable data type, the method should be prefixed with an underscore (‘_’) to mark it as a protected function that cannot be accessed remotely.

Resources may implement more functions than just those which are defined in the API below, see the interface and resource class documentation to learn more.

class labtronyx.bases.resource.ResourceBase(manager, resID, **kwargs)[source]

Resource Base Class. Acts as a proxy for driver if one is loaded.

Parameters:
close()[source]

Close the resource

Returns:True if close was successful, False otherwise
getProperties()[source]

Get the property dictionary for the resource. If a driver is loaded, the driver properties will be merged and returned as well

Return type:dict[str:object]
hasDriver()[source]

Check if the resource has a driver loaded

Returns:bool
isOpen()[source]

Check if the resource is currently open

Returns:bool
loadDriver(driverName, force=False)[source]

Load a Driver for a resource. A driver name can be specified, even if it may not be compatible with this resource. Existing driver is no unloaded unless the force parameter is set to True.

Parameters:
  • driverName (str) – Module name of the desired Model
  • force – Force load driver by unloading existing driver
Returns:

True if successful, False otherwise

Raises:

KeyError if driver class not found

open()[source]

Open the resource. If a driver is loaded, the driver open method will also be called

Returns:True if open was successful, False otherwise
Raises:ResourceUnavailable
unloadDriver()[source]

If a driver is currently loaded for the resource, unload it. This will close the resource as well.

Returns:True if successful, False otherwise
driver
Return type:labtronyx.bases.driver.DriverBase