Morelia.Devices package

Subpackages

Submodules

Morelia.Devices.BasicPodProtocol module

class Morelia.Devices.BasicPodProtocol.Pod(port, baudrate=9600, device_name=None, use_d2xx=False)

Bases: object

Pod handles basic communication with a generic POD device, including reading and writing packets and packet interpretation. This is the parent class for any device that communcates using the POD protocol.

Parameters:
  • port (str | int) – Serial port to be opened. For COM ports: β€œCOM9” or 9. For D2XX: serial number string or device index.

  • baudrate (int) – Baud rate of the opened serial port. Default value is 9600.

  • device_name (str | None) – Virtual Name used to indentify device.

  • use_d2xx (bool) – If True, use FTDI D2XX direct USB communication instead of COM port. Requires pylibftdi. Defaults to False.

apply_config(config)

Recursively apply a device configuration dictionary by invoking property setters discovered via the MRO.

Keys listed in skip_keys (determined per device type) are ignored.

Parameters:

config (dict) – Device configuration dictionary (e.g. loaded from TOML).

property baudrate: int
static build_pod_packet_standard(command_number, payload=None)

Builds a standard POD packet (control packet) as bytes: STX (1 byte) + command number (4 bytes) + optional packet (? bytes) + checksum (2 bytes)+ ETX (1 bytes).

Parameters:
  • command_number (int) – Integer representing the command number. This will be converted into a 4 byte long ASCII-encoded bytes string.

  • payload (bytes | None) – bytes string containing the payload. Defaults to None.

Return type:

bytes

Returns:

Bytes string of a complete standard POD packet.

check_write_queue()

Checks the queue for packets and writes them to the device if they exist.

Return type:

None

static checksum(bytes_in)

Calculates the checksum of a given bytes message. This is achieved by summing each byte in the message, inverting, and taking the last byte.

Parameters:

bytes_in (bytes) – Bytes message containing POD packet data.

Return type:

bytes

Returns:

Two ASCII-encoded bytes containing the checksum for bytes_in.

static choose_port(forbidden=[])

Checks user’s Operating System, and chooses ports accordingly.

Parameters:

forbidden (list[str]) – List of port names that are already used. Defaults to an empty list.

Return type:

str

Returns:

Name of the port.

cleanup()

Clean up resources including closing the port and terminating queue server subprocess.

close_port()
property device_name: str

The virtual device name.

flush_port()

Reset the input and output serial port buffer.

Return type:

bool

Returns:

True of the buffers are flushed, False otherwise.

get_config(folder_path, filename=None)

Read all configured properties from the device and write them to a TOML file.

Requires that the subclass provides id, pod_type, and get_combined_property_map (available on AcquisitionDevice and its subclasses).

Parameters:
  • folder_path (str) – Folder in which to save the generated TOML file.

  • filename (str | None) – Optional filename; defaults to <device_name>_config.toml.

get_device_commands()

Gets the dictionary containing the class instance’s available POD commands.

Return type:

dict[int, list[str | tuple[int] | bool]]

Returns:

Dictionary containing the available commands and their information.Formatted as key(command number) : value([command name, number of argument ASCII bytes, number of return bytes, binary flag ])

get_dict()

Obtains pod __init__ argument values to use for process pickling

get_pod_packet(cmd, payload=None)

Builds a POD packet and writes it to a POD device via COM port. If an integer payload is give, the method will convert it into a bytes string of the length expected by the command. If a bytes payload is given, it must be the correct length.

Parameters:
  • cmd (str | int) – Command number.

  • payload (int | bytes | tuple[int | bytes]) – None when there is no payload. If there is a payload, set to an integer value, bytes string, or tuple. Defaults to None.

Return type:

bytes

Returns:

Bytes string of the POD packet.

static get_u(u)

Number of hexadecimal characters for an unsigned u-bit value.

Parameters:

u (int) – 8, 16, or 32 bits. Enter any other number for NO_VALUE.

Return type:

int

Returns:

number of hexadecimal characters for an unsigned u-bit value.

initialize_control_queue()
obtain_read_queue()
obtain_write_queue()
open_port()

Open the port using either PortIO (COM port) or D2XXPortIO (direct USB).

static payload_to_bytes(payload, arg_sizes)

Converts a payload into a bytes string (assuming that the payload is for a valid command).

