| optoMDC

Functions
optoKummenberg.tools.command_tools Namespace Reference

## Functions
def | issue_command (board, command_bytes, float cmd_delay=None)
def | attempt_reconnect (board)
def | process_simple_response (board, str process_name, bytes received_response)
def | process_response (int command_id_sent, register, value, response, verbose=False)
def | get_cmd_reg_val (command, dict or list or int register, value=None)

## Function Documentation

## ◆ attempt_reconnect()

def optoKummenberg.tools.command_tools.attempt_reconnect | ( |  | board | ) |

    Will attempt to reconnect to board. Will attempt 3 times.

    Parameters
    ----------
    board : Board
        The board to attempt reconnect.

    Returns
    -------
    none

    Raises
    ------
    Upon failure, will dump serial information.

## ◆ get_cmd_reg_val()

def optoKummenberg.tools.command_tools.get_cmd_reg_val | ( |  | command,
|  | dict or list or int | register,
|  |  | value = `None`
| ) |  |

    Given register(s) and value(s) will return command_id, register_id, value.

    Parameters
    ----------
    command : string or int related to command type 'SET_VALUE', 'GET_VALUE', etc with no determination of MULTIPLE
    register : dict or list of dicts or int or list of ints
        Register dictionary corresponding to desired registers.{'id': registers number, 'type': data type, ...}
        Further, a raw registers id can be passed, in which case no validation will occur (COULD CAUSE ERRORS).
    value : varies, can also be list of values
        The type and range of value is dependent on the registers being addressed, see 'type' element above.

    Returns
    -------
    cmd_id
        Hex value corresponding to proper command (1 Byte).
    reg_id
        Hex value corresponding to proper register (2 Bytes).
    value
        Validated value for the given register.

    Raises
    ------
    none

    See Also
    --------
    Register IDs, value type and range can be found in the registers module.

    Examples
    --------
    In this example, set value command for static input OF on channel 1 to 0.1 is expected.

    >>> from optoKummenberg.registers.generic_registers import StaticInput
    >>> res=get_cmd_register_value(0x10, 0x5100, 0.1)
    >>> print(encode(*res))
    b'~\x00\x10\x06Q\x00=\xcc\xcc\xcd\x00\x00~'
    >>> res=get_cmd_register_value(commandID['SET_VALUE'], StaticInput(1).current, 0.1)
    >>> print(encode(*res))
    b'~\x00\x10\x06Q\x00=\xcc\xcc\xcd\x00\x00~'
    >>> res=get_cmd_register_value('SET_VALUE', StaticInput(1).current, 0.1)
    >>> print(encode(*res))
    b'~\x00\x10\x06Q\x00=\xcc\xcc\xcd\x00\x00~'

    You can see these results are the same, thus any of these methods are valid.

## ◆ issue_command()

def optoKummenberg.tools.command_tools.issue_command | ( |  | board,
|  |  | command_bytes,
|  | float | cmd_delay = `None`
| ) |  |

    Issues given command_bytes over _board connection. Will attempt 3 times.

    This method unlocks the comm_lock, sends the desired data, receives a response, then reapplies the lock.

    Parameters
    ----------
    board : Board
        The board to issue a command over.
    command_bytes : bytes or int or str
        The byte array to send over the connection.

    Returns
    -------
    str
        Firmware response, contains acknowledgement or parse_error information. In DEBUG mode this returns the internal state.

    Raises
    ------
    none

    See Also
    --------
    Command bytes must be properly encoded, see registers encode function.

## ◆ process_response()

def optoKummenberg.tools.command_tools.process_response | ( | int | command_id_sent,
|  |  | register,
|  |  | value,
|  |  | response,
|  |  | verbose = `False`
| ) |  |

    Processes firmware response.

    Parameters
    ----------
    command_id_sent : int
        The attempted command, see: commandID dictionary for potential values.
    register : dict or list of dicts or int or list of ints
        Register dictionary corresponding to desired registers.{'id': registers number, 'type': data type, ...}
    value
        The value or values that were originally destined to be transmitted.
    response : bytes or int or str
        Firmware response.
    verbose : bool = False
        Output verbosity.
    simulated : bool = False
        Whether connection over port is simulated, thus response is simulated.

    Returns
    -------
    slave_id, command_id, response_data, crc
        Decoded firmware response

    Raises
    ------
    none

## ◆ process_simple_response()

def optoKummenberg.tools.command_tools.process_simple_response | ( |  | board,
|  | str | process_name,
|  | bytes | received_response
| ) |  |

    Processes firmware simple response to determine if successful.

    Parameters
    ----------
    board : Board
        The object sending/receiving.
    process_name : str
        The name of the attempted process, for output statement.
    received_response : bytes
        The response received over the communication channel.

    Returns
    -------
    processed_response or error_response
        Decoded firmware response

    Raises
    ------
    none