Morelia.Devices package

Subpackages

Submodules

Morelia.Devices.BasicPodProtocol module

class Morelia.Devices.BasicPodProtocol.Pod(port: str | int, baudrate: int = 9600)

Bases: object

POD_Basics handles basic communication with a generic POD device, including reading and writing packets and packet interpretation.

_port

Instance-level COM_io object, which handles the COM port

Type:

COM_io

_commands

Instance-level POD_Commands object, which stores information about the commands available to this POD device.

Type:

POD_Commands

static BuildPODpacket_Standard(commandNumber: int, payload: bytes | None = None) bytes

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

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

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

Returns:

Bytes string of a complete standard POD packet.

Return type:

bytes

static Checksum(bytesIn: bytes) bytes

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:

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

Returns:

Two ASCII-encoded bytes containing the checksum for bytesIn.

Return type:

bytes

static ChoosePort(forbidden: list[str] = []) str

Systems checks user’s Operating System, and chooses ports accordingly.

Parameters:

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

Returns:

String name of the port.

Return type:

str

FlushPort() bool

Reset the input and output serial port buffer.

Returns:

True of the buffers are flushed, False otherwise.

Return type:

bool

GetDeviceCommands() dict[int, list[str | tuple[int] | bool]]

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

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 ])

Return type:

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

GetPODpacket(cmd: str | int, payload: int | bytes | tuple[int | bytes] | None = None) bytes

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], optional) – None when there is no payload. If there is a payload, set to an integer value, bytes string, or tuple. Defaults to None.

Raises:
  • Exception – POD command does not exist.

  • Exception – POD command requires a payload.

Returns:

Bytes string of the POD packet.

Return type:

bytes

static GetU(u: int) int

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

Parameters:

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

Returns:

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

Return type:

int

static PayloadToBytes(payload: int | bytes | tuple[int | bytes], argSizes: tuple[int]) bytes

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.

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

Returns:

Bytes string of the payload.

Return type:

bytes

ReadPODpacket(validateChecksum: bool = True, timeout_sec: int | float = 5) Packet

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:
  • validateChecksum (bool, optional) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

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

Returns:

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

Return type:

Packet

SetBaudrateOfDevice(baudrate: int) bool

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.

Returns:

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

Return type:

bool

TestConnection(pingCmd: str | int = 'PING') bool

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

Parameters:

pingCmd (str | int, optional) – Command name or number to ping. Defaults to ‘PING’.

Returns:

True for successful connection, false otherwise.

Return type:

bool

Raises:

Exception – Ping command does not exist for this POD device.

WritePacket(cmd: str | int, payload: int | bytes | tuple[int | bytes] | None = None) PacketStandard

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

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

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

Returns:

Packet that was written to the POD device.

Return type:

Packet_Standard

WriteRead(cmd: str | int, payload: int | bytes | tuple[int | bytes] | None = None, validateChecksum: bool = True) Packet

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], optional) – None when there is no payload. If there is a payload, set to an integer value or a bytes string. Defaults to None.

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

Returns:

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

Return type:

Packet

_ReadPODpacket_Recursive(validateChecksum: bool = True) Packet

Reads the command number. If the command number ends in ETX, the packet is returned. Next, it checks if the command is allowed. Then, it checks if the command is standard or binary and reads accordingly, then returns the packet.

Parameters:

validateChecksum (bool, optional) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

Raises:

Exception – Cannot read an invalid command.

Returns:

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

Return type:

Packet|Packet_Standard|Packet_BinaryStandard

_Read_Binary(prePacket: bytes, validateChecksum: bool = True) PacketBinary

Reads the remaining part of the variable-length binary packet. It first reads the standard packet (prePacket+payload+checksum+ETX). Then it determines how long the binary packet is from the payload of the standard POD packet and reads that many bytes. It then reads to ETX to get the checksum+ETX.

Parameters:
  • prePacket (bytes) – Bytes string containing the beginning of a POD packet: STX (1 byte) + command number (4 bytes)

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

