Code reference

FreiCtrl laser

class FreiCtrl_laser.host_utils.DataWriter(session_id: str, path2save: (<class 'str'>, <class 'pathlib.Path'>) = None, write_csv: bool = False)[source]

Class for writing data received from serial to csv and JSON file data arrives per trial and is written as individual row

copyCSV(target_path: Path)[source]

copy files to specified path, To be called from GUI with DB knowledge

injest_task(task: dict)[source]

get a dictionary from GUI writes the params to Json

injest_trial(trial: dict, do_additional_math: bool = True)[source]

gets a trial dictionary, writes to csv and to json

make_trial_math(dict_trial: dict) dict[source]

modify the trial dictionary with some more calculated values

purgeFiles()[source]

delete created files, in case of early abort

writeJSON()[source]

Write global parameters as json input is Task.strip_parameters(return_global = True)

writeTrial(trial: dict)[source]

write a dict representing Information about a single Trial to file

FreiCtrl_laser.host_utils.Stage_params

alias of stage_tuple

FreiCtrl_laser.host_utils.Version_params

from Task_parameters import TaskParameters params = TaskParameters().dictionize() NP_init = Stage_params(“NP_init”,params,’Initial stage, whereby the animal learns to interact with the nose poke.’) ver0 = Version_params(0,[NP_init])

FreiCtrl_laser.host_utils.dict_to_uuid(key: dict)[source]

Given a dictionary key, returns a hash string as UUID :param key: Any python dictionary :type key: dict

This module uses pyserial module for communication with OMICRON LuxX laser. The class Laser provides convenient methods for control of one or several lasers, connected to the computer.

Example

laser1 = Laser() laser1.smart_ask(“GSI”) laser1.smart_ask(“GOM”) laser1.start() laser1.set_power(24) laser1.stop() del laser1

Author

Roman Kiselev, January 2014 Artur Schneider, November 2023 - adopted to python3

License

GNU GPL - use it for any purpose

class FreiCtrl_laser.luxx_communication.Laser(port='auto', baudrate=500000)[source]

This class represents OMICRON LuxX laser. It opens the communication port upon object creation and asks the device for model and maximum power.

Functions

  • __init__(port=”auto”, baudrate=500000)

    constructor. Open port, get model name and power

  • __del__()

    destructor. Close the port upon completion

  • write(command)

    send command to device

  • read()

    read all data from port buffer

  • ask(command)

    send command and get only the relevant answer, as well as time

  • smart_ask(command)

    ask, which prints HEX answers in a table

  • print_HEX(HEXstring)

    print a nice table representing bits in a HEX number

  • start()

    start emission (takes 3 seconds)

  • stop()

    stop emission immediately

  • setPower(power_value)

    change the emitted power

  • getPower()

    ask for the current power (seting point, not actual emitted power)

  • setMode

    set an operating mode: standby, current control, power control or analog modulation.

  • getMode

    determine current operating mode

  • setAutostart

    if set, the laser will start emission on key turn event or on powerup. Otherwise, it can be started only from software with LOn command (start function).

  • getAutostart

    determine if autostart is active

Laser control

The device itself contains FTDI microchip, which emulates serial port via USB. In Linux it appears as dev tyUSB# file, where # is a number. In Windows, it leads to appearance of an additional COM port (COM##).

If the laser is connected via USB cable, the baudrate is 500000; it can also be connected via RS-232 interface with a special cable, then the baudrate should be set to 57600.

The laser is controlled with short commands (register matters!). The full desciption of commands can be found in the file PhoxX_LuxX_BrixX_command_list V1.0.pdf. Here is a list of commands that are relevant to the LuxX model:

  • RsC

    Reset Controller

  • GFw

    Get Firmware

  • GSN

    Get Serial Number

  • GSI

    Get Spec Info

  • GMP

    Get Maximum Power

  • GWH

    Get Working Hours

  • ROM

    Recall Operating Mode (Standby, CW-ACC, CW-APC, Analog)

  • GOM

    Get Operating Mode (ASCII HEX)

  • SOM

    Set Operating Mode (ASCII HEX)

  • SAS

    Set Auto Start (Laser will emit after startup)

  • SAP

    Set Auto Powerup

  • LOn

    Laser On - start emission

  • LOf

    Laser Off

  • POn

    Power On

  • POf

    Power Off

  • GAS

    Get Actual Status

  • GFB

    Get Failure Byte (ASCII HEX)

  • GLF

    Get Last Failurebyte (ASCII HEX)

  • MDP

    Measure Diode Power

  • MTD

    Measure Temperature Diode

  • MTA

    Measure Temperature Ambient

  • CLD

    Calibrate Laser Diode

  • SLP

    Set Level Power - set the emitted power (ASCII HEX up to 0xFFF)

  • GLP

    Get Level Power (ASCII HEX)

ask(command)[source]

Write, then read. However, return only the relevant info.

get_autostart()[source]

Check if light is emitted on powerup.

get_emitted_power() float[source]

get current power measured by internal diode :return:

get_errors()[source]

Print contents of failure byte

get_mode()[source]
The device is able to work in the following modes:
  • Standby

    turned off

  • CW-ACC

    constant wave, automatic current control

  • CW-APC

    constant wave, automatic power control

  • Analog

    the output power is dependent on the analog input; however, it cannot exceed the specified with set_power value.

get_parameters()[source]

Print a table showing laser status.

get_power()[source]

Get the current power value in mW

read()[source]

Read all information from the port and return it as string.

set_autostart(state)[source]

Decide if light is emitted on powerup.

set_mode(mode)[source]
The device is able to work in the following modes:
  • Standby

    Laser is ready, but no emission is produced. However, if we it is turned on (e.g. with start function), then change to other mode will result in immediate emission, i.e. without 3 seconds delay.

  • CW-ACC

    constant wave, automatic current control

  • CW-APC

    constant wave, automatic power control

  • Analog

    the output power is dependent on the analog input; however, it cannot exceed the specified with set_power value.

set_power(power)[source]

Set the desired power in mW

smart_ask(command)[source]

Several commands return information coded in ASCII HEX numbers. The relevant are bits in the registers. For convenient representation, we will print these bytes in tables. This is relevant for the following commands:

  • GOM

  • GFB

  • GLF

  • GLP

For all other commands the behavior is identical to ask function

start()[source]

Start the emission (takes about 3 seconds)

stop()[source]

Stop the emission immediately

write(command)[source]

Send command to device. Preceed it with “?” und end with CR.

class FreiCtrl_laser.luxx_communication.LaserColor(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
class FreiCtrl_laser.luxx_communication.LaserErrors(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
class FreiCtrl_laser.luxx_communication.TriggerEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
FreiCtrl_laser.luxx_communication.print_hex(hex_code)[source]

Print a nice table that represents hex_code (ASCII HEX string) in a binary code.

Return type:

corresponding decimal numbers in array

FreiCtrl_laser.luxx_communication.stopwatch(func, *func_args, **func_kwargs)[source]

Call func and print elapsed time

class FreiCtrl_laser.socket_utils.MessageStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
class FreiCtrl_laser.socket_utils.MessageType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
class FreiCtrl_laser.socket_utils.SocketComm(type: str = 'server', host: str = 'localhost', port: int = 8800, use_ssl: bool = False)[source]

Socket communication class

connect() bool[source]

Connects to the server

stop_waiting_for_connection()[source]

sets the stop event, so the thread will stop waiting for a connection

threaded_accept_connection()[source]

Accepts connection in a separate thread, to not block the main thread