Example #1
0
def move_2d():
    config_form = g.get("scopeconfig_form")
    scan_form = g.get("move2d_form")

    if scan_form.move2d.data and scan_form.validate_on_submit():
        scan_name = "Unnamed"
        if (scan_form.name.data):
            scan_name = scan_form.name.data

        if scan_form.axis_secondary_radio.data in scan_form.axis_radio.data:
            flash(helper.ERROR['SAME_AXIS'], helper.FLASH_ERROR)
        else:
            data = {
                'name': scan_name,
                'primary_axis': scan_form.axis_radio.data,
                'direction': scan_form.direction_radio.data,
                'steps': scan_form.steps.data,
                'acquisition_rate': scan_form.acquisition_rate.data,
                'secondary_axis': scan_form.axis_secondary_radio.data,
                'acquisition_offset_rate':
                scan_form.acquisition_offset_rate.data,
                'secondary_axis_step_size':
                scan_form.secondary_axis_step_size.data
            }

            response = requests.post_data(endpoint.scan, data)

            if (response):
                flash(
                    helper.SCAN_OK.format(scan_name,
                                          response.json()['filename']))
            else:
                flash(helper.ERROR['SCAN_EXCEPTION'], helper.FLASH_ERROR)

    elif config_form.set_config.data and config_form.validate_on_submit():
        data = wrap_configs(config_form)

        response = requests.post_data(endpoint.set_scope_config, data)

        if (response):
            flash(helper.SET_CONFIG_OK)
        else:
            flash(helper.ERROR['SET_CONFIG_EXCEPTION'], helper.FLASH_ERROR)

    return render_template("move2d.html",
                           scan_form=scan_form,
                           config_form=config_form)
Example #2
0
    def post(self, axis):
        settings.start_run("SingleAxisMoveAndCapture")

        if axis in axis_list:

            try:
                args = self.reqparse.parse_args()
                name = args['name']
                acquisition_rate = args['acquisition_rate']
                direction = args['direction']
                full_path = args['steps']
            except Exception as e:
                logging.exception(e)
                abort(500, cause=helper.FIELDS(), error=str(e))

            response_list = []

            for i in range(0, full_path, acquisition_rate):
                data = {
                    'direction': direction,
                    'steps': acquisition_rate,
                    'acknowledge': True
                }
                response = post_data(
                    endpoint.move + "/{}".format(axis_list.get(axis)), data,
                    True)

                response_node = str(response.json()['response'])

                if response_node == "ao" or response_node == "a":
                    acquired_data = get_data(endpoint.acquire).json()
                    if (acquired_data):
                        response_list.append(acquired_data)
                    else:
                        abort(500, message=helper.ERROR['SCOPE_EXCEPTION'])
                else:
                    abort(500, message=helper.ERROR['MOTOR_EXCEPTION'])

            settings.end_run()

            try:
                filename = filemg.create_uuid_filename()
                filemg.save(str({'acquired_data': response_list}),
                            filemg.captures_path + filename)
                db.save_capture(filename, [
                    unicode(name) or helper.DEFAULT_CAPTURE_NAME,
                    time.time()
                ])
                return {'filename': filename}, 200
            except Exception as e:
                logging.exception(e)
                abort(500, message=helper.ERROR['CREATE_FILE_EXCEPTION'])
        else:
            abort(400, message=helper.MOVE['primary_axis'])
def move_to_direction():
    print(request.data)

    data = json.loads(request.data)
    axis = data['axis']
    direction = data['direction']
    data = {'direction': direction, 'steps': 5}
    response = requests.post_data(endpoint.move + "/{}".format(axis), data)

    if (response):
        flash(helper.MOVE_OK.format(response.status_code))
    else:
        flash(helper.ERROR['UNFINISHED'], helper.FLASH_ERROR)

    return render_template("manual_move.html")
	def post(self):
		try:
			args = self.reqparse.parse_args()
			channel = args['channel']
			frequency = args['frequency']
			cycles = args['cycles']
			averaging = args['averaging']
			v_scale = args['v_scale']
			t_scale = args['t_scale']
		except Exception as e:
			abort(500)

		data = { 
			'channel': channel,
			'frequency': frequency,
			'cycles': cycles,
			'averaging': averaging,
			'v_scale': float(v_scale),
			't_scale': float(t_scale) 
		}

		return post_data(endpoint.scope_config, data).json()
Example #5
0
    def post(self, axis):
        settings.start_run("SingleAxisMove")
        finished = False

        if axis in axis_list:

            try:
                args = self.reqparse.parse_args()
                name = args['name']
                direction = args['direction']
                steps = args['steps']
            except Exception as e:
                logging.exception(e)
                abort(500, cause=helper.FIELDS(), error=str(e))

            data = {
                'direction': direction,
                'steps': steps,
                'acknowledge': True
            }
            response = post_data(
                endpoint.move + "/{}".format(axis_list.get(axis)), data, True)

            response = str(response.json()['response'])

            if response == "ao" or response == "a":
                finished = True
            else:
                abort(500, message=helper.ERROR['MOTOR_EXCEPTION'])

            if finished:
                settings.end_run()
                return {'message': 'OK'}, 200
            else:
                abort(500, message=helper.ERROR['UNFINISHED'])
        else:
            abort(400, message=helper.MOVE['primary_axis'])
def send_abort_signal():
    response = requests.post_data(endpoint.abort)
    return helper.ABORT_OK.format(response.status_code)