Parameters:
  • payload (int | bytes | tuple[int | bytes]) – Integer, bytes, or tuple containing the payload.

  • arg_sizes (tuple[int]) – Tuple of the argument sizes.

Return type:

bytes

Returns:

Bytes string of the payload.

property port
property port_inst
read_pod_packet(validate_checksum=True, timeout_sec=5)

Reads a complete POD packet, either in standard or binary format, beginning with STX and ending with ETX. Reads first STX and then starts recursion.

Parameters:
  • validate_checksum (bool) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

  • timeout_sec (int | float) – Time in seconds to wait for serial data. Defaults to 5.

Return type:

PodPacket

Returns:

POD packet beginning with STX and ending with ETX. This may be a control packet, data packet, or an unformatted packet (STX+something+ETX).

register_control_queue()
set_baudrate_of_device(baudrate)

If the port is open, it will change the baud rate to the parameter’s value.

Parameters:

baudrate (int) – Baud rate to set for the open serial port.

Return type:

bool

Returns:

True if successful at setting the baud rate, false otherwise.

set_config(folder_path)

Load an experiment configuration folder, match this device by ID and name, apply the referenced device config TOML, and validate the result.

Requires that the subclass provides id, pod_type, and validate_config (available on AcquisitionDevice and its subclasses).

Parameters:

folder_path (str) – Path to the experiment configuration folder.

test_connection(ping_cmd='PING')

Tests if a POD device can be read from or written. Sends a PING command.

Parameters:

ping_cmd (str | int) – Command name or number to ping. Defaults to β€˜PING’.

Return type:

bool

Returns:

True for successful connection, false otherwise.

write_packet(cmd, payload=None)

Builds a POD packet and writes it to the POD device.

Parameters:
  • cmd (str | int) – Command number.

  • payload (int | bytes | tuple[int | bytes]) – None when there is no payload. If there is a payload, set to an integer value, bytes string, or tuple. Defaults to None.

Return type:

ControlPacket

Returns:

Packet that was written to the POD device.

write_read(cmd, payload=None, validate_checksum=True, timeout_sec=5)

Writes a command with optional payload to POD device, then reads (once) the device response.

Parameters:
  • cmd (str | int) – Command number.

  • payload (int | bytes | tuple[int | bytes]) – None when there is no payload. If there is a payload, set to an integer value or a bytes string. Defaults to None.

  • validate_checksum (bool) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

Return type:

PodPacket

Returns:

POD packet beginning with STX and ending with ETX. This may be a control packet, data packet, or an unformatted packet (STX+something+ETX).

Morelia.Devices.PodDevice_8206HR module

class Morelia.Devices.PodDevice_8206HR.Pod8206HR(port, preamp_gain, baudrate=9600, device_name=None, use_d2xx=False, sample_rate=None)

Bases: AcquisitionDevice

Pod8206HR is used to interact with a 8206HR data acquisition device.

Parameters:
  • port (str | int) – Serial port to be opened. For COM ports: β€œCOM9” or 9. For D2XX: serial number string or device index.

  • preamp_gain (int) – A unitless number used to add gain to vlues recived from the preamplifier. Used in converting streaming data from the device into something human-readable. Must be 10 or 100.

  • baudrate (int) – Baud rate of the opened serial port. Default value is 9600.

  • device_name (str | None) – Virtual name used to indentify device.

  • use_d2xx (bool) – If True, use FTDI D2XX direct USB communication instead of COM port. Requires ftd2xx (Windows) or pylibftdi (Linux/Mac). Defaults to False.

property filter_config: int

Hardware filter configuration. 0=SL, 1=SE (40/40/100Hz), 2=SE3 (40/40/40Hz).

get_dict()

Obtains pod __init__ argument values to use for process pickling

property lowpass_ch0: int

Lowpass filter for channel 0 (EEG1) in Hz.

property lowpass_ch1: int

Lowpass filter for channel 1 (EEG2) in Hz.

property lowpass_ch2: int

Lowpass filter for channel 2 (EEG3/EMG) in Hz.

property preamp_gain
read_pod_packet_streaming(timeout_sec=0.1, validate_checksum=True)

Read one packet (data or control) using a single read(16) when aligned. Use in streaming mode for higher throughput.

When a fixed-size block is a complete data packet (16 bytes, ends with ETX), returns DataPacket8206HR. When the block starts with STX but does not end with ETX (e.g. control packet), reads to ETX, parses as ControlPacket, and returns it so the pipeline can deliver it to read_queue for mixed traffic. Accumulates partial reads so driver returning fewer than 16 bytes does not cause timeout. Raises TimeoutError if no data in timeout_sec.

