Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. shell script in qt not changing the value

shell script in qt not changing the value

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 564 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wasee
    wrote on 25 Jan 2022, 10:20 last edited by
    #1

    Hi everyone help required!
    I pass two values in shell script when script runs then Two RX_LO run in device one at 2425000000 and other at 2475000000 within script when my Rx_LO at 2425000000 then it out value at Tx_LO at 2425000000 but when my value change for other one at 2475000000 then its still gave me value for Tx_LO at 2425000000 previous value of first one. How I can change it according new for second LO?

    void secbox::dds_control(){
                 QProcess proc;
                 QStringList args;
    
                 proc.setProcessChannelMode(QProcess::MergedChannels);
                 args << "devmem2" << "0x80000000";
    
                 proc.start("sudo", args);
                 if(proc.waitForFinished())
                 {
                     QString result = QString(proc.readAll());
                     qDebug() << "devmem2 done and returning:"<<result;
                     QString dds_en = result.mid(result.lastIndexOf("0x"));
                     QString test=dds_en.simplified();
    
                    qDebug()<<"Detected:"<<dds_en;
                    qDebug()<<"Detected 2:"<<test;
                        //test.flush();
                      if(test=="0x0"){
                          QProcess p1 ;
                          p1.startDetached("/bin/bash", QStringList() << "-c" << "/home/analog/Documents/master/hoppingMaster.sh");
                          QProcess Rx_CF;
                          Rx_CF.start("cat /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency");
                          Rx_CF.waitForFinished(-1); // will wait forever until finished
                          Rx_CF_read =Rx_CF.readAllStandardOutput();
                          qDebug()<<"Rx LO ="<<Rx_CF_read;
    
                                  }
    
                       if(test=="0x1"){
              
                          QFile file("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
                          qDebug()<<"Try to set out_altvoltage1_TX_LO_frequency to:"<<Rx_CF_read;
                          if(file.open(QIODevice::WriteOnly)){
                              quint64 count = file.write(Rx_CF_read.toLatin1());
                              Q_ASSERT(count > 0);
                              file.flush();
                              file.close();
                             qDebug()<<"QFile Run:"<<count;
    
                          }
    
                      }
    
                  proc.close();
                 }
                 else
                     qDebug() << "faild to start devmem2 for dds_en";
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      JonB
      wrote on 25 Jan 2022, 10:37 last edited by JonB
      #2

      I don't know how people can understand what you write, or answer your specific desires, about which we have no idea.

      I see a Rx_CF_read variable. Since I do not see it declared I have to assume it is a (persistent) member variable. I see it set during if(test=="0x0"). I see it used (at a later date?) to write during the if(test=="0x1") case. Only you know whether it has the desired value at that point.

      As a separate issue, I don't know why in order to read the content of file /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency you issue an OS cat command and read the stdout from that, when all you should do is open the file for read and read it, why the OS cat command?

      Also as a separate issue, you will (potentially at least) execute /home/analog/Documents/master/hoppingMaster.sh multiple times. Is that desired, or is it desired only once before all this reading/writing? Again only you know that.

      Finally, your title is "shell script in qt not changing the value". What shell script is not changing what value? the only shell script I see is hoppingMaster.sh? And again only you can know how that behaves/what it;s supposed to do.

      1 Reply Last reply
      4
      • W Offline
        W Offline
        Wasee
        wrote on 26 Jan 2022, 04:50 last edited by
        #3

        @JonB said in shell script in qt not changing the value:

        I don't know how people can understand what you write, or answer your specific desires, about which we have no idea.
        I see a Rx_CF_read variable. Since I do not see it declared I have to assume it is a (persistent) member variable. I see it set during if(test=="0x0"). I see it used (at a later date?) to write during the if(test=="0x1") case. Only you know whether it has the desired value at that point.
        As a separate issue, I don't know why in order to read the content of file /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency you issue an OS cat command and read the stdout from that, when all you should do is open the file for read and read it, why the OS cat command?
        Also as a separate issue, you will (potentially at least) execute /home/analog/Documents/master/hoppingMaster.sh multiple times. Is that desired, or is it desired only once before all this reading/writing? Again only you know that.
        Finally, your title is "shell script in qt not changing the value". What shell script is not changing what value? the only shell script I see is hoppingMaster.sh? And again only you can know how that behaves/what it;s supposed to do.

        @JonB Thanks your valuable response!
        Variable Rx_CF_read is defined in header file as QString. And its value is updated as it should be.

        I am reading and writing in OS file directly so thats why I am accessing the file using cat command because it directly access in terminal.

        I need to run the hoppingMaster.sh file once when GUI start before any reading and writing step.

        hoppingMaster.sh

        See below

                                                                      #!/bin/sh
        
        find_zynq_base_gpio () {
        	for i in /sys/class/gpio/gpiochip*; do
        		if [ "zynq_gpio" = `cat $i/label` ]; then
        			return `echo $i | sed 's/^[^0-9]\+//'`
        			break
        		fi
        	done
        	return -1
        }
        
        if [ `id -u` != "0" ]
        then
           echo "This script must be run as root" 1>&2
           exit 1
        fi
        
        for i in $(find -L /sys/bus/iio/devices -maxdepth 2 -name name)
        do
          dev_name=$(cat $i);
          if [ "$dev_name" = "ad9361-phy" ]; then
             phy_path=$(echo $i | sed 's:/name$::')
             cd $phy_path
             break
          fi
        done
        
        if [ "$dev_name" != "ad9361-phy" ]; then
         exit
        fi
        
        #Setup 8 Profiles 1MHz spaced
        ##GPS-P1
        
        	echo 2425000000 > out_altvoltage0_RX_LO_frequency
        	echo "Initializing PROFILE $i at 2425000000 MHz"
        	
        	echo 0 > out_altvoltage0_RX_LO_fastlock_store
        ##GPS-P2
        	
        	echo 2475000000 > out_altvoltage0_RX_LO_frequency
        	echo "Initializing PROFILE $i at 2475000000 MHz"
        
        	echo 1 > out_altvoltage0_RX_LO_fastlock_store
        
        ##GPS-P3
        
        	echo 2425000000 > out_altvoltage0_RX_LO_frequency
        	echo "Initializing PROFILE $i at 2425000000 MHz"
        
        	echo 2 > out_altvoltage0_RX_LO_fastlock_store
        
        ##GPS-P4
        
        	echo 2475000000 > out_altvoltage0_RX_LO_frequency
        	echo "Initializing PROFILE $i at 2475000000 MHz"
        
        	echo 3 > out_altvoltage0_RX_LO_fastlock_store
        
        ##GPS-P5
        	
        	echo 2425000000 > out_altvoltage0_RX_LO_frequency
        	echo "Initializing PROFILE $i at 2425000000 MHz"
        
        	echo 4 > out_altvoltage0_RX_LO_fastlock_store
        
        ##GPS-P1
        
        	echo 2475000000 > out_altvoltage0_RX_LO_frequency
        	echo "Initializing PROFILE $i at 2475000000 MHz"
        	
        	echo 5 > out_altvoltage0_RX_LO_fastlock_store
        ##GPS-P2
        	
        	echo 2425000000 > out_altvoltage0_RX_LO_frequency
        	echo "Initializing PROFILE $i at 2425000000 MHz"
        	
        	echo 6 > out_altvoltage0_RX_LO_fastlock_store
        ##GPS-P4
        
        	echo 2475000000 > out_altvoltage0_RX_LO_frequency
        	echo "Initializing PROFILE $i at 2475000000 MHz"
        
        	echo 7 > out_altvoltage0_RX_LO_fastlock_store
        
        #Enable Fastlock Mode
        
        echo "Entering to find the hopping IP"
        
        for i in $(find -L /sys/bus/iio/devices -maxdepth 2 -name name)
        do
          dev_name=$(cat $i)
          if [ "$dev_name" = "axi-hopper" ]; then
             phy_path=$(echo $i | sed 's:/name$::')
             echo "Hopping IP found"
             cd $phy_path
             break
          fi
        done
        
        if [ "$dev_name" != "axi-hopper" ]; then
        	echo "Hopping IP not found"
         exit
        fi
        
        echo 1 > hopping_enable
        echo 2000 > dwell_samples
        
        
        
        J jsulmJ 2 Replies Last reply 26 Jan 2022, 07:11
        0
        • W Wasee
          26 Jan 2022, 04:50

          @JonB said in shell script in qt not changing the value:

          I don't know how people can understand what you write, or answer your specific desires, about which we have no idea.
          I see a Rx_CF_read variable. Since I do not see it declared I have to assume it is a (persistent) member variable. I see it set during if(test=="0x0"). I see it used (at a later date?) to write during the if(test=="0x1") case. Only you know whether it has the desired value at that point.
          As a separate issue, I don't know why in order to read the content of file /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency you issue an OS cat command and read the stdout from that, when all you should do is open the file for read and read it, why the OS cat command?
          Also as a separate issue, you will (potentially at least) execute /home/analog/Documents/master/hoppingMaster.sh multiple times. Is that desired, or is it desired only once before all this reading/writing? Again only you know that.
          Finally, your title is "shell script in qt not changing the value". What shell script is not changing what value? the only shell script I see is hoppingMaster.sh? And again only you can know how that behaves/what it;s supposed to do.

          @JonB Thanks your valuable response!
          Variable Rx_CF_read is defined in header file as QString. And its value is updated as it should be.

          I am reading and writing in OS file directly so thats why I am accessing the file using cat command because it directly access in terminal.

          I need to run the hoppingMaster.sh file once when GUI start before any reading and writing step.

          hoppingMaster.sh

          See below

                                                                        #!/bin/sh
          
          find_zynq_base_gpio () {
          	for i in /sys/class/gpio/gpiochip*; do
          		if [ "zynq_gpio" = `cat $i/label` ]; then
          			return `echo $i | sed 's/^[^0-9]\+//'`
          			break
          		fi
          	done
          	return -1
          }
          
          if [ `id -u` != "0" ]
          then
             echo "This script must be run as root" 1>&2
             exit 1
          fi
          
          for i in $(find -L /sys/bus/iio/devices -maxdepth 2 -name name)
          do
            dev_name=$(cat $i);
            if [ "$dev_name" = "ad9361-phy" ]; then
               phy_path=$(echo $i | sed 's:/name$::')
               cd $phy_path
               break
            fi
          done
          
          if [ "$dev_name" != "ad9361-phy" ]; then
           exit
          fi
          
          #Setup 8 Profiles 1MHz spaced
          ##GPS-P1
          
          	echo 2425000000 > out_altvoltage0_RX_LO_frequency
          	echo "Initializing PROFILE $i at 2425000000 MHz"
          	
          	echo 0 > out_altvoltage0_RX_LO_fastlock_store
          ##GPS-P2
          	
          	echo 2475000000 > out_altvoltage0_RX_LO_frequency
          	echo "Initializing PROFILE $i at 2475000000 MHz"
          
          	echo 1 > out_altvoltage0_RX_LO_fastlock_store
          
          ##GPS-P3
          
          	echo 2425000000 > out_altvoltage0_RX_LO_frequency
          	echo "Initializing PROFILE $i at 2425000000 MHz"
          
          	echo 2 > out_altvoltage0_RX_LO_fastlock_store
          
          ##GPS-P4
          
          	echo 2475000000 > out_altvoltage0_RX_LO_frequency
          	echo "Initializing PROFILE $i at 2475000000 MHz"
          
          	echo 3 > out_altvoltage0_RX_LO_fastlock_store
          
          ##GPS-P5
          	
          	echo 2425000000 > out_altvoltage0_RX_LO_frequency
          	echo "Initializing PROFILE $i at 2425000000 MHz"
          
          	echo 4 > out_altvoltage0_RX_LO_fastlock_store
          
          ##GPS-P1
          
          	echo 2475000000 > out_altvoltage0_RX_LO_frequency
          	echo "Initializing PROFILE $i at 2475000000 MHz"
          	
          	echo 5 > out_altvoltage0_RX_LO_fastlock_store
          ##GPS-P2
          	
          	echo 2425000000 > out_altvoltage0_RX_LO_frequency
          	echo "Initializing PROFILE $i at 2425000000 MHz"
          	
          	echo 6 > out_altvoltage0_RX_LO_fastlock_store
          ##GPS-P4
          
          	echo 2475000000 > out_altvoltage0_RX_LO_frequency
          	echo "Initializing PROFILE $i at 2475000000 MHz"
          
          	echo 7 > out_altvoltage0_RX_LO_fastlock_store
          
          #Enable Fastlock Mode
          
          echo "Entering to find the hopping IP"
          
          for i in $(find -L /sys/bus/iio/devices -maxdepth 2 -name name)
          do
            dev_name=$(cat $i)
            if [ "$dev_name" = "axi-hopper" ]; then
               phy_path=$(echo $i | sed 's:/name$::')
               echo "Hopping IP found"
               cd $phy_path
               break
            fi
          done
          
          if [ "$dev_name" != "axi-hopper" ]; then
          	echo "Hopping IP not found"
           exit
          fi
          
          echo 1 > hopping_enable
          echo 2000 > dwell_samples
          
          
          
          J Offline
          J Offline
          JonB
          wrote on 26 Jan 2022, 07:11 last edited by
          #4

          @Wasee said in shell script in qt not changing the value:

          I am reading and writing in OS file directly so thats why I am accessing the file using cat command because it directly access in terminal.

          I do not know what you think this means. Going cat on a file and reading from its stdout does the same as just opening the file for read, only much slower.

          I need to run the hoppingMaster.sh file once when GUI start before any reading and writing step.

          Then I suggest you change your code to make that the case instead of what it does now, which is potentially to run it any number of times, whenever test=="0x0", which we have no idea how many times may occur. I have no interest in reading through the code of the script to figure what it does.

          Whatever, I am no clearer on what your question is, and it appears from the lack of responses nor is anyone else. Other than you need to get your logic right, this does not sound like it is a Qt question.

          1 Reply Last reply
          1
          • W Wasee
            26 Jan 2022, 04:50

            @JonB said in shell script in qt not changing the value:

            I don't know how people can understand what you write, or answer your specific desires, about which we have no idea.
            I see a Rx_CF_read variable. Since I do not see it declared I have to assume it is a (persistent) member variable. I see it set during if(test=="0x0"). I see it used (at a later date?) to write during the if(test=="0x1") case. Only you know whether it has the desired value at that point.
            As a separate issue, I don't know why in order to read the content of file /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency you issue an OS cat command and read the stdout from that, when all you should do is open the file for read and read it, why the OS cat command?
            Also as a separate issue, you will (potentially at least) execute /home/analog/Documents/master/hoppingMaster.sh multiple times. Is that desired, or is it desired only once before all this reading/writing? Again only you know that.
            Finally, your title is "shell script in qt not changing the value". What shell script is not changing what value? the only shell script I see is hoppingMaster.sh? And again only you can know how that behaves/what it;s supposed to do.

            @JonB Thanks your valuable response!
            Variable Rx_CF_read is defined in header file as QString. And its value is updated as it should be.

            I am reading and writing in OS file directly so thats why I am accessing the file using cat command because it directly access in terminal.

            I need to run the hoppingMaster.sh file once when GUI start before any reading and writing step.

            hoppingMaster.sh

            See below

                                                                          #!/bin/sh
            
            find_zynq_base_gpio () {
            	for i in /sys/class/gpio/gpiochip*; do
            		if [ "zynq_gpio" = `cat $i/label` ]; then
            			return `echo $i | sed 's/^[^0-9]\+//'`
            			break
            		fi
            	done
            	return -1
            }
            
            if [ `id -u` != "0" ]
            then
               echo "This script must be run as root" 1>&2
               exit 1
            fi
            
            for i in $(find -L /sys/bus/iio/devices -maxdepth 2 -name name)
            do
              dev_name=$(cat $i);
              if [ "$dev_name" = "ad9361-phy" ]; then
                 phy_path=$(echo $i | sed 's:/name$::')
                 cd $phy_path
                 break
              fi
            done
            
            if [ "$dev_name" != "ad9361-phy" ]; then
             exit
            fi
            
            #Setup 8 Profiles 1MHz spaced
            ##GPS-P1
            
            	echo 2425000000 > out_altvoltage0_RX_LO_frequency
            	echo "Initializing PROFILE $i at 2425000000 MHz"
            	
            	echo 0 > out_altvoltage0_RX_LO_fastlock_store
            ##GPS-P2
            	
            	echo 2475000000 > out_altvoltage0_RX_LO_frequency
            	echo "Initializing PROFILE $i at 2475000000 MHz"
            
            	echo 1 > out_altvoltage0_RX_LO_fastlock_store
            
            ##GPS-P3
            
            	echo 2425000000 > out_altvoltage0_RX_LO_frequency
            	echo "Initializing PROFILE $i at 2425000000 MHz"
            
            	echo 2 > out_altvoltage0_RX_LO_fastlock_store
            
            ##GPS-P4
            
            	echo 2475000000 > out_altvoltage0_RX_LO_frequency
            	echo "Initializing PROFILE $i at 2475000000 MHz"
            
            	echo 3 > out_altvoltage0_RX_LO_fastlock_store
            
            ##GPS-P5
            	
            	echo 2425000000 > out_altvoltage0_RX_LO_frequency
            	echo "Initializing PROFILE $i at 2425000000 MHz"
            
            	echo 4 > out_altvoltage0_RX_LO_fastlock_store
            
            ##GPS-P1
            
            	echo 2475000000 > out_altvoltage0_RX_LO_frequency
            	echo "Initializing PROFILE $i at 2475000000 MHz"
            	
            	echo 5 > out_altvoltage0_RX_LO_fastlock_store
            ##GPS-P2
            	
            	echo 2425000000 > out_altvoltage0_RX_LO_frequency
            	echo "Initializing PROFILE $i at 2425000000 MHz"
            	
            	echo 6 > out_altvoltage0_RX_LO_fastlock_store
            ##GPS-P4
            
            	echo 2475000000 > out_altvoltage0_RX_LO_frequency
            	echo "Initializing PROFILE $i at 2475000000 MHz"
            
            	echo 7 > out_altvoltage0_RX_LO_fastlock_store
            
            #Enable Fastlock Mode
            
            echo "Entering to find the hopping IP"
            
            for i in $(find -L /sys/bus/iio/devices -maxdepth 2 -name name)
            do
              dev_name=$(cat $i)
              if [ "$dev_name" = "axi-hopper" ]; then
                 phy_path=$(echo $i | sed 's:/name$::')
                 echo "Hopping IP found"
                 cd $phy_path
                 break
              fi
            done
            
            if [ "$dev_name" != "axi-hopper" ]; then
            	echo "Hopping IP not found"
             exit
            fi
            
            echo 1 > hopping_enable
            echo 2000 > dwell_samples
            
            
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on 26 Jan 2022, 07:16 last edited by
            #5

            @Wasee said in shell script in qt not changing the value:

            I am reading and writing in OS file directly so thats why I am accessing the file using cat command because it directly access in terminal.

            There is absolutely no need to use shell and cat to read a any file! Just use QFile...
            The great thing about UNIX/Linux is that a file is a file and behaves as a file, doesn't matter whether it is normal file or device file.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • W Offline
              W Offline
              Wasee
              wrote on 21 Feb 2022, 10:18 last edited by
              #6

              @jsulm said in shell script in qt not changing the value:

              There is absolutely no need to use shell and cat to read a any file! Just use QFile...
              The great thing about UNIX/Linux is that a file is a file and behaves as a file, doesn't matter whether it is normal file or device file.

              Hi Dear;
              I didn't understand Please brief more. In my case I run the bash script behind the external signal when its value equal zero and when external signal value change to 1 then only one value pass to out_altvoltage1_TX_LO_frequency and write on the devices register.

              Thanks

              jsulmJ 1 Reply Last reply 21 Feb 2022, 12:15
              0
              • W Wasee
                21 Feb 2022, 10:18

                @jsulm said in shell script in qt not changing the value:

                There is absolutely no need to use shell and cat to read a any file! Just use QFile...
                The great thing about UNIX/Linux is that a file is a file and behaves as a file, doesn't matter whether it is normal file or device file.

                Hi Dear;
                I didn't understand Please brief more. In my case I run the bash script behind the external signal when its value equal zero and when external signal value change to 1 then only one value pass to out_altvoltage1_TX_LO_frequency and write on the devices register.

                Thanks

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on 21 Feb 2022, 12:15 last edited by jsulm
                #7

                @Wasee What did you not understand?
                How to read/write a file in Qt using QFile?
                Did you read its documentation already: https://doc.qt.io/qt-5/qfile.html
                There are even examples...

                If your question is about writing shell scripts, then you're in the wrong forum and should at least try to be more clear as @JonB already pointed out.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved