estim2py package

Submodules

estim2py.connection module

type estim2py.connection.ChannelName = str

Type used to refer to channel names: A B C D.

type estim2py.connection.ChannelVal = int

Type used to refer to a channel value: 0-100.

class estim2py.connection.Estim2pyConnection(device: str, timeout: float = 2, delay: float = 0.04, do_flush: bool = False)

Bases: object

Connect to the Estim 2b box, and manage communication

All method calls will return an Estim2pyStatus object.

A note about the delay. This needs to be at least 0.034, as that is the amount of time it takes to send 33 bytes over the serial wire. That doesn’t necessarily give any time for the 2B to act. 0.10 (the default) is extremely safe.

args: device - the serial device to connect with.

keywords: timeout - Serial timeout, sent straight to pyserial delay - enforced delay. This gives the 2b enough time to act, and then respond. do_flush - whether or not to flush input on status retrieval. This is probably witchcraft and can be left as false.

BAUD: int = 9600
BYTESIZE: int = 8
MODE_MAX: int = 100
PARITY: str = 'N'
STOPBITS: int = 1
TERMINATION_CHAR: Literal[b'\n'] = b'\n'
get_status()

Returns a Estim2pyStatus object

high()

Sets the box to high power mode and returns Estim2pyStatus

kill()

Sets channels A and B to 0 and returns Estim2pyStatus

Enable’s link mode and returns Estim2pyStatus. Note, does not work on my box!

low()

Sets the box to low power mode and returns Estim2pyStatus

reset()

Resets the box and returns Estim2pyStatus

set_a(val: ChannelVal) → Estim2pyStatus

Set channel A to val

set_b(val: ChannelVal) → Estim2pyStatus

Set channel B to val

set_c(val: ChannelVal) → Estim2pyStatus

Set channel C to val

set_channel(channel: ChannelName, val: ChannelVal)

Set’s the channel to value val.

Will throw a ValueError if: The channel is not a,b,c or d (upper or lowercase) The val is notan integer between 0-100 for A and B, 2-100 for C, or 1-100 for D

args: channel (str): A or B for power channels, C for Speed, D for Feeling. (generally) val (int): 1-100 for A or B, 2-100 for C, 1-100 for D

returns: Estim2pyStatus

set_d(val: ChannelVal) → Estim2pyStatus

Set channel D to val

set_mode(mode_num: int) → Estim2pyStatus

Sets the mode to the numbered mode and returns Estim2pyStatus.

Doesn’t accept arguments over 100. Note that my box only accepts up to 13. (I might need an update.)

args: mode_num (int): mode number to set to.

set_to_status(to_status: Estim2pyStatus) → bool

Change all settings to the input status. Returns a success boolean.

This will cowardly set the link to 0 before trying to send all the statuses Until I figure out what is wrong with channel link.

args: to_status (Estim2pyStatus): target status.

returns: True if all parameters were set, false if there was a mismatch.

Enable’s link mode and returns Estim2pyStatus. Note, does not work on my box!

estim2py.exceptions module

exception estim2py.exceptions.Estim2pyError(message: str, data: str | None = None)

Bases: Exception

estim2py.modes module

class estim2py.modes.Estim2pyMode(mid: int, name: str, param_a: str, param_b: str | None, notes: str)

Bases: object

A class representing a mode for the Estim 2b.

Construct with Estim2pyMode.get_mode(int). That will return the relevant mode by integer id.

classmethod get_mode(mid: int)

Returns the mode based on the integer id.

classmethod id_names() → dict[int, str]

returns a dictionary of {modeid: name, …}

i.e. {0: “pulse”, 1: “bounce”, …}

mid: int

numeric id of the mode.

