Digital button & code that must run outside the switch of the event

I have an interesting situation.  I have a command button which I activated the control via the mouse wheel of the user (thanks to great examples of code herein for one!). To do this I like, I had to put the processing part of the code outside the set event button, such that the value of the output of the control would be updated immediately.

The only problem with this methodology which is then when the user closes the Panel and the button control is a final reminder, this block of code is executed one last time, which translates into a non fatal error "invalid control ID '.  The solution here is relevant, but is not ideal as shown above.

My solution feels like a hack, but tell me what you think - trap on EVENT_DISCARD and back at the beginning.  Seems to work, just feels like a patch.  Here is the code:

int CVICALLBACK KnobCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
    int prevValue = 0;
    int currValue;          // current value of knob control, range = 0-100
    double currMotor = 0;
    double currMeter = 0;
    double idealMotor = 0;
    double currVoltage;
    int max, min, inc;

    // find the range values set in the UIR control:
    GetCtrlAttribute(panel, control, ATTR_MIN_VALUE, &min);
    GetCtrlAttribute(panel, control, ATTR_MAX_VALUE, &max);
    GetCtrlAttribute(panel, control, ATTR_INCR_VALUE, &inc);

    // load the current control changed value:
    GetCtrlVal(panel, control, &currValue);

    switch (event)
    {
        case EVENT_COMMIT:  // any control commit:
            break;

        case EVENT_MOUSE_WHEEL_SCROLL:

            switch (eventData1)
            {
                case MOUSE_WHEEL_SCROLL_UP:
                    if (currValue < max)
                        currValue += inc;  // increment 1 step at a time, not eventData2 number of steps (Windows scroll wheel number)
                    else
                    {
                        currValue = max;    // hold at max
                        return 1;   // Swallow event to prevent from updating UIR
                    }
                    break;

                case MOUSE_WHEEL_SCROLL_DOWN:
                    if (currValue > min)
                        currValue -= inc;  // decrement 1 step at a time, not eventData2 number of steps (Windows scroll wheel number)
                    else
                    {
                        currValue = min;    // hold at min
                        return 1;   // Swallow event to prevent from updating UIR
                    }
                    break;

                case MOUSE_WHEEL_PAGE_UP:
                    if (currValue < max)
                        currValue += (inc * 5);  // eventData2 = 0 when PAGE up/down
                    else
                    {
                        currValue = max;    // hold at max
                        return 1;   // Swallow event to prevent from updating UIR
                    }
                    break;

                case MOUSE_WHEEL_PAGE_DOWN:
                    if (currValue > min)
                        currValue -= (inc * 5);  // eventData2 = 0 when PAGE up/down
                    else
                    {
                        currValue = min;    // hold at min
                        return 1;   // Swallow event to prevent from updating UIR
                    }
                    break;
            }
            SetCtrlVal(panel, control, currValue);  // update control with processed value
            break;

        case EVENT_VAL_CHANGED:
            if ((currValue < prevValue) && (currValue > min))         // decrementing above floor
            {
                currValue -= inc;
            }
            else if ((currValue > prevValue) && (currValue < max))        // incrementing below ceiling
            {
                currValue += inc;
            }
            else if (currValue = max) // TODO: this condition doesn't work as expected; control doesn't trap for wrap-around from max to min, vice versa
            {
                currValue = max;    // hold at max
                return 1;   // Swallow event to prevent from updating UIR
            }
            else if (currValue = min) // TODO: this condition doesn't work as expected; control doesn't trap for wrap-around from max to min, vice versa
            {
                currValue = min;    // hold at min
                return 1;   // Swallow event to prevent from updating UIR
            }
            SetCtrlVal(panel, control, currValue);  // update control with processed value
            prevValue = currValue;  // update state variable
            break;

        case EVENT_DISCARD:
            return 0;   // TODO: bug fix for quitting cleanly, so that the code outside of the event switch doesn't execute one last time when the panel is quit.
            break;

    }   // end switch

    currVoltage =  (currValue * MOTOR_VOLT_STEP) + MOTOR_VOLT_MIN;
    currMotor = LabJackTimer(LABJACK_TIMER0);
    idealMotor = MOTOR_SLOPE * currVoltage;

    if (abs((int)(currMotor - idealMotor)) < MOTOR_TOL)
    {
        SetCtrlVal(panel, MAINPANEL_TEXTMSG6, "GOOD");
        SetCtrlAttribute(panel, MAINPANEL_TEXTMSG6, ATTR_TEXT_BGCOLOR, VAL_GREEN);
    }
    else
    {
        SetCtrlVal(panel,MAINPANEL_TEXTMSG6,"FAIL");
        SetCtrlAttribute(panel, MAINPANEL_TEXTMSG6, ATTR_TEXT_BGCOLOR, VAL_RED);
    }
    return 0;
}