property ttl_pin0: int

TTL pin 0 input value (0 or 1).

property ttl_pin1: int

TTL pin 1 input value (0 or 1).

property ttl_pin2: int

TTL pin 2 input value (0 or 1).

property ttl_pin3: int

TTL pin 3 input value (0 or 1).

property ttl_port: int

Entire TTL port value as a byte (read-only, does not modify pin direction).

Morelia.Devices.PodDevice_8229 module

class Morelia.Devices.PodDevice_8229.Pod8229(port, baudrate=19200, device_name=None)

Bases: Pod

POD8229 handles communication with a 8229 POD device.

Parameters:
  • port (str | int) – Serial port to be opened. Used when initializing the COM_io instance.

  • baudrate (int) – Integer baud rate of the opened serial port. Used when initializing the COM_io instance. Defaults to 19200.

  • device_name (str | None) – Virtual name used to identify device.

static build_set_day_schedule_argument(day, hours, speed)

Appends the day of the week code to the front of the encoded hourly schedule. this tuple is formatted to be used as the #141 SET DAY SCHEDULE argument.

Parameters:
  • day (str | int) – Day of the week. Can be either the name of the day (i.e. Sunday, Monday, etc.) or the 0-6 day code (0 for Sunday increacing to 6 for Saturday).

  • hours (list | tuple[bool | int]) – Array of 24 items. The value is 1 for motor on and 0 for motor off.

  • speed (int | list | tuple[int]) – Speed of the motor (0-100). This is an integer of all hours are the same speed. If there are multiple speeds, this should be an array of 24 items.

Return type:

tuple[int]

Returns:

Argument to pass with packet for SET DAY SCHEDULE.

static code_day_of_week(day)

Converts the day of the week to an integer code understandable by the POD device. The day is determined by the first 1-2 characters of the string, which supports multiple abbreviations for days of the week.

Parameters:

day (str) – Day of the week.

Return type:

int

Returns:

Code for the day of the week. Values are 0-6, with 0 for Saturday, 1 for Monday, …, and 6 for Saturday.

static code_day_schedule(hours, speed)

Bitmasks the day schedule to encode the motor on/off status and the motor speed. Use this for getting the command #141 SET DAY SCHEDULE UINT8x24 argument component.

Parameters:
  • hours (list | tuple[bool | int]) – Array of 24 items. The value is 1 for motor on and 0 for motor off.

  • speed (int | list | tuple[int]) – Speed of the motor (0-100). This is an integer of all hours are the same speed. If there are multiple speeds, this should be an array of 24 items.

Return type:

list[int]

Returns:

List of 24 integer items. The msb is the motor on/off flag and the remaining 7 bits are the speed.

static decode_day_and_schedule(dayschedule)

Decode the packet payload returned by the SET DAY SCHEDULE.

Parameters:

dayschedule (bytes) – Raw payload of packet.

Return type:

tuple[int, dict[str, int | tuple[int]]]

Returns:

Tupke containg day and schedule for day.

static decode_day_of_week(day)

Converts the integer code for a day of the week to a human-readable string.

Parameters:

day (int) – Day of the week code must be 0-6.

Return type:

str

Returns:

Day of the week (β€˜Sunday’, β€˜Monday’, etc.).

static decode_day_schedule(schedule)

Interprets the return bytes from the command #142 β€˜GET DAY SCHEDULE’.

Parameters:

schedule (bytes) – 24 byte long bitstring with one UINT8 per hour in a day.

Return type:

dict[str, int | tuple[int]]

Returns:

Dictionary with β€˜Hour’ as a tuple of 24 0/1 values (0 is motor off and 1 is motor on) and β€˜Speed’ as the motor speed (0-100). If the motor speed is the same every hour, β€˜Speed’ will be an integer; otherwise, β€˜Speed’ will be a tuple of 24 items.

static decode_lcd_schedule(schedule)

Interprets the return bytes from the command #202 β€˜LCD SET DAY SCHEDULE’.

Parameters:

schedule (bytes) – 4 Byte long bitstring. Byte 3 is weekday, Byte 2 is hours 0-7, Byte 1 is hours 8-15, and byte 0 is hours 16-23.

Return type:

dict[str, str | list[int]]

Returns:

