<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic question about callbacks in LabWindows/CVI</title>
    <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2358588#M61395</link>
    <description>&lt;P&gt;I'm trying to design a small program that involves TCP socket reads and writes. In the help for the ConnectToTCPServer() function, there's a note about the callbackFunction:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;The callback function should be short and should return as soon as possible.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is, does this statement apply principally to the ConnectToTCPServer() function, or to all callbacks? It seems that once I've called RunUserInterface(), pretty much all my processing will be within callbacks (or routines that the callbacks call).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I missing something here?&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2013 01:30:22 GMT</pubDate>
    <dc:creator>mzimmers</dc:creator>
    <dc:date>2013-03-21T01:30:22Z</dc:date>
    <item>
      <title>question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2358588#M61395</link>
      <description>&lt;P&gt;I'm trying to design a small program that involves TCP socket reads and writes. In the help for the ConnectToTCPServer() function, there's a note about the callbackFunction:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;The callback function should be short and should return as soon as possible.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is, does this statement apply principally to the ConnectToTCPServer() function, or to all callbacks? It seems that once I've called RunUserInterface(), pretty much all my processing will be within callbacks (or routines that the callbacks call).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I missing something here?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 01:30:22 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2358588#M61395</guid>
      <dc:creator>mzimmers</dc:creator>
      <dc:date>2013-03-21T01:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2359458#M61409</link>
      <description>&lt;P&gt;To it's callback function.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 15:05:04 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2359458#M61409</guid>
      <dc:creator>test_man</dc:creator>
      <dc:date>2013-03-21T15:05:04Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2359756#M61411</link>
      <description>&lt;P&gt;Generally speaking, that warning applies to all callbacks: a control callback that takes too long to terminate blocks all user input on the user interface. One very common question on this forum is indeed "I have a callback that executes a test but I cannot stop it pressing a stop button because it is unresponsive!" CVI offers ProcessSystemEvents () function exactly to permit processing events in case of a long callback that blocks out other events, but it must be used with cautions: as you can read in the help for the function,&amp;nbsp;&lt;EM&gt;Take care when using &lt;SPAN class="Monospace"&gt;ProcessSystemEvents&lt;/SPAN&gt;, because it can allow other callback functions to execute before it completes.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;Additionally, there are several methods to execute code out of a control callback or without blocking the user interface:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;UI timers&lt;/LI&gt;
