LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

using timers

I am using a 100msec timer control in my application. When I FTP a large file using "InetFTPSendFile" the timer is not entered during FTP. Is there a way to continue entering the timer interrupt while FTPing?

 

Thanks

0 Kudos
Message 1 of 11
(5,182 Views)

Hi,

 

An immediate solution would be using the Async Timer facility.

 

It is available as a separate .fp that you need to add to your project.

Search for the asynctmr.fp file in your CVI installation.

 

It runs in its own thread, so it is not effected by other time consuming opertions in your program.

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 11
(5,178 Views)

Thanks.

 

Getting an link error when I added the code;

 

I included :

"#include "asynctmr.h" in my main file.

 

I then put in:

int CVICALLBACK MyTimerCallback (int reserved, int theTimerId, int event,
                                 void *callbackData, int eventData1,
                                 int eventData2);

 

I then put in Main:

   NewAsyncTimer (1, -1, 1, MyTimerCallback, NULL);

 

I then created a simple thread function:

int CVICALLBACK MyTimerCallback (int reserved, int theTimerId, int event,
                                 void *callbackData, int eventData1,
                                 int eventData2)
{
    static int a = 0;
    a ^= 1;
    SetCtrlAttribute (repPanel, REPROPANEL_LED, ATTR_CTRL_VAL, a);
    ProcessDrawEvents();
    return 0;
}

When I build and link I am getting this error:

1 Project link error

  Undefined symbol '_NewAsyncTimer@24' referenced in "PASS II.c".

 

Can you help me with this? I'm sure it's somthing simple I am missing.

 

Thanks!

JW


 

 

0 Kudos
Message 3 of 11
(5,167 Views)

Please ignore the last post, I forgot to add the asynctmr.fp to my project.

 

The async timer is running but I am still having a problem.

The async timer is simply an led that flashes on and off. In the main program I go out and try to connect to an FTP client. While attempting to connect, the led in the async timer stops flashing. Is there something else I need to do to keep entering the async timer so that the led keeps flashing when I am connecting or FTPing files?

 

Thanks
JW

0 Kudos
Message 4 of 11
(5,162 Views)

Are you sure the async timer is not working? That is, you may only be having a problem in updating the GUI.

On one hand you should not manipulate GUI objects from a thread that dows not owns it (in your case the timer callback).

On the other hand, you GUI may be freezed while performing FTP access so that you do not see the led flashing but the timer callback is still working.

 

To perform a different test you should:

  • Have the timer count up on a static variable once per second and display it on screen (OK, I told you not to do so: consider it a poetic licence for testing purposes only Smiley Wink )
  • Calculate the time elapsed in FTP functions by a difference in Timer () count
  • Compare the two values


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 11
(5,154 Views)

Yes, you are right, the async timer is working properly, the gui is just not updating the LED.

How do I get around this?

I'm just trying to give the user some kind of indication that the program is still working while FTPing large files. A simple LED on/off would suffice.

 

Thanks!
JW

 

0 Kudos
Message 6 of 11
(5,136 Views)

One possible solution could be to spawn a separate thread with its own GUI to flash the led. Specifically, the thread routine should load and display the panel and then stay in a loop flashing the led until a signal is issued to it to terminate; the panel must be discarded at the routine end.

 

An alternative is to move FTP functions in the separate thread: this could be useful if you want the user to be able to do other things in the main thread during FTP transfer.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 7 of 11
(5,129 Views)

Thanks!

I'm pretty new to this so please bear with me.

When you say spawn a new thread, can this be the Async timer I created? Would I then launch a gui with the LED right from the Async timer and then cancel it when complete in the async timer?

 

Thanks!

JW

0 Kudos
Message 8 of 11
(5,123 Views)

Well, the problem with the timer callback is that it is executed repeatedly so you must identify when to start using the GUI and when to discard it.

 

Working with the timer is a little bit complicated since its callback is not constantly executing, while a thread function is so it's easy to load the panel at callback entrance and unload it at callback end. You can use a static variable in timer callback to hold the panel handle so that it is maintained over several executions of the callback: if the variable is 0 you know you have to load and display the panel. More difficult is to detect when to unload the GUI: you may try manually sending EVENT_CLOSE or EVENT_DISCARD to the callback: once received the event the callback can discard the panel and then exit. Alternatively you may use a global variable as a flag but as you know globals are not an example of good programming style: they indeed work but they are prone to several misuses and problems so you should avoid using them.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 9 of 11
(5,120 Views)

Thanks!

I did get it to work. When I start the FTP transfer, I launch a separate panel within the async timer which has an LED that toggles when going into the Async Timer. When the FTP transfer is complete I discard the LED panel.

I am using a global variable to signal the async timer to launch and discard the panel.

Thanks for the help! I'm slowly getting there!

 

John W.

0 Kudos
Message 10 of 11
(5,110 Views)