leicacam package¶
Control Leica microscopes with python.
- class leicacam.CAM(*args, **kwargs)[source]¶
Bases:
BaseCAM
Driver for LASAF Computer Assisted Microscopy.
- load_template(filename='{ScanningTemplate}leicacam.xml')[source]¶
Load scanning template from filename.
Template needs to exist in database, otherwise it will not load.
- Parameters:
filename (str) – Filename to template to load. Filename may contain path also, in such case, the basename will be used. ‘.xml’ will be stripped from the filename if it exists because of a bug; LASAF implicit add ‘.xml’. If ‘{ScanningTemplate}’ is omitted, it will be added.
- Returns:
Response from LASAF in an ordered dict.
- Return type:
collections.OrderedDict
Example
>>> # load {ScanningTemplate}leicacam.xml >>> cam.load_template('leicacam') >>> # load {ScanningTemplate}leicacam.xml >>> cam.load_template('{ScanningTemplate}leicacam') >>> # load {ScanningTemplate}leicacam.xml >>> cam.load_template('/path/to/{ScanningTemplate}leicacam.xml')
- save_template(filename='{ScanningTemplate}leicacam.xml')[source]¶
Save scanning template to filename.
- send(commands)[source]¶
Send commands to LASAF through CAM-socket.
- Parameters:
commands (list of tuples or bytes string) – Commands as a list of tuples or a bytes string. cam.prefix is allways prepended before sending.
- Returns:
Bytes sent.
- Return type:
int
Example
>>> # send list of tuples >>> cam.send([('cmd', 'enableall'), ('value', 'true')]) >>> # send bytes string >>> cam.send(b'/cmd:enableall /value:true')
- wait_for(cmd, value=None, timeout=60)[source]¶
Hang until command is received.
If value is supplied, it will hang until
cmd:value
is received.- Parameters:
cmd (string) – Command to wait for in bytestring from microscope CAM interface. If
value
is falsy, value of received command does not matter.value (string) – Wait until
cmd:value
is received.timeout (int) – Minutes to wait for command. If timeout is reached, an empty OrderedDict will be returned.
- Returns:
Last received messsage or empty message if timeout is reached.
- Return type:
collections.OrderedDict
Submodules¶
leicacam.async_cam module¶
Provide an interface using asyncio to the CAM server.
- class leicacam.async_cam.AsyncCAM(*args, **kwargs)[source]¶
Bases:
BaseCAM
Driver for LASAF Computer Assisted Microscopy using asyncio.
- async send(commands)[source]¶
Send commands to LASAF through CAM-socket.
- Parameters:
commands (list of tuples or bytes string) – Commands as a list of tuples or a bytes string. cam.prefix is allways prepended before sending.
- Returns:
Bytes sent.
- Return type:
int
Example
>>> # send list of tuples >>> await cam.send([('cmd', 'enableall'), ('value', 'true')]) >>> # send bytes string >>> await cam.send(b'/cmd:enableall /value:true')
- async wait_for(cmd, value=None, timeout=60)[source]¶
Hang until command is received.
If value is supplied, it will hang until
cmd:value
is received.- Parameters:
cmd (string) – Command to wait for in bytestring from microscope CAM interface. If
value
is falsy, value of received command does not matter.value (string) – Wait until
cmd:value
is received.timeout (int) – Minutes to wait for command. If timeout is reached, an empty OrderedDict will be returned.
- Returns:
Last received messsage or empty message if timeout is reached.
- Return type:
collections.OrderedDict
leicacam.cam module¶
Provide an interface to the CAM server.
- class leicacam.cam.BaseCAM(host='127.0.0.1', port=8895)[source]¶
Bases:
object
Base driver for LASAF Computer Assisted Microscopy.
- class leicacam.cam.CAM(*args, **kwargs)[source]¶
Bases:
BaseCAM
Driver for LASAF Computer Assisted Microscopy.
- load_template(filename='{ScanningTemplate}leicacam.xml')[source]¶
Load scanning template from filename.
Template needs to exist in database, otherwise it will not load.
- Parameters:
filename (str) – Filename to template to load. Filename may contain path also, in such case, the basename will be used. ‘.xml’ will be stripped from the filename if it exists because of a bug; LASAF implicit add ‘.xml’. If ‘{ScanningTemplate}’ is omitted, it will be added.
- Returns:
Response from LASAF in an ordered dict.
- Return type:
collections.OrderedDict
Example
>>> # load {ScanningTemplate}leicacam.xml >>> cam.load_template('leicacam') >>> # load {ScanningTemplate}leicacam.xml >>> cam.load_template('{ScanningTemplate}leicacam') >>> # load {ScanningTemplate}leicacam.xml >>> cam.load_template('/path/to/{ScanningTemplate}leicacam.xml')
- save_template(filename='{ScanningTemplate}leicacam.xml')[source]¶
Save scanning template to filename.
- send(commands)[source]¶
Send commands to LASAF through CAM-socket.
- Parameters:
commands (list of tuples or bytes string) – Commands as a list of tuples or a bytes string. cam.prefix is allways prepended before sending.
- Returns:
Bytes sent.
- Return type:
int
Example
>>> # send list of tuples >>> cam.send([('cmd', 'enableall'), ('value', 'true')]) >>> # send bytes string >>> cam.send(b'/cmd:enableall /value:true')
- wait_for(cmd, value=None, timeout=60)[source]¶
Hang until command is received.
If value is supplied, it will hang until
cmd:value
is received.- Parameters:
cmd (string) – Command to wait for in bytestring from microscope CAM interface. If
value
is falsy, value of received command does not matter.value (string) – Wait until
cmd:value
is received.timeout (int) – Minutes to wait for command. If timeout is reached, an empty OrderedDict will be returned.
- Returns:
Last received messsage or empty message if timeout is reached.
- Return type:
collections.OrderedDict
- leicacam.cam.bytes_as_dict(msg)[source]¶
Parse CAM message to OrderedDict based on format /key:val.
- Parameters:
msg (bytes) – Sequence of /key:val.
- Returns:
With /key:val => dict[key] = val.
- Return type:
collections.OrderedDict
- leicacam.cam.check_messages(msgs, cmd, value=None)[source]¶
Check if specific message is present.
- Parameters:
cmd (string) – Command to check for in bytestring from microscope CAM interface. If
value
is falsy, value of received command does not matter.value (string) – Check if
cmd:value
is received.
- Returns:
Correct messsage or None if no correct message if found.
- Return type:
collections.OrderedDict
- leicacam.cam.logger(function)[source]¶
Decorate passed in function and log message to module logger.
- leicacam.cam.tuples_as_bytes(cmds)[source]¶
Format list of tuples to CAM message with format /key:val.
- Parameters:
cmds (list of tuples) – List of commands as tuples.
- Returns:
Sequence of /key:val.
- Return type:
bytes
Example
>>> tuples_as_bytes([('cmd', 'val'), ('cmd2', 'val2')]) b'/cmd:val /cmd2:val2'