Results 1 to 4 of 4

Thread: How to trig an action at reaching of defined value (with fast sampling)?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2016
    Posts
    22
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to trig an action at reaching of defined value (with fast sampling)?

    Hello,
    I have to face a problem with alarm sensor. I have a qLineEdit where values are modified by an external widget (it manages data from a serial port).
    Now I need that, when values exceed a defined level, an action is trigged (just like an alarm, or a motor power on, etc.).
    I tried to use a signal/slot for the qLineEdit (_textChanged event with a simple "if ()" condition), it's ok for slow data flow, but obviously, for an high data rate ( as from a fast voltage sensor, a position device, a piece counter), it's freeze my code. So I'm searching a better strategy, did you have any suggestion? Thanks!!

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to trig an action at reaching of defined value (with fast sampling)?

    Signalize the transition through a given level and not every change in value above that level.
    Simple code of the slote :
    Qt Code:
    1. if(value > alarm_value)
    2. {
    3. if(!alarm_state)
    4. {
    5. alarm_state = true;
    6. //do what You need to alarm ON
    7. }
    8. }
    9. else
    10. {
    11. if(alarm_state)
    12. {
    13. alarm_state = false;
    14. //do what You need to alarm OFF
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to trig an action at reaching of defined value (with fast sampling)?

    It seems like a very strange design to use a change in the text of a GUI widget to trigger an alarm signal. Why aren't you monitoring the sensor directly and using the sensor value to trigger the alarm?

    If your basic problem is that the data rate from the sensor is too high, then you have at least two options:

    - don't sample the sensor so often. If you don't need microsecond or millisecond response, then sample once per second.

    - if you can't change the sampling rate, then change the rate that you report the signal to the rest of the app. Compute the average of all of the samples received over a 1 second period (for example), and once every second emit a signal with the average value. Connect that signal to other parts of your app.

    And change your design so you aren't relying on looking at a QLineEdit's value to tell your app when the alarm should be raised. Take the signal from the monitoring widget and connect it to two slots - one that changes the text in the QLineEdit, and another that checks the value to see if the alarm should be raised.

    Your current design is like looking in the mirror to see if your face is sweating to tell you it is too hot instead of just looking at the thermometer.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Mar 2016
    Posts
    22
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to trig an action at reaching of defined value (with fast sampling)?

    "Your current design is like looking in the mirror to see if your face is sweating to tell you it is too hot instead of just looking at the thermometer." It's a very clear comparison!
    I decided to review the design of my app, in order to have the widget only as GUI, while data process and alarm will be done with a flow limit (it's unuseful having a ton of aquiring, when 10 per sec is enough!)

Similar Threads

  1. Replies: 2
    Last Post: 8th November 2016, 05:44
  2. Replies: 1
    Last Post: 24th October 2016, 09:35
  3. N-Trig presure detection
    By ConfaMiky in forum Qt Programming
    Replies: 0
    Last Post: 15th May 2014, 23:12
  4. Server sent message not reaching client
    By tiredtyrant in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2014, 14:12
  5. Replies: 8
    Last Post: 6th June 2013, 02:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.