Main module¶
This is the module that handles all the communication with the current Gramophone device.
Gramophone class¶
-
class
Gramophone.
Gramophone
(device, verbose=False)[source]¶ Representation of a Gramophone device.
Parameters: - device (usb.core.Device) – The USB device.
- verbose (bool) – 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)[source]¶ 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)[source]¶ 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
-
read_analog_out
()[source]¶ Read the voltage of the analog output.
Returns: The voltage the analog output is set to. Return type: float
-
read_dev_state
()[source]¶ 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
()[source]¶ 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
()[source]¶ The home postion that can be found by homing.
Returns: The position Return type: int
-
read_homing_state
()[source]¶ 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)[source]¶ 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
()[source]¶ 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
()[source]¶ 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)[source]¶ 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
()[source]¶ 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)[source]¶ 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_position
()[source]¶ Read the position register of the Gramophone.
Returns: The position in counts travelled (1 full rotation = 14400 counts) Return type: int
-
read_product_info
()[source]¶ 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
()[source]¶ 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
()[source]¶ 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
()[source]¶ Read the values from the temperature sensors.
Returns: A dict with the parameter ids as keys. See: Gramophone.parameters Return type: dict
-
read_time
()[source]¶ Read the time from the Gramophone’s clock
Returns: Time in ms/10 Return type: int
-
read_velocity
()[source]¶ 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
()[source]¶ 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
()[source]¶ 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
-
send
(packet)[source]¶ Sends a Packet to the device.
Parameters: packet – The Packet to send. Ptype packet: Packet
-
stop_burst
(port)[source]¶ Stop turning the given port on and off. see: start_burst
Parameters: port (int (1-4)) – The port that will stop being turned on and off
-
write_analog
(value)[source]¶ Set the analog output to the given voltage, eg. to 2.1 V
Parameters: value (float) – The voltage that will be set.
Helper classes¶
-
class
Gramophone.
Packet
(target, source, cmd, payload, msn=None)[source]¶ A 64 byte data packet that can be sent to the Gramophone.
Parameters: - target ([int, int]) – 2 byte address of the target. source of the reply given to this packet
- source ([int, int]) – 2 byte address of the source. target of the reply given to this packet
- cmd (int) – Identifier of the command
- payload (list of ints) – The payload for the command eg.: the value to write
- msn (int) – Any number. The reply packet’s msn will be the same.