Raises:

Exception – An exception is raised if the checksum is invalid (only if validateChecksum=True).

Returns:

Variable-length binary POD packet.

Return type:

PacketBinary

_Read_GetCommand(validateChecksum: bool = True) bytes

Reads one byte at a time up to 4 bytes to get the ASCII-encoded bytes command number. For each byte read, it can (1) start the recursion over if an STX is found, (2) returns if ETX is found, or (3) continue building the command number.

Parameters:

validateChecksum (bool, optional) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

Returns:

4 byte long string containing the ASCII-encoded command number.

Return type:

bytes

_Read_Standard(prePacket: bytes, validateChecksum: bool = True) PacketStandard

Reads the payload, checksum, and ETX. Then it builds the complete standard POD packet in bytes.

Parameters:
  • prePacket (bytes) – Bytes string containing the beginning of a POD packet: STX (1 byte) + command number (4 bytes).

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

Raises:

Exception – An exception is raised if the checksum is invalid (only if validateChecksum=True).

Returns:

Complete standard POD packet.

Return type:

Packet_Standard

_Read_ToETX(validateChecksum: bool = True) bytes

Reads one byte at a time until an ETX is found. It will restart the recursive read if an STX is found anywhere.

Parameters:

validateChecksum (bool, optional) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

Returns:

Bytes string ending with ETX.

Return type:

bytes

static _ValidateChecksum(msg: bytes) bool

Validates the checksum of a given POD packet. The checksum is valid if the calculated checksum from the data matches the checksum written in the packet.

Parameters:

msg (bytes) – Bytes message containing a POD packet: STX (1 bytes) + data (? bytes) + checksum (2 bytes) + ETX (1 byte).

Returns:

True if the checksum is correct, false otherwise.

Return type:

bool

Raises:

Exception – msg does not begin with STX or end with ETX.

Morelia.Devices.PodDevice_8206HR module

class Morelia.Devices.PodDevice_8206HR.Pod8206HR(port: str | int, preampGain: int, baudrate: int = 9600)

Bases: Pod

POD_8206HR handles communication using an 8206HR POD device.

_preampGain

Instance-level integer (10 or 100) preamplifier gain.

Type:

int

ReadPODpacket(validateChecksum: bool = True, timeout_sec: int | float = 5) Packet

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:
  • validateChecksum (bool, optional) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

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

Returns:

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

Return type:

Packet

_Read_Binary(prePacket: bytes, validateChecksum: bool = True) PacketBinary4

After receiving the prePacket, it reads the 8 bytes(TTL+channels) and then reads to ETX (checksum+ETX).

Parameters:
  • prePacket (bytes) – Bytes string containing the beginning of a POD packet: STX (1 byte) + command number (4 bytes).

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

Raises:

Exception – Bad checksum for binary POD packet read.

Returns:

Binary4 POD packet.

Return type:

Packet_Binary4

static _TranslateTTLbyte_ASCII(ttlByte: bytes) dict[str, int]

Separates the bits of each TTL (0-3) from a ASCII encoded byte.

Parameters:

ttlByte (bytes) – One byte string for the TTL (ASCII encoded).

Returns:

Dictionary of the TTLs. Values are 1 when input, 0 when output.

Return type:

dict[str,int]

Morelia.Devices.PodDevice_8229 module

class Morelia.Devices.PodDevice_8229.Pod8229(port: str | int, baudrate: int = 19200)

Bases: Pod

POD_8229 handles communication using an 8229 POD device.

static BuildSetDayScheduleArgument(day: str | int, hours: list | tuple[bool | int], speed: int | list | tuple[int]) tuple[int]

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.

Returns:

_description_

Return type:

tuple[int]

static CodeDayOfWeek(day: str) int

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.

Raises:

Exception – Invalid day of the week.

Returns:

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

Return type:

int

static CodeDaySchedule(hours: list | tuple[bool | int], speed: int | list | tuple[int]) list[int]

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’ U8x24 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.

Returns:

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

Return type:

list[int]

static DecodeDayAndSchedule(dayschedule: bytes)
static DecodeDayOfWeek(day: int) str

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.

Returns:

Day of the week (‘Sunday’, ‘Monday’, etc.).

Return type:

str

static DecodeDaySchedule(schedule: bytes) dict[str, int | tuple[int]]

Interprets the return bytes from the command #142 ‘GET DAY SCHEDULE’.

Parameters:

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

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.

Return type:

dict[str,int|tuple[int]]

static DecodeLCDSchedule(schedule: bytes) dict[str, str | list[int]]

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.

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.

Return type:

dict[str,int|list[int]]

static GetCurrentTime() tuple[int]

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

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))

Return type:

tuple[int]

ReadPODpacket(validateChecksum: bool = True, timeout_sec: int | float = 5) PacketStandard

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:
  • validateChecksum (bool, optional) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

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

Returns:

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

Return type:

Packet

WritePacket(cmd: str | int, payload: int | bytes | tuple[int | bytes] | None = None) PacketStandard

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

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

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

Returns:

Packet that was written to the POD device.

Return type:

PacketStandard

static _CodeDecimalAsHex(val: int) int

Builds an integer that equals the val argument when converted into hexadecimal. All integers are converted to hexadecimal ASCII encoded bytes. Some commands (i.e. 8229 #140) need decimal ASCII encoded bytes; to do this, give the return value of _CodeDecimalAsHex() as the payload. Example: I want a number that is equal to 16 in hex. 1*16^1 + 6*16^0 = 22. Calling _CodeDecimalAsHex(16) will return 22.

Parameters:

val (int) – Unsigned integer number.

Returns:

integer that equals the val argument when converted into hexadecimal.

Return type:

int

static _Custom140SETTIME(payload: tuple[int]) tuple[int]

Custom function to translate the payload for command #140 SET TIME.

Parameters:

payload (tuple[int]) – Default translated payload.

Returns:

Tuple of times.

Return type:

tuple[int]

static _DecodeDecimalAsHex(val: int) int

Interprets an integer that was converted to a hexadecimal representation of a decimal value. In other words, this method reverses _CodeDecimalAsHex().

Parameters:

val (int) – Unsigned integer that was converted to a hexadecimal representation of a decimal value.

Returns:

Unsigned integer as a true decimal number.

Return type:

int

static _Validate_Day(day: str | int) int

Raises an exception if the day is incorrectly formatted. If the day is given as a string, it will be converted to its integer code.

Parameters:

day (str | int) – String day of the week or its repsective integer code.

Raises:
  • Exception – The day integer argument must be 0-6.

  • Exception – The day argument must be a str or int.

Returns:

Integer code representing a day of the week.

Return type:

int

static _Validate_Hours(hours: list | tuple[bool | int]) list[bool | int]

Raises an exception if the hours is incorrectly formatted. Converts the hours into a list before returning it.

Parameters:

hours (list | tuple[bool | int]) – Array with 24 items with values of 1/0 representing each hour

Raises:
  • Exception – The hours argument must be a list or tuple.

  • Exception – The hours argument must have exactly 24 items.

  • Exception – The hours items must be 0 or 1.

Returns:

List with 24 items for each hour. The values are 1/0.

Return type:

list[bool|int]

static _Validate_Schedule(schedule: bytes, size: int) bytes

Raises an exception if the schedule is incorrectly formatted

Parameters:
  • schedule (bytes) – Bytes string containing the day schedule.

  • size (int) – Number of U8 bytes.

Raises:
  • Exception – The schedule must be bytes.

  • Exception – The schedule is the incorrect size

Returns:

Same as the schedule argument.

Return type:

bytes

static _Validate_Speed(speed: int | list | tuple[int]) list[int]

Raises an exception if the speed is incorrectly formatted. If an integer speed is given, it will convert it to a list.

Parameters:

speed (int | list | tuple[int]) – Motor speed (0-100). This can either be an integer or a tuple/list of 24 speeds.

Raises:
  • Exception – The speed argument must be an int, list, or tuple.

  • Exception – The speed must be between 0 and 100.

  • Exception – The speed argument must have exactly 24 items as a list/tuple.

  • Exception – The speed must be between 0 and 100 for every list/tuple item.

Returns:

List containing 24 motor speeds.

Return type:

list[int]

Morelia.Devices.PodDevice_8274D module

class Morelia.Devices.PodDevice_8274D.Pod8274D(port: str | int, baudrate: int = 921600)

Bases: Pod

POD_8274D handles communication using an 8274D POD device.

WriteRead(cmd: str | int, payload: int | bytes | tuple[int | bytes] | None = None, validateChecksum: bool = True) Packet

Writes a command with optional payload to POD device, then reads (once) the device response. 8274D works differently compared to other devices as it is bluetooth based. Some commands require a re-read from the Pod Device, in order to get the right payload back. Each Get and Set Command will generate a Procedure Complete (command 211) indicating a successful write/read.

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

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

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

Returns:

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

There are some conditions for some commands. For example, if cmd is Local Scan, it returns Payload[1:7] because that will be the bluetooth address that can be used to connect to the device.

Return type:

Packet

Morelia.Devices.PodDevice_8401HR module

class Morelia.Devices.PodDevice_8401HR.Pod8401HR(port: str | int, ssGain: tuple | list | dict[str, int | None] = {'A': None, 'B': None, 'C': None, 'D': None}, preampGain: tuple | list | dict[str, int | None] = {'A': None, 'B': None, 'C': None, 'D': None}, baudrate: int = 9600)

Bases: Pod

POD_8401HR handles communication using an 8401-HR POD device.

_ssGain

Instance-level dictionary storing the second-stage gain for all four channels.

Type:

dict[str,int|None]

_preampGain

Instance-level dictionary storing the pramplifier gain for all four channels.

Type:

dict[str,int|None]

static CalculateBiasDAC_GetDACValue(vout: int | float) int

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

Parameters:

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

Returns:

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

Return type:

int

static CalculateBiasDAC_GetVout(value: int) float

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

Parameters:

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

Returns:

Float of the output bias voltage [V].

Return type:

float

static DecodeChannelBitmask(channels: bytes) dict[str, int]

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

Parameters:

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

Returns:

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

Return type:

dict[str,int]

static DecodeSSConfigBitmask(config: bytes)

Converts the SS configuration byte to a dictionary with the high-pass and gain. Use for ‘GET SS CONFIG’ command payloads.

Parameters:

config (bytes) – U8 byte containing the SS configurtation. Bit 0 = 0 for 0.5Hz Highpass, 1 for DC Highpass. Bit 1 = 0 for 5x gain, 1 for 1x gain.

static DecodeTTLByte(ttlByte: bytes) dict[str, int]

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

Parameters:

ttlByte (bytes) – U8 byte containing the TTL bitmask.

Returns:

Dictinoary with TTL name keys and integer TTL values.

Return type:

dict[str,int]

static DecodeTTLPayload(payload: bytes) tuple[dict[str, int]]

Decodes a paylaod with the two TTL bytes.

Parameters:

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

Returns:

Tuple with two TTL dictionaries.

Return type:

tuple[dict[str, int]]

static GetChannelBitmask(a: bool, b: bool, c: bool, d: bool) int

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.

Returns:

Integer representing a bitmask.

Return type:

int

static GetChannelMapForPreampDevice(preampName: str) dict[str, str] | None

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

Parameters:

preampName (str) – String for the device/sensor name.

Returns:

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

Return type:

dict[str,str]|None

static GetSSConfigBitmask(gain: int, highpass: float) int

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.

Returns:

Integer representing a bitmask.

Return type:

int

static GetSupportedPreampDevices() list[str]

Gets a list of device/sensor names used for channel mapping.

Returns:

List of string names of all supported sensors.

Return type:

list[str]

static GetTTLbitmask(ext0: bool = 0, ext1: bool = 0, ttl4: bool = 0, ttl3: bool = 0, ttl2: bool = 0, ttl1: bool = 0) int

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

Parameters:
  • ext0 (bool, optional) – boolean bit for ext0. Defaults to 0.

  • ext1 (bool, optional) – boolean bit for ext1. Defaults to 0.

  • ttl4 (bool, optional) – boolean bit for ttl4. Defaults to 0.

  • ttl3 (bool, optional) – boolean bit for ttl3. Defaults to 0.

  • ttl2 (bool, optional) – boolean bit for ttl2. Defaults to 0.

  • ttl1 (bool, optional) – boolean bit for ttl1. Defaults to 0.

Returns:

Integer number to be used as a bit mask.

Return type:

int

static IsPreampDeviceSupported(name: str) bool

Checks if the argument exists in channel map for all preamp sensors.

Parameters:

name (str) – name of the device

Returns:

True if the name exists in __CHANNELMAPALL, false otherwise.

Return type:

bool

ReadPODpacket(validateChecksum: bool = True, timeout_sec: int | float = 5) Packet

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:
  • validateChecksum (bool, optional) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

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

Returns:

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

Return type:

Packet

WritePacket(cmd: str | int, payload: int | bytes | tuple[int | bytes] | None = None) PacketStandard

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

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

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

Returns:

Packet that was written to the POD device.

Return type:

Packet_Standard

static _FixABCDtype(info: tuple | list | dict, thisIs: str = '') dict

Converts the info argument into a dictionary with A, B, C, and D as keys.

Parameters:
  • info (tuple | list | dict) – Variable to be converted into a dictionary.

  • thisIs (str, optional) – Description of the info argument, which is used in Exception statements. Defaults to ‘’.

Raises:
  • Exception – The dictionary has improper keys; keys must be [‘A’,’B’,’C’,’D’].

  • Exception – The argument must have only four values.

  • Exception – The argument must be a tuple, list, or dict.

Returns:

The info argument converted to a dictionary with A, B, C, and D as keys.

Return type:

dict

_Read_Binary(prePacket: bytes, validateChecksum: bool = True)

After receiving the prePacket, it reads the 23 bytes (binary data) and then reads to ETX.

Parameters:
  • prePacket (bytes) – Bytes string containing the beginning of a POD packet: STX (1 byte) + command number (4 bytes).

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

Raises:

Exception – Bad checksum for binary POD packet read.

static _ValidatePreampGain(preampGain: dict) None

Checks that the preamplifier gain dictionary has proper values (10, 100, or None).

Parameters:

preampGain (dict) – preamplifier gain dictionary.

Raises:

Exception – EEG/EMG preampGain must be 10 or 100. For biosensors, the preampGain is None.

static _ValidateSsGain(ssgain: dict)

Checks that the second stage gain dictionary has proper values (1, 5, or None).

Parameters:

ssgain (dict) – Second stage gain dictionary.

Raises:

Exception – The ssGain must be 1 or 5; set ssGain to None if no-connect.

__CHANNELMAPALL: dict[str, dict[str, str]] = {'8406-2BIO': {'A': 'Bio1', 'B': 'Bio2', 'C': 'NC', 'D': 'NC'}, '8406-BIO': {'A': 'Bio', 'B': 'NC', 'C': 'NC', 'D': 'NC'}, '8406-EEG2BIO': {'A': 'Bio1', 'B': 'EEG1', 'C': 'EMG', 'D': 'Bio2'}, '8406-SE': {'A': 'Bio', 'B': 'EEG1', 'C': 'EMG', 'D': 'EEG2'}, '8406-SE3': {'A': 'Bio', 'B': 'EEG1', 'C': 'EEG3', 'D': 'EEG2'}, '8406-SE31M': {'A': 'EMG', 'B': 'EEG1', 'C': 'EEG3', 'D': 'EEG2'}, '8406-SE4': {'A': 'EEG4', 'B': 'EEG1', 'C': 'EEG3', 'D': 'EEG2'}, '8406-SL': {'A': 'Bio', 'B': 'EEG1', 'C': 'EMG', 'D': 'EEG2'}, '8407-SE': {'A': 'Bio', 'B': 'EEG1', 'C': 'EMG', 'D': 'EEG2'}, '8407-SE-2BIO': {'A': 'Bio1', 'B': 'Bio2', 'C': 'EMG', 'D': 'EEG2'}, '8407-SE3': {'A': 'Bio', 'B': 'EEG1', 'C': 'EEG3', 'D': 'EEG2'}, '8407-SE31M': {'A': 'EEG3', 'B': 'EEG1', 'C': 'EMG', 'D': 'EEG2'}, '8407-SE4': {'A': 'EEG4', 'B': 'EEG1', 'C': 'EEG3', 'D': 'EEG2'}, '8407-SL': {'A': 'Bio', 'B': 'EEG1', 'C': 'EMG', 'D': 'EEG2'}, '8407-SL-2BIO': {'A': 'Bio1', 'B': 'Bio2', 'C': 'EMG', 'D': 'EEG2'}}

Class-level dictionary containing the channel map for all preamplifier devices.

Morelia.Devices.PodDevice_8480SC module

class Morelia.Devices.PodDevice_8480SC.Pod8480SC(port: str | int, baudrate: int = 9600)

Bases: Pod

POD_8480SC handles communication using an 8480-SC POD device.

static DecodeStimulusConfigBits(config: int) dict

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.

Returns:

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

Return type:

dict

static DecodeSyncConfigBits(config: int) dict

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.

Returns:

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

Return type:

dict

static DecodeTTlConfigBits(config: int) dict

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.

Returns:

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

Return type:

dict

ReadPODpacket(validateChecksum: bool = True, timeout_sec: int | float = 5) PacketStandard

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:
  • validateChecksum (bool, optional) – Set to True to validate the checksum. Set to False to skip validation. Defaults to True.

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

Returns:

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

Return type:

Packet

static StimulusConfigBits(optoElec: bool, monoBiphasic: bool, Simul: bool) int

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.

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’.

Return type:

int

static SyncConfigBits(sync_level: bool, sync_idle: bool, signal_trigger: bool) int

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.

Returns:

which represents the Sync Config Bits format value.

Return type:

int

static TtlConfigBits(trigger: bool, stimtrig: bool, input_sync: bool) int

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.

Returns:

which represents the TTL Config Bits Format value.

Return type:

int

WritePacket(cmd: str | int, payload: int | bytes | tuple[int | bytes] | None = None) PacketStandard

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

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

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

Returns:

Packet that was written to the POD device.

Return type:

Packet_Standard

static _Custom108GETTTLSETUP(payload: bytes) tuple[int | dict]

Custom function to translate the TTL setup for command #108 GET TTL SETUP.

Parameters:

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

Returns:

Tuple of the TTL setup.

Return type:

tuple[int|dict]

static _Custom109SETTTLSETUP(payload: bytes) tuple[int | dict]

Custom function to translate the TTL setup for command #109 SET TTL SETUP.

Parameters:

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

Returns:

Tuple of the TTL setup.

Return type:

tuple[int|dict]

static _CustomSTIMULUS(payload: bytes, defaultPayload: tuple) tuple

_summary_

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

  • defaultPayload (tuple) – Default translated payload.

Returns:

Tuple of the translated stimulus payload.

Return type:

tuple

static _CustomSYNCCONFIG(payload: bytes) dict

Custom function to translate the sync config.

Parameters:

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

Returns:

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

Return type:

dict

Module contents