12-08-2011 03:14 PM
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
12-09-2011 01:21 AM
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.
12-09-2011 10:18 AM
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
12-09-2011 10:58 AM
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
12-09-2011 04:53 PM
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:
12-12-2011 08:07 AM
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
12-12-2011 09:05 AM
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.
12-12-2011 09:20 AM
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
12-12-2011 09:44 AM
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.
12-12-2011 10:30 AM
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.