&lt;LI&gt;Asyncronous timers&lt;/LI&gt;
&lt;LI&gt;Functions called via PostDeferredCall&lt;/LI&gt;
&lt;LI&gt;Threads other than the main thread&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;In case of a long lasting procedure, I strongly encourage you to handle it in one of these methods instead of running it inside a control callback with embedded calls to ProcessSystemEvents () .&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 16:47:21 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2359756#M61411</guid>
      <dc:creator>RobertoBozzolo</dc:creator>
      <dc:date>2013-03-21T16:47:21Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2359824#M61412</link>
      <description>&lt;P&gt;Interesting. This raises a different issue: will one callback block another?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've constructed my program like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;buttonCB:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; write a TCP message&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; wait for newdataFlag&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; process new data&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TCPCB&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; read TCP reply&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set newdataFlag&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(newdataFlag is a global variable.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there anything intrinisically wrong with this design? Will the fact that I'm in buttonCB prevent TCPCB from executing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 17:25:30 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2359824#M61412</guid>
      <dc:creator>mzimmers</dc:creator>
      <dc:date>2013-03-21T17:25:30Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2360092#M61413</link>
      <description>&lt;P&gt;OK, I did a bit of research, and it turns out that my concern is indeed the case. So, I've restructured the program like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;buttonCB:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; write a TCP message&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TCPCB&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; read TCP reply&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; process new data&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not thrilled with it, because my TCP callback isn't as brief as I'd like it, but...it works. If I wished to improve on this, which of the options that Roberto recommended above would seem preferable in this application?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 19:59:46 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2360092#M61413</guid>
      <dc:creator>mzimmers</dc:creator>
      <dc:date>2013-03-21T19:59:46Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2360558#M61417</link>
      <description>&lt;P&gt;I have little experience with TCP libary, but according to&amp;nbsp;&lt;A href="http://zone.ni.com/reference/en-XX/help/370051V-01/cvi/libref/cvitcp_callback_function/" target="_self"&gt;this page&lt;/A&gt;&amp;nbsp;&lt;EM&gt;you must process messages in order to receive events in the callback&lt;/EM&gt;; given this, your rewrite is on the right path. You could have inserted a ProcessSystemEvents inside your loop, but the change in logic is indeed better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could make your callback faster by moving processing out of it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TCPCB&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; read TCP reply&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PostDeferredCall (ProcessingRoutine, NULL);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2013 23:49:39 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2360558#M61417</guid>
      <dc:creator>RobertoBozzolo</dc:creator>
      <dc:date>2013-03-21T23:49:39Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2361558#M61429</link>
      <description>&lt;P&gt;Hi, Roberto -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the PostDeferredCall(), and it seems to work well. The documentation (ie, the online help) is a bit confusing, though. Am I correct in my understanding that this will not execute until ALL pending callbacks are finished, or merely the TCPCB that posted the deferred call?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2013 17:02:07 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2361558#M61429</guid>
      <dc:creator>mzimmers</dc:creator>
      <dc:date>2013-03-22T17:02:07Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2361956#M61433</link>
      <description>&lt;P&gt;I am not sure about that. If pending events are lined up in a single queue that is processed when running function has finished, the deferred callback will be executed after already raised events but before others that may happend after PostDeferredCall. This may not be true if events have priority flag associated to them so that they may be processed in an order other than chronological one. I tend to consider the first option is the right one but I am not sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, consider that you may spawn an separate thread to process some events and launch the deferred function in that thread with ProstDeferredCallToThread (): this will definitely alter the order of event processing, especially with multicore PCs&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2013 22:40:57 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2361956#M61433</guid>
      <dc:creator>RobertoBozzolo</dc:creator>
      <dc:date>2013-03-22T22:40:57Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2362302#M61435</link>
      <description>&lt;P&gt;I'd like to pursue the issue of callbacks vs. deferred functions a bit more. My application has a "START" button. When the start button is pressed, it's callback sends a message through a socket to a connected device. Upon receiving this message, the connected device sends a block of data to the program (through the same socket). Once the program processes the data, it sends anotherh command for more data, and continues to do so until a "STOP" button is pressed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tentatively designed my program like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ButtonCallback:&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set g_send to true&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; send a "SEND" command to the device&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TCPCallback:&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; read the data from the socket&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; post a deferred call to process the data.&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ProcessDataCallback:&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; process the data, display, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if (g_send == TRUE)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; send another "SEND" command to the device.&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(let's ignore for now how g_send is set to false)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If my understanding of how callbacks work is correct, TCPCallback and ProcessDataCallback will cause each other to cycle until g_send is set to FALSE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From my very brief description above, can anyone see a flaw in this design? I welcome any input, but I'm particularly interested in whether a call could somehow be blocked, or fill up and eventually overrun the call stack.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for any input on this.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2013 22:28:54 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2362302#M61435</guid>
      <dc:creator>mzimmers</dc:creator>
      <dc:date>2013-03-23T22:28:54Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2362418#M61436</link>
      <description>&lt;P&gt;I see no real flaw in this design: the deferred callback is fired by TCP callback after receiving a complete message and fires a new message to the device only after terminating handling data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This structure stresses the system (intended as external device and PC application) to the maximum possible throughput, in the sense that each step is executed immediately after the preceding one is completed, without any pause or delay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2013 11:23:37 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2362418#M61436</guid>
      <dc:creator>RobertoBozzolo</dc:creator>
      <dc:date>2013-03-24T11:23:37Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2362472#M61437</link>
      <description>&lt;P&gt;That's a good point about the lack of delays. Perhaps I should put in a short delay after sending the "SEND" commands?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does CVI have any timing mechanisms better than the Sleep() function that's provided by Windows? I've heard that Sleep isn't very precise.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2013 14:18:30 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2362472#M61437</guid>
      <dc:creator>mzimmers</dc:creator>
      <dc:date>2013-03-24T14:18:30Z</dc:date>
    </item>
    <item>
      <title>Rif.: question about callbacks</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2362506#M61438</link>
      <description>&lt;P&gt;Ah..Delay(). Very good.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2013 15:53:17 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/question-about-callbacks/m-p/2362506#M61438</guid>
      <dc:creator>mzimmers</dc:creator>
      <dc:date>2013-03-24T15:53:17Z</dc:date>
    </item>
  </channel>
</rss>

