Main module — GramophoneTools 0.6.22-beta documentation

# Main module

This is the module that handles all the communication with the current Gramophone device.

## Gramophone class

class `Gramophone.` `Gramophone`(device, verbose=False)

  Representation of a Gramophone device.

  Parameters: | device (bool) – The USB device. verbose – If set to True the details of the communication are printed.

  class `Parameter`(name, info, type)
    `info`

      Alias for field number 1

    `name`

      Alias for field number 0

    `type`

      Alias for field number 2

  `decode_payload`(param_id, payload)

    Decodes the given payload based on the type of the parameter.

    Parameters: | param_id (int) – The key for the parameter dict. See: Gramophone.parameters payload (list) – The payload that will be decoded

  `decode_response`(response)

    Decodes a response. Returns the error message if the command was not successful and None otherwise.

    Parameters: | response – The response to decode.
    Ptype response: | Packet

  `ping`()

    Send a ping packet with 5 bytes and print the time the process took.

  `read_analog_out`()

    Read the voltage of the analog output.

    Returns: | The voltage the analog output is set to.
    Return type: | float

  `read_dev_state`()

    Read the state of the device. The device should be in 0x01 state for usage. The 0x00 state is for setup.

    Returns: | The device state. ‘Application’ or ‘IAP’
    Return type: | str

  `read_firmware_info`()

    Read the firmware information from the Gramophone. Sets the fimware related variables of the object.

    Returns: | A dictionary with the firmware info fields in a human readable format.
    Return type: | dict

  `read_homing_position`()

    The home postion that can be found by homing.

    Returns: | The position
    Return type: | int

  `read_homing_state`()

    Reads wheter the device is homing. A home position can be set and this value changes when it is reached. 0 if the encoder is not trying to find the home position, 1 if it is homing and 2 if the home position was found.

    Returns: | 0, 1 or 2 dependin on the state
    Return type: | int

  `read_input`(input_id)

    Read the state of a digital input.

    Parameters: | input_id (int) – The number of the digital input (1 or 2)
    Returns: | 0 if the input is low, 1 if it is high
    Return type: | int

  `read_inputs`()

    Read the state of all digital inputs.

    Returns: | dict with input numbers as keys, and their states as values. eg: {1:1, 2:1} when both inputs are high
    Return type: | dict

  `read_linmaze_params`()

    Read the parameters for the LineMaze module. Time, position, and IO combined.

    Retruns: | A dict with the read parameters, with ids as keys
    Return type: | dict

  `read_output`(output_id)

    Read the state of a digital output.

    Parameters: | output_id (int) – The number of the digital output (1 to 4)
    Returns: | 0 if the output is low, 1 if it is high
    Return type: | int

  `read_outputs`()

    Read the state of all digital outputs.

    Returns: | dict with output numbers as keys, and their states as values. eg: {1:0, 2:0, 3:0, 4:0} when both outputs are low
    Return type: | dict

  `read_param`(param_id)

    Read a single parameter and return its value.

    Parameters: | param_id (int) – The id of the parameter that should be read.
    Returns: | The value of the parameter
    Return type: | depends on the parameter, see: Gramophone.parameters

  `read_params`(combo_id)

    Read multiple parameters and return them in a dict.

  `read_position`()

    Read the position register of the Gramophone.

    Returns: | The position in counts travelled (1 full rotation = 14400 counts)
    Return type: | int

  `read_product_info`()

    Read the product information from the Gramophone. Sets the product related variables of the object.

    Returns: | A dictionary with the product info fields in a human readable format.
    Return type: | dict

  `read_recorder_params`()

    Read the parameters for the Recorder module. Time, velocity, and IO combined.

    Retruns: | A dict with the read parameters, with ids as keys
    Return type: | dict

  `read_sensors`()

    Read the values from the voltage and temperature sensors.

    Returns: | A dict with the parameter ids as keys. See: Gramophone.parameters
    Return type: | dict

  `read_temperatures`()

    Read the values from the temperature sensors.

    Returns: | A dict with the parameter ids as keys. See: Gramophone.parameters
    Return type: | dict

  `read_time`()

    Read the time from the Gramophone’s clock

    Returns: | Time in ms/10
    Return type: | int

  `read_velocity`()

    Read the velocity of the Gramophones disk. Velocity is averaged in a window with a set size.

    Returns: | Velocity in counts/sec (1 full rotation = 14400 counts)
    Return type: |

  `read_voltages`()

    Read the values from the voltage sensors.

    Returns: | A dict with the parameter ids as keys. See: Gramophone.parameters
    Return type: | dict

  `read_window_size`()

    Read the window size of the velocity calculation, ie. how many position differences are averaged to get the velocity. Larger windows result in smoother velocity but slower response.

    Retruns: | The window size
    Return type: | int

  `reset`()

    Reset the device. Returns None if successful and the error string otherwise.

  `reset_position`()

    Reset the Gramophone’s internal position counter to 0.

  `reset_time`()

    Reset the Gramophone’s internal clock to 0.

  `send`(packet)

    Sends a Packet to the device.

    Parameters: | packet – The Packet to send.
    Ptype packet: | Packet

  `write_analog`(value)

    Set the analog output to the given voltage, eg. to 2.1 V

    Parameters: | value (float) – The voltage that will be set.

  `write_output`(output, value)

    Set the given output to a given state, eg. output 1 to 1 (high).

    Parameters: | output (int) – The output to set (1 to 4) value (int) – The state to set (1 is high, 0 is low)

## Helper classes

class `Gramophone.` `Packet`(target, source, cmd, payload, msn=None)

  A 64 byte data packet that can be sent to the Gramophone.

class `Gramophone.` `GramophoneError`

  Exception for Gramophone related communication errors.