Morelia.Devices packageο
Subpackagesο
Submodulesο
Morelia.Devices.BasicPodProtocol moduleο
- class Morelia.Devices.BasicPodProtocol.Pod(port, baudrate=9600, device_name=None)ο
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. 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 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.
- 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.
- 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_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_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.
- 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.
- 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:
- 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).
- 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.
- 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:
- 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:
- 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)ο
Bases:
AquisitionDevice
Pod8206HR is used to interact with a 8206HR data aquisition device.
- Parameters:
port (
str
|int
) β Serial port to be opened. Used when initializing the COM_io instance.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.
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:
AquisitionDevice
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)ο
Bases:
AquisitionDevice
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.
- 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].
- 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. Use for
GET SS CONFIG
command payloads.- Parameters:
config (
bytes
) β UINT8 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.- Return type:
dict
[str
,Union
[float
,int
]]
- static decode_ttl_byte(ttl_byte)ο
Converts the TTL bytes argument into a dictionary of integer TTL values.
- Parameters:
ttl_byte (
bytes
) β UINT8 byte containing the TTL bitmask.- Return type:
dict
[str
,int
]- Returns:
Dictinoary 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.
- 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.
- 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.
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.aquisition_device moduleο
POD device that streams data.
- class Morelia.Devices.aquisition_device.AquisitionDevice(port, max_sample_rate, baudrate=9600, device_name=None, get_sample_rate_cmd_no=100, set_sample_rate_cmd_no=101)ο
Bases:
Pod
This class is the parent of any device that can stream (i.e. data aquisiton devices).
- Parameters:
port (
str
|int
) β Serial port to be opened. Used when initializing the COM_io instance.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 theGET SAMPLE RATE
command on the device.set_sample_rate_cmd_no (
int
) β Command number for theSET SAMPLE RATE
command on the device.
- property max_sample_rate: intο
Maximum allowable sample rate.
- property sample_rate: intο
Currently set sample rate.
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ο