Python Forum
Problem: Once I cancel the process my program will start working!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem: Once I cancel the process my program will start working!
#1
I am trying to control the frequency sampling rate of my dial_tone python code through a AJAX for to flask server. The problem is when I start running the program and start sliding/dragging the round slider to change the freq samp value it doesn't have any impact! It doesn't run the 'tone' sound. And once I cancel the process on the Terminal (ctrl + c) the program will operate and I start hearing the tone! Any help to solve this problem will be highly appreciated.

This is the Python code:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Top Block 22
# Generated: Tue Jul 23 15:54:16 2019
##################################################
  
  
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
from flask import Flask, render_template, jsonify, request, redirect, url_for
from random import randint
app = Flask(__name__)
  
  
class top_block_22(gr.top_block):
  
    def __init__(self):
        gr.top_block.__init__(self, "Top Block 22")
  
        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000
  
        ##################################################
        # Blocks
        ##################################################
        self.blocks_add_xx = blocks.add_vff(1)
        self.audio_sink = audio.sink(32000, '', True)
        self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 440, 0.4, 0)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350, 0.4, 0)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.005, -42)
  
        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 2))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
        self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx, 1))
        self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))
  
  
    @app.route('/')
    def hex_color():
            return render_template("index.html")
           
    @app.route('/valueofslider')
    def slide():
            samp_rate = request.args.get('samp_rate')
            print(samp_rate)
            return samp_rate 
  
def main(top_block_cls=top_block_22, options=None):
  
  
  
    tb = top_block_cls()
    tb.start()
    try:
        raw_input('Press Enter to quit: ')
    except EOFError:
        pass
    tb.stop()
    tb.wait()
  
if __name__ == '__main__':
    app.run(debug=True)
  
if __name__ == '__main__':
    main()
The html code is:

Python Code: (Double-click to select all)
The html code is:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>jQuery roundSlider - JS Bin</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"></script>
</head>
<body>
  <!-- Only html needed   -->
  <div id="slider"></div>
     
  <script>
    var val;
    $("#slider").roundSlider({
      radius: 215,
        min: 0,
        max: 40000,
  
      change: function () {
        var obj1 = $("#slider").data("roundSlider");
        val = obj1.getValue();
        value: 1
        $.getJSON('/valueofslider', {
          samp_rate: val
        });
      }
    });
  </script>
</body>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Confirm / Cancel button in Python & Flask ladak 0 750 Mar-18-2023, 11:26 AM
Last Post: ladak
  How to start the program from the beginning. iamaghost 5 2,872 Feb-23-2021, 03:40 AM
Last Post: deanhystad
  I have problem with ACO, I want to always start in the first city and end in the last pKKy 0 1,517 Jan-28-2021, 05:58 PM
Last Post: pKKy
  Start my program in RPI4B from SSH and Failed ATARI_LIVE 3 3,435 Nov-11-2020, 11:19 AM
Last Post: ATARI_LIVE
  how to cancel scheduler module event nanok66 0 2,097 May-11-2020, 10:31 PM
Last Post: nanok66
  pydev debugger: process 3442 is connecting when I run a program with ALT+COMMAND+R Seneca260 1 2,607 Jan-06-2020, 06:57 PM
Last Post: micseydel
  Cleanest Way to Cancel a ThreadPool SvetlanaofVodianova 0 1,578 Dec-10-2019, 06:25 PM
Last Post: SvetlanaofVodianova
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,617 Sep-03-2019, 09:49 PM
Last Post: woooee
  Program Problem (2) ChrisG 2 2,358 May-25-2019, 05:11 PM
Last Post: ChrisG
  Program Problem ChrisG 2 1,939 May-25-2019, 11:41 AM
Last Post: ChrisG

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020