I suggest to put the code SetCtrlVal fragment in a separate function and call this function for the correct event only; at present, it is called for any event, including the event throwing...

In addition, there is no need to recall the values min/max/inc of your control each time, once the start programme should be enough

Tags: NI Software

Similar Questions

  • Why my code does not perform outside the service?

    I have unfinished code, I'm getting. There is a listener and a function. I noticed when I put the loop outside the service (it would be less than the last line) it is not running. Why does not run the code as I type outside the service? I need to know for future reference

    Here's a piece of it

    function onLoaded(e:Event):void {}
    trace (e.Target.Data.Files);
    trace (e.Target.Data.images);

    fileData = e.target.data.Files;
    imgData = e.target.data.images;

    imgArray = imgData.split ('.jpg'), Table of images
    trace (FileData);
    trace (imgArray);
    for (var i: Number = 0; i < 15; i ++) {}
    trace (insArray [i] .source = path + "/" + imgArray [i] + "_tn.jpg");
    }

    }

    myTextLoader.load (new URLRequest ("info.txt"));

    Here are 2 examples:

    example 1:

    Import 12345678910111213import;
    var url: String = "Image.jpg";
    var bm:Bitmap;
    var loader: Loader = new Loader();
    loader.contentLoaderInfo.addEventListener (Event.COMPLETE, completeHandler);
    var request: URLRequest = new URLRequest (url);
    Loader.Load (request);

    function completeHandler(event:Event):void
    {
    BM = bitmap (Event.Target.Content);
    trace (WB);    //<-  you="" get="" :="" [object="">
    }

    example 2: (just change the location of trace (bm)

    Import 12345678910111213import;
    var url: String = "Image.jpg";
    var bm:Bitmap;
    var loader: Loader = new Loader();
    loader.contentLoaderInfo.addEventListener (Event.COMPLETE, completeHandler);
    var request: URLRequest = new URLRequest (url);
    Loader.Load (request);

    trace (WB);    //<-  you="" get="" :="">

    function completeHandler(event:Event):void
    {
    BM = bitmap (Event.Target.Content);
    }

    same code as an example 2:

    Import 12345678910111213import;
    var url: String = "Image.jpg";
    var bm:Bitmap;
    var loader: Loader = new Loader();
    loader.contentLoaderInfo.addEventListener (Event.COMPLETE, completeHandler);
    var request: URLRequest = new URLRequest (url);
    Loader.Load (request);

    function completeHandler(event:Event):void
    {
    BM = bitmap (Event.Target.Content);
    }

    trace (WB);    //<-  you="" get="" :="">

    as you can see it's okay where the function is written. That the function runs only after the load event is over. If the layout in the sample 2 and 3 line will result as null because at that time the loading process has just begun...

  • View the programs that are running on the remote computer.

    How use remote desktop to view the programs that are running on the remote computer. I connect to the pc remotely is used to monitor a communication system for the alarms. The alarm Viewer application runs as a service. When I connect locally to the computer, I can see the application and view the status of the alarm system. When I connect via remote desktop, I can't. I don't see that the application is running in the services list.

    Do you mean the Task Manager?

    If so, try using change sequence to bring up the Task Manager while in the session remote desktop active...

    http://Windows.Microsoft.com/en-us/Windows7/keyboard-shortcuts

    You might also find something in the PsTools collection...

    http://TechNet.Microsoft.com/en-us/Sysinternals/bb896649

  • How can I place a captcha before a html code that is displayed when the captcha is finished?

    andrebertel.com/support

    I don't like my Skype appearing automatically... I have block 2 robots... can I place a captcha before a html code that is displayed when the captcha is finished?

    You can add a form with only the email field and the captcha and set up the landing page as the page where the content html is placed, so that users will have to enter captcha to land on this page apart from that, you need to use the coding customized for adding verification captcha to the content of the page.

    Thank you

    Sanjit

  • How can I create a cluster of two instances that are running on the same server?

    Hello
    I can't find how to create a cluster or even a rule of failover for my two instances that are running on the same server ODSEE 11 GR 1 material.
    Could you please help?

    Thank you

    Hello
    Clustering (intended as Sun Cluster, Veritas Cluster, etc...) IS NOT supported since 7.0:

    http://docs.Oracle.com/CD/E20295_01/PDF/821-1216.PDF [page 20]

    and, according to my own experience, is the WORST way to achieve high availability of Service LDAP directory and in a way almost CONCEDED for replication problems in your topology (lock, split, re-init, etc...).

    Please use the "application level" collection that you get out of the box with the multimaster replication.

    http://docs.Oracle.com/CD/E20295_01/HTML/821-1217/index.html

    http://docs.Oracle.com/CD/E20295_01/HTML/821-1220/fhkry.html#scrolltoc

    HTH,
    Marco

  • What are the limits it in code that is running in a SIO

    Hello

    I wonder if any of you good people out there can tell me if there are limits on what the code can be executed (or accessed memory) by a method of object of shareable Interface (SIO) server-side?

    I have a server applet that implements a SIO which includes a single method - IncNumber(). It simply increments a field on a single byte which is one of the many areas in an array of nonvolatile memory. BUT before the number can be incremented IncNumber() must verify a seal THAT protects the entire table. If the seal is OK then the field can be incremented and a new seal is created the entire table. The server cmdlet has an APDU that calls IncNumber and I can make these units APDU to my heart's content and see incrementing number always protected by properly trained seals. So when running the applet Server everything works fine.

    The problem comes when I create a Client applet which tries to call the Principal agent. IncNumber() method, because it always returns an error 6F00. I found that the problem comes when the applet Server runs the following command (in trying to check the certificate FOR):

    cipherDES.init (keyTest [0], Cipher.MODE_ENCRYPT);

    cipherDES is declared in a non-volatile memory and is initialized in the constructor of the server. keyTest is an array of possible keys (also resident in non-volatile memory), but for the moment only [0] is already used. The server must go through an initialization phase which initializes keyTest [0] so I'm fairly certain that all objects exist. Don't forget that I can issue an APDU to the server cmdlet that runs this code yourself without problem.

    My understanding of the functioning of the WIS system is that when the customer calls that the SIO customer method gets hunted in memory to be replaced by the server, as if the server had been selected himself, so I don't see why it will fail on this line of code. This interpretation is correct?

    So my QUESTION is this. He knows that this will not work? If so, can you please explain why and give me ideas on how I could get around it (if possible). If you think that this should can work you give me ideas why it isn't (or things that I could try to find out). Would it be a limitation on the card that I use (AFAIK, the map I use this on is a map of NXP JCop 2.4.1 running Javacard 2.2.2 and global platform 2.1.1)?

    Any ideas gratefully will welcome.

    Hello

    The problem is with the creation of the object of encryption. You must define externalAccess to true in the call to getInstance(). The javadoc says:

    externalAccess true indicates that the instance will be shared between applet multiple instances and that the instance of the encryption algorithm is also available (via a shared interface) when the owner of the instance of the encryption algorithm is not the currently selected applet. If true the implementation doesn't have to allocate internal data CLEAR_ON_DESELECT transitional space.

    In addition, when the main agent is called, the caller is not deleted from the memory, there is a change of context internally in the JCRE. The SIO server may not necessarily be currently selected. It is covered in a bit more detail in the JCRE plug.

    Shane

  • Code that is running in Debug Mode, but not in Standard Mode

    Hello world

    A few months ago, I wrote a code that registers the current over time.  He measures each 1 s current, and it gives the user the ability to specify how often the data should be encoded.  It can be either linear (for example, every minute), or logarithmic way (by small increments in the largest leading to greater value and the user can specify the maximum sampling intervals).  I also created a queue that will record the "last minute".  For example, if the user wants to see what happened at the last minute, he will have every second saved and that data will be added at the end of the file.

    However, it was a messy piece of code (while working), and I wanted to clean it up so that it would be easier to add in the future.  I started to learn more about state machines.  I'm slowly building.  First the user pushes playing, and then complete the where to save, intervals of maximum recording, other variables etc and click on load.  After that, the user can run a push play to start the program.  For now, it is not connected to any equipment, I wanted just the working time of recording intervals.

    At present, if it is running in debug mode, everything works well, but if it is not in debug mode, it stops after a few intervals.  I think it is most likely a race condition.  I have a few local variables, and I read that they must only be used if there are used in two places inside the same VI. But I do not think that I use in the subVIs.

    Can someone give me some advice please?  It seems it is not updated to the next recording interval.  I have attached my code.


  • Developer10g forms run outside the browser

    Hello world

    I'm new with the form 10g developer

    I built a form successfully and run it, but when it runs, it runs in a window (like Java applet), but not in the browser

    My question is

    Is it possible to run the form that I build in the Internet browser?

    Here is a picture of the running form

    s2.jpg

    Thnaks,

    Of course, simply change your formsweb.cfg and change the seperateFrame = True to seperateFrame = False.  This is the setting that controls if the application forms will take place inside or outside the browser.

    Craig...

  • Database SQL vCenter that is running on the virtual machine within vsphere

    Hey guys, I was wondering how many of you are running your database remote vcenter on a virtual machine inside your vsphere environment? We always ran the vcenter db on a physical remote outside the vsphere group box, but I am considering the upgrade to sql 2008 R2 and I already have a virtual sql server computer running within vsphere.

    Pro/drawbacks to be aware of the db running on a virtual machine?

    Thanks in advance

    Kevin

    We rotated our SQL database in a VM for a while now.

    Some advantages are for example the wide use of HA and the ability to easily extend if necessary resources. In addition, if you use backup as Veeam software a restore takes only a few minutes from a physical configuration.

    There are a few things when you have to keep in mind:

    -Make sure that your SQL VM database begins before your vCenter (the service does not start if it cannot reach the database), even if it can be fixed manually it might be something you want to keep in mind

    -If you use the distributed switches power risk since data is stored in the database, of course there are solutions for this (keep the traffic on a standard switch management)

    -If you use HA make sure you modify the priority of restarting HA for the virtual machine (you don't want a reboot suddenly)

  • How to close programs that are running in the background and what services are safe cut

    under windows xp with sp3, I hear something running in the background, but no photo with her, how I close it, also how do you know which windows services are safe to clog then start and stop can be a little faster?

    For performance tweaks that I would recommend looking at http://www.tweakxp.com/performance_tweaks.aspx they have a great compilation of good settings you can do and more are step by step, so even the most novice person can perform these tasks. Insofar as something running in the background of his always possible, you have some kind of malware running I want to run a scan for these emissions.

  • How to create the .cod file to run on the Simulator BB9900

    Hi, I already from the zip package in order to use the bbwp command to create the .cod file and be able to run on the simulator of BB9900, but when I run this command as described in: https://developer.blackberry.com/html5/documentation/compile_ww_app_for_smartphones_1873321_11.html

    It creates two files, each with a .bar file, this type of file, I can't run it on the 9900 Simulator but a .cod file is required to run applications on the sim card.

    I don't know how to create the .cod file.

    Thank you

    Have you used Blackberry Webworks SDK for smartphone or Tablet SDK? The .cod files should be located in the subfolder OTAInstall of your output folder if you are using the Webworks SDK for Smartphone

  • Y at - it a tool that can run in the background (without GUI) on a permanent basis and store information to a file or a database?

    Separated from this thread.

    Tom... I'm looking for the answer to the exact same question... How is it difficult to understand that applications die/chew place memory/chew time cpu and we cannot sit at the PC at the same time watching a monitor of performance...

    Resource monitor is really an extension of part of the tool used long ago to Windows.

    Win + R and Run perfmon. This allows you to define specific counters and sampling frequencies. Not easier to use tools but the data can be used and analyzed after the event.

  • Several processes that are running on the standard user account because it runs slow and internet does not "."

    Create a user profile for children on PC 32-bit W7 with MS Family Safety.

    Recently they have complained he "runs slow and internet does not work.

    After playing for a little, I realized a ton of processes were running in the background. I couldn't run msconfig to their profile (not administrator) and after some research, I even if the profile has been corrupted.

    I created a new profile, but now the same thing is happening a few days later.

    See below; multiple copies of the same process are running. This happens within 2 m after the log-in and I only started one program.

    I started in safe mode with network and ran Windows defender, Spybot S & D and my virus scanner (all full scans) and turned up nothing malicious.  A few cookies tracking in the web cache, but nothing out of the ordinary.  I searched for the files wlaacmgr.exe and dplaysvr.exe (b/c they do not appear running in my admin profile) but they were found only in windows OS directories.  I understand that they are files of W7 but some maleware recreates.

    Many of them are the same files taking up process on the old profile that I deleted.

    Any help or suggestion as to why I have multiple copies of large processes running on the machine?  As I wrote it, I sign in, seems to be fine for one but 2 minutes a lot of process appear repeatedly and slows down the computer to a crawl.

    These two files listed are not at all on my admin profile and the machine works fine in my admin profile.  Even with open Photoshop, the CPU is only about 50% under my profile.

    Try to check/change the entries in startup with Autoruns from Sysinternals, which should work on the limited account to see its startup items.

  • How to correct text and images that are somehow outside the area of cardboard?

    This is the second document that my layout has mysteriously been presented outside the editing table. I saved this document yesterday and everything was fine. Today, there is a connection of several pages text box link, but on 4 pages my text and images have disappeared from the actual page and the table surrounding mount, but it shows the link text box later in the grey area. The last time I had to delete and re-create the pages, but don't have the time. I tried selecting all and using the arrow key to move everything, but he mistakes "this value would cause one or more objects to leave the editing table. I also tried selecting all and downward revision to 10% to bring it to the page or the editing table, but the same error. Any other suggestions? Screenshot below.

    It's a really long shot, but it would be interesting to .idml export and opening that. (see delete minor corruption by exporting)

    And Daniel is right - there is something is wrong with this file and it seriousl get better.

  • Y at - it an easy way to get the sql code that is sent in the query UPDATE

    I have a request to UPDATE abbreviated for readability. Is there an easy way to get the sql code that is sent? I use get this info for sql select in the display of debugging in cfeclipse but not for the UPDATE.

    < cfquery debug = "" name = "q" datasource = "#datasource #" > "



    UPDATE [BookingSystem]. [dbo]. [tbTrades]
    SET
    [Status] = #MATCHED_STATUS #.
    WHERE

    clientID = < cfqueryparam value = "" #arguments.clientID # "cfsqltype ="cf_sql_integer"> AND"

    < / cfquery >

    It might pay to read the docs for - http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_17.html#1102316 - focusing on the RESULT parameter.

    Read also about debugging in CF: http://livedocs.adobe.com/coldfusion/8/htmldocs/Debug_01.html

    --

    Adam

Maybe you are looking for