modes: dict[int, tuple[str, str, str | None, str]] = {0: ('pulse', 'pulse speed', 'pulse feel', 'Pulsing on and off'), 1: ('bounce', 'pulse speed', 'pulse feel', 'Pulsing alternatively'), 2: ('continuous', 'pulse feel', None, 'Both channels always on'), 3: ('asplit', 'pulse speed', 'pulse feel', 'A Pulse B Continuous'), 4: ('bsplit', 'pulse speed', 'pulse feel', 'B Pulse A Continuous'), 5: ('wave', 'speed of increase', 'wave feel', 'Output increases to power, then to 0'), 6: ('waterfall', 'speed of increase / decrease', 'waterfall feel', 'Output to power, then back down'), 7: ('squeeze', 'pulse speed', 'feel', 'Pulse rate increases and then drops to slow'), 8: ('milk', 'pulse speed', 'feel', 'Pulse rate increases and then drops to slow, b channel alternates'), 9: ('throb', 'feel range', None, 'Continuous, with the feel increasing to range and dropping to 0'), 10: ('thrust', 'feel range', None, 'Continuous, with the feel increasing to range and decreasing'), 11: ('random', 'random range', 'pulse feel', 'Random Levels'), 12: ('step', 'step delay', 'pulse feel', 'Builds towards a power level slowly'), 13: ('training', 'jump delay', 'pulse feel', 'Jumps to the power level quickly')}

List of modes that this class knows about. Access directly if you like!

name: str

Short name of the mode.

notes: str

A real short description of the mode.

param_a: str

What channel C modifies.

param_b: str | None

What channel D modifies, or None if not applicable

estim2py.simulated module

class estim2py.simulated.Estim2pySimulatedConnection

Bases: Estim2pyConnection

This is a sumulated 2B box, so you don’t always have to plug a box in to write code. It should behave exactly like the real box.

If it doesn’t… that’s a bug!

The interface is exactly like Estim2pyConnection.

error_on_next(do_throw=True)

Simulate an error on the next command.

Error will only happen once. After that normal behavior will continue. You can send it False to not error on the next command.

get_status()

Returns a Estim2pyStatus object

high()

Sets the box to high power mode and returns Estim2pyStatus

kill()

Sets channels A and B to 0 and returns Estim2pyStatus

Enable’s link mode and returns Estim2pyStatus. Note, does not work on my box!

low()

Sets the box to low power mode and returns Estim2pyStatus

reset()

Resets the box and returns Estim2pyStatus

reset_status()

Manually reset the status to the default state.

set_channel(channel, val)

Set’s the channel to value val.

Will throw a ValueError if: The channel is not a,b,c or d (upper or lowercase) The val is notan integer between 0-100 for A and B, 2-100 for C, or 1-100 for D

args: channel (str): A or B for power channels, C for Speed, D for Feeling. (generally) val (int): 1-100 for A or B, 2-100 for C, 1-100 for D

returns: Estim2pyStatus

set_mode(mode_num)

Sets the mode to the numbered mode and returns Estim2pyStatus.

Doesn’t accept arguments over 100. Note that my box only accepts up to 13. (I might need an update.)

args: mode_num (int): mode number to set to.

simulate()

Enable’s link mode and returns Estim2pyStatus. Note, does not work on my box!

estim2py.status module

class estim2py.status.Estim2pyStatus(battery: int, a: int, b: int, c: int, d: int, mode: int, power: str, linked: int, version: str)

Bases: object

An object that reports back the status of the Estim Box.

Object members are direct from the serial port. Object methods relate closer to what the box displays and return useful python objects.

i.e. status.a will return 200 at max power, but get_channel(‘a’) will return 100.

as_items() → tuple[tuple[str, int], tuple[str, int], tuple[str, int], tuple[str, int], tuple[str, int], tuple[str, int], tuple[str, str], tuple[str, int], tuple[str, str]]

Returns an items-like representation of the status.

It’s ‘items-like’ in that you can use it for iteration, but modifying the values of the tuples inside the dictionary does nothing.

NOTE, this is the raw values from the serial port.

changes(other: Estim2PyStatus) → None | tuple

Returns a tuple of value-names that are different between two values

static from_binary(bin: bytes)

Return an Estim2pyStatus object from bytes.

This is mostly internal, but may be useful in some circumstances. Check unit tests.

get_a() → int
get_b() → int
get_c() → int
get_channel(channel: str) → int

Returns the value of the channel as reported by UI on the box.

Channel must be a,b,c or d (upper or lower). The value is what is displayed on the LCD, which is half of that reported on the serial port.

This value is compatible with Estim2pyConnection.set_channel().

get_d() → int
get_mode() → Estim2pyMode

Returns an Estim2pyMode representing the current mode.

See Estim2pyMode for more information.

is_high_power()

Returns True if the box is in high power mode, False otherwise.

is_linked()

Return True if the box is in linked mode, False otherwise.

is_low_power()

Returns True if the box is in low power mode, False otherwise.

is_unlinked()

Returns True if the box is in unlinked mode, False otherwise.

Module contents