Dictionary with Day as the day of the week, and Hours containing a list of 24 0/1 values (one for each hour). Each bit represents the motor state in that hour, 1 for on and 0 for off.

static get_current_time()

Gets a tuple to use as the argument for command #140 SET TIME containing values for the current time.

Return type:

tuple[int]

Returns:

Tuple of 7 integer values. The format is (Seconds, Minutes, Hours, Day, Month, Year (without century, so 23 for 2023), Weekday (0 for Sunday))

Morelia.Devices.PodDevice_8274D module

class Morelia.Devices.PodDevice_8274D.Pod8274D(port, baudrate=921600, device_name=None)

Bases: AcquisitionDevice

POD_8274D handles communication using an 8274D POD device. Currently under construction and is unreliable.

Parameters:
  • port (str | int) – Serial port to be opened. Used when initializing the COM_io instance.

  • baudrate (int) – Baud rate of the opened serial port. Default value is 9600.

  • device_name (str | None) – Virtual name used to indentify device.

Morelia.Devices.PodDevice_8401HR module

class Morelia.Devices.PodDevice_8401HR.Pod8401HR(port, preamp, primary_channel_modes, secondary_channel_modes, ss_gain=(None, None, None, None), preamp_gain=(None, None, None, None), baudrate=9600, device_name=None, use_d2xx=False)

Bases: AcquisitionDevice

Pod8401HR handles communication using an 8401HR POD device.

Parameters:
  • port (str | int) – Serial port to be opened. Used when initializing the COM_io instance.

  • preamp (Preamp) – Device/sensor connected to the the 8401HR.

  • primary_channel_mode – A tuple containing the mode of operation for each primary channel (EEG/EMG or Biosensor).

  • secondary_channel_modes (tuple[SecondaryChannelMode]) – A tuple containing the mode of operation for each secondary (TTL/AEXT) channel (analog or digital).

  • ss_gain (tuple[int | None]) – Tuple storing the second-stage gain for all four channels. Defaults to (None, None, None, None).

  • preamp_gain (tuple[int | None]) – Tuple storing the pramplifier gain for all four channels. Defaults to (None, None, None, None).

  • baudrate (int) – Integer baud rate of the opened serial port. Used when initializing the COM_io instance. Defaults to 9600.

  • device_name (str | None) – Virtual name used to indentify device.

apply_preamp_config(model)

Look up model in the preamp registry and apply its settings.

Sets per-channel hardware properties (dc_mode, highpass, lowpass, bias, ss_config), updates _channel_invert, _preamp_gain, _ss_gain, and rebuilds the stream packet factory so that all downstream consumers see correct values.

Parameters:

model (str) – Preamp model number (e.g. "8406-SE3").

Raises:

ValueError – If model is not found in the registry.

Return type:

None

property bias_0: float

Bias voltage on channel 0 (derived from 16-bit DAC).

property bias_1: float

Bias voltage on channel 1.

property bias_2: float

Bias voltage on channel 2.

property bias_3: float

Bias voltage on channel 3.

static calculate_bias_dac_get_dac_value(vout)

Calculates the DAC value given the output voltage. Used for GET/SET BIAS commands.

Parameters:

vout (int | float) – Output voltage (+/- 2.048 V).

Return type:

int

Returns:

Integer of the DAC value (16 bit 2’s complement).

static calculate_bias_dac_get_vout(value)

Calculates the output voltage given the DAC value. Used for GET/SET BIAS commands.

Parameters:

value (int) – DAC value (16 bit 2’s complement).

Return type:

float

Returns:

Float of the output bias voltage [V].

property channel_invert: tuple[bool, ...]

Per-channel inversion flags (True = negate stream value).

property channel_labels: tuple[str, ...] | None

Per-channel display labels from the applied preamp config, or None if no preamp config has been applied.

property dc_mode_0: int

DC mode for channel 0. 0=Subtract VBias, 1=Subtract AGND.

property dc_mode_1: int

DC mode for channel 1.

property dc_mode_2: int

DC mode for channel 2.

property dc_mode_3: int

DC mode for channel 3.

static decode_channel_bitmask(channels)

Converts the channel bitmask byte to a dictionary with each channel value. Use for GET INPUT GROUND command payloads.

Parameters:

channels (bytes) – UINT8 byte containing the channel configuration.

Return type:

dict[str, int]

Returns:

Dictionary with the channels as keys and values as the state. 0=Grounded and 1=Connected to Preamp.

static decode_ss_config_bitmask(config)

Converts the SS configuration byte to a dictionary with the high-pass and gain.

Parameters:

config (bytes | bytearray | int) – UINT8 containing the SS configuration (raw bytes, bytearray, or int). Bit 0: 0 = 0.5 Hz Highpass, 1 = DC Highpass. Bit 1: 0 = 5x gain, 1 = 1x gain.

Return type:

dict[str, float | int]

static decode_ttl_byte(ttl_byte)

Converts the TTL bytes argument into a dictionary of integer TTL values.

Handles both raw bytes (length 1, decoded by bit-shift) and ASCII hex bytes (decoded via conv.ascii_bytes_to_int_split).

Parameters:

ttl_byte (bytes) – UINT8 byte containing the TTL bitmask.

Return type:

dict[str, int]

Returns:

Dictionary with TTL name keys and integer TTL values.

static decode_ttl_payload(payload)

Decodes a paylaod with the two TTL bytes.

Parameters:

payload (bytes) – Bytes string of the POD packet payload.

Return type:

tuple[dict[str, int]]

Returns:

Tuple with two TTL dictionaries.

property ext0: int

Analog value on EXT0 pin (unsigned 12-bit, 3.3V range).

property ext1: int

Analog value on EXT1 pin (unsigned 12-bit, 3.3V range).

static get_channel_bitmask(a, b, c, d)

Gets a bitmask, represented by an unsigned integer, used for SET INPUT GROUND command.

Parameters:
  • a (bool) – State for channel A, 0=Grounded and 1=Connected to Preamp.

  • b (bool) – State for channel B, 0=Grounded and 1=Connected to Preamp.

  • c (bool) – State for channel C, 0=Grounded and 1=Connected to Preamp.

  • d (bool) – State for channel D, 0=Grounded and 1=Connected to Preamp.

Return type:

int

Returns:

Integer representing a bitmask.

static get_channel_map_for_preamp_device(preamp_name)

Get the channel mapping (channel labels for A,B,C,D) for a given device.

Parameters:

preamp_name (Preamp) – Device/sensor for lookup.

Return type:

dict[str, str] | None

Returns:

Dictionary with keys A,B,C,D with values of the channel names. Returns None if the device name does not exist.

get_channel_preamp_gain(channel)

Return the preamplifier gain for channel (0-3).

Return type:

float

get_dict()

Obtains pod __init__ argument values to use for process pickling

get_preamp_highpass(channel)

Get the highpass filter value for channel (0-3).

Return type:

int

get_second_stage_gain(channel)

Get second-stage gain for channel (0-3).

Return type:

int

static get_ss_config_bitmask(gain, highpass)

Gets a bitmask, represented by an unsigned integer, used for SET SS CONFIG command.

Parameters:

gain (int) – 1 for 1x gain. else for 5x gain. highpass (float): 0 for DC highpass, else for 0.5Hz highpass.

Return type:

int

Returns:

Integer representing a bitmask.

static get_ttl_bitmask(ext0=0, ext1=0, ttl4=0, ttl3=0, ttl2=0, ttl1=0)

Builds an integer, which represents a binary mask, that can be used for TTL command arguments.

Parameters:
  • ext0 (int) – boolean bit for ext0. Defaults to 0.

  • ext1 (int) – boolean bit for ext1. Defaults to 0.

  • ttl4 (int) – boolean bit for ttl4. Defaults to 0.

  • ttl3 (int) – boolean bit for ttl3. Defaults to 0.

  • ttl2 (int) – boolean bit for ttl2. Defaults to 0.

  • ttl1 (int) – boolean bit for ttl1. Defaults to 0.

Return type:

int

Returns:

Integer number to be used as a bit mask.

property input_ground0: int

Channel A ground state: 1=preamp, 0=grounded.

property input_ground1: int

Channel B ground state: 1=preamp, 0=grounded.

property input_ground2: int

Channel C ground state: 1=preamp, 0=grounded.

property input_ground3: int

Channel D ground state: 1=preamp, 0=grounded.

property input_ground_all: dict[str, int]

All input ground states (channels A-D) read from device.

property lowpass_ch0: int

Lowpass filter for channel 0 in Hz.

property lowpass_ch1: int

Lowpass filter for channel 1 in Hz.

property lowpass_ch2: int

Lowpass filter for channel 2 in Hz.

property lowpass_ch3: int

Lowpass filter for channel 3 in Hz.

property mux_mode: int

Mux mode state. 0=off, 1=on (toggles EXT1 for 2BIO/3EEG preamps).

property preamp: Preamp

Preamp connected to device.

property preamp_gain

Preamp connected to device.

property preamp_highpass_0: int

Highpass filter for channel 0. 0=0.5Hz, 1=1Hz, 2=10Hz, 3=DC.

property preamp_highpass_1: int

Highpass filter for channel 1.

property preamp_highpass_2: int

Highpass filter for channel 2.

property preamp_highpass_3: int

Highpass filter for channel 3.

property preamp_model: str | None

Currently configured preamp model, or None if not set via apply_preamp_config().

property primary_channel_modes
read_pod_packet_streaming(timeout_sec=0.1, validate_checksum=True)

Read one packet (data or control) using a single read(31) when aligned. Use in streaming mode for higher throughput.

When a fixed-size block is a complete data packet (31 bytes, ends with ETX), returns DataPacket8401HR. When the block starts with STX but does not end with ETX (e.g. control packet), reads to ETX, parses as ControlPacket, and returns it so the pipeline can deliver it to read_queue for mixed traffic. Raises TimeoutError if no data in timeout_sec.

property secondary_channel_modes
set_ss_config(channel, config)

Set the second-stage config for channel (0-3).

Parameters:
  • channel (int) – Channel index.

  • config (dict[str, int | float]) – Dict with keys "Gain" and "High-pass".

set_ttl_outputs(pins)

Set specific TTL output states.

Parameters:

pins (dict[str, int]) – Keys from EXT0, EXT1, TTL1-TTL4; values 0 (low) or 1 (high).

property ss_config_0: dict[str, float | int]

Second-stage config for channel 0 (Gain + High-pass).

property ss_config_1: dict[str, float | int]

Second-stage config for channel 1.

property ss_config_2: dict[str, float | int]

Second-stage config for channel 2.

property ss_config_3: dict[str, float | int]

Second-stage config for channel 3.

property ss_gain
property ss_gain_0: int

Second-stage gain for channel 0.

property ss_gain_1: int

Second-stage gain for channel 1.

property ss_gain_2: int

Second-stage gain for channel 2.

property ss_gain_3: int

Second-stage gain for channel 3.

property ttl_analog_ext0: int

Analog reading on TTL EXT0 (10-bit).

property ttl_analog_ext1: int

Analog reading on TTL EXT1.

property ttl_analog_ttl1: int

Analog reading on TTL1.

property ttl_analog_ttl2: int

Analog reading on TTL2.

property ttl_analog_ttl3: int

Analog reading on TTL3.

property ttl_analog_ttl4: int

Analog reading on TTL4.

property ttl_config: dict[str, dict[str, int]]

TTL configuration with β€˜output’ and β€˜input’ sub-dicts.

Morelia.Devices.PodDevice_8480SC module

class Morelia.Devices.PodDevice_8480SC.Pod8480SC(port, baudrate=9600, device_name=None)

Bases: Pod

POD_8480SC handles communication using an 8480-SC POD device.

Parameters:
  • port (str | int) – Serial port to be opened. Used when initializing the COM_io instance.

  • baudrate (int) – Baud rate of the opened serial port. Default value is 9600.

  • device_name (str | None) – Virtual name used to indentify device.

static decode_stimulus_config_bits(config)

Converts an integer into 3 values, representing 3 individual bits of the Stimulus Config Bits.

Parameters:

config (int) – an integer is passed in, and it represents the Config Flag byte.

Return type:

dict

Returns:

Keys as the names of the bits, the values representing values at each bit.

static decode_sync_config_bits(config)

Converts an integer into 3 values, representing 3 individual bits of the Sync Config Bits.

Parameters:

config (int) – an integer is passed in, and it represents the Sync Config Flag byte.

Return type:

dict

Returns:

Keys as the names of the bits, the values representing values at each bit.

static decode_ttl_config_bits(config)

Converts an interger into 3 values, representing 3 individual bits of the TTL Config Bits.

Parameters:

config (int) – an integer is passed in, and it represents the TTL Setup Config Flag Byte.

Return type:

dict

Returns:

Keys as the names of the bits, the values representing values at each bit.

static stimulus_config_bits(optoElec, monoBiphasic, Simul)

Incoming inputs are bitmasked into an integer value. This value is later given as part of a payload to command #102 β€˜SET STIMULUS’.

Parameters:
  • optoElec (bool) – Bit is Opto/Electrical.

  • monoBiphasic (bool) – Bit 1 is Monophasic/Biphasic.

  • Simul (bool) – Bit 2 is Simultaneous.

Return type:

int

Returns:

which represents the Config flag byte in the Stimulus Command. The return value is the seventh item in the payload for command β€˜SET STIMULUS’.

static sync_config_bits(sync_level, sync_idle, signal_trigger)

Incoming inputs are bitmasked into an integer value. This value is later given as the payload to command #127 β€˜SET SYNC CONFIG’.

Parameters:
  • sync_level (bool) – Bit 0 is Sync Level.

  • sync_idle (bool) – Bit 1 is Stimulus Triggering.

  • signal_trigger (bool) – Bit 2 is Signal/Trigger.

Return type:

int

Returns:

which represents the Sync Config Bits format value.

static ttl_config_bits(trigger, stimtrig, input_sync)

Incoming inputs are bitmasked into an integer value. This value is later given as part of the payload to command #109 β€˜SET TTL SETUP’. This commands accepts 3 items in the payload, and the return value of this function is given as the second item.

Parameters:
  • trigger (bool) – Bit 0 is 0 for rising edge, 1 for falling edge.

  • stimtrig (bool) – Bit 1 is 0 for TTL event notifications, 1 for TTL inputs as triggers.

  • input_sync (bool) – Bit 7 is 0 for normal TTL operation, 1 for TTL pin operates as a sync output.

Return type:

int

Returns:

which represents the TTL Config Bits Format value.

Morelia.Devices.acquisition_device module

POD device that streams data.

class Morelia.Devices.acquisition_device.AcquisitionDevice(port, max_sample_rate, baudrate=9600, device_name=None, get_sample_rate_cmd_no=100, set_sample_rate_cmd_no=101, use_d2xx=False)

Bases: Pod

This class is the parent of any device that can stream (i.e. data acquisiton devices).

Parameters:
  • port (str | int) – Serial port to be opened. For COM ports: β€œCOM9” or 9. For D2XX: serial number string or device index.

  • max_sample_rate (int) – Maximum sample rate supported by the device (in Hz).

  • baudrate (int) – Baud rate of the opened serial port. Default value is 9600.

  • device_name (str | None) – Virtual Name used to indentify device.

  • get_sample_rate_cmd_no (int) – Command number for the GET SAMPLE RATE command on the device.

  • set_sample_rate_cmd_no (int) – Command number for the SET SAMPLE RATE command on the device.

  • use_d2xx (bool) – If True, use FTDI D2XX direct USB communication instead of COM port. Requires ftd2xx (Windows) or pylibftdi (Linux/Mac). Defaults to False.

classmethod get_combined_property_map()

Merge the base property_map with any device-specific _property_map defined on a subclass.

Return type:

dict

property id: int

Returns a device’s hardware ID.

property max_sample_rate: int

Maximum allowable sample rate.

property pod_info: dict

Returns pod identification info as a dictionary.

property pod_type: str

Maps the device TYPE number to a pod device class name string.

property_map: dict = {'sample_rate': {'sample_rate': 'sample_rate'}}
property sample_rate: int

Currently set sample rate.

property type: int

Returns a device’s TYPE number.

validate_config(expected_config, skip_keys=None)

Compare expected_config against the device’s current settings.

Parameters:
  • expected_config (dict) – Expected configuration dictionary.

  • skip_keys (set | None) – Keys to ignore during comparison.

Return type:

dict

Returns:

Dict mapping config keys (dot-notation) to (expected, actual) tuples for any differences. Empty when everything matches.

Morelia.Devices.preamp module

class Morelia.Devices.preamp.Preamp(*values)

Bases: Enum

Preamp8406_2BIO = 10
Preamp8406_BIO = 9
Preamp8406_EEG2BIO = 11
Preamp8406_SE = 12
Preamp8406_SE3 = 14
Preamp8406_SE31M = 8
Preamp8406_SE4 = 15
Preamp8406_SL = 13
Preamp8407_SE = 1
Preamp8407_SE3 = 3
Preamp8407_SE31M = 5
Preamp8407_SE4 = 4
Preamp8407_SE_2BIO = 6
Preamp8407_SL = 2
Preamp8407_SL_2BIO = 7

Module contents