msl.equipment.config module

Load an XML Configuration File.

class msl.equipment.config.Config(path)[source]

Bases: object

Load an XML Configuration File.

This function is used to set the configuration constants to use for the Python runtime and it allows you to access EquipmentRecord’s from an Equipment-Register Database and ConnectionRecord’s from a Connections Database.

The following table summarizes the XML elements that are used by MSL-Equipment and can be defined in a Configuration File:

XML Tag

Example Values

Description

pyvisa_library

@ivi, @py, @sim, /path/to/libvisa.so.7

The PyVISA library to use.

demo_mode

true, false, True, False

Whether to open connections in demo mode.

path

/path/to/SDKs, D:/images

A path that contains external resources. Accepts a recursive=”true” attribute. The path(s) are appended to os.environ['PATH'] and to PATH

The user is also encouraged to define their own application-specific elements within the Configuration File.

Parameters:

path (str) – The path to an XML Configuration File.

Raises:

OSError – If path does not exist or if the Configuration File is invalid.

PyVISA_LIBRARY = '@ivi'

The PyVISA backend library to use.

Type:

str

DEMO_MODE = False

Whether to open connections in demo mode.

If enabled then the equipment does not need to be physically connected to a computer and the connection is simulated.

Type:

bool

PATH = []

Paths are also appended to os.environ['PATH'].

Type:

list of str

property path

The path to the configuration file.

Type:

str

property root

Returns the root element (the first node) of the XML tree.

Returns:

Element – The root element.

database()[source]
Returns:

Database – A reference to the equipment and connection records in the database(s) that are specified in the configuration file.

value(tag, default=None)[source]

Gets the value associated with the specified tag in the configuration file.

The first element with name tag (relative to the root) is used.

The value is converted to the appropriate data type if possible. Otherwise, the value will be returned as a str.

Parameters:
  • tag (str) – The name of an XML tag in the configuration file.

  • default – The default value if tag cannot be found.

Returns:

The value associated with tag or default if the tag cannot be found.

find(tag)[source]

Find the first sub-element (from the root) matching tag in the configuration file.

Parameters:

tag (str) – The name of an XML tag in the configuration file.

Returns:

Element or None – The first sub-element or None if the tag cannot be found.

findall(tag)[source]

Find all matching sub-elements (from the root) matching tag in the configuration file.

Parameters:

tag (str) – The name of an XML tag in the configuration file.

Returns:

list of Element – All matching elements in document order.

attrib(tag)[source]

Get the attributes of an Element in the configuration file.

The first element with name tag (relative to the root) is used.

The values are converted to the appropriate data type if possible. Otherwise, the value will be kept as a str.

Parameters:

tag (str) – The name of an XML element in the configuration file.

Returns:

dict – The attributes of the Element. If an element with the name tag does not exist, then an empty dict is returned.