08-04-2005 04:08 AM
My callback function which reads the values from the Data Socket Server which is running on remote machine. With in callback function i calculate the Alarm condition and generates the alarm if any. On an average 100 alarms are getting generated out of 512 different values which i reading from datasocket server. For all generated alarm i am logging into database (SQL Server 2000) which is presently running on the same machine and also the same alarms i writing to another data socket port. My callback gets event almost every second. Due to these heavy database logging (is it really heavy per sec 100 data base insertion with in a call back ?) i loose the data socket connection after few seconds. Why ? Please advice me
Thanks and Regards
R K Gupta
08-04-2005 10:57 AM
If you need to do something potentialy time consuming, then it is best to NOT do this in any callback function (DataSocket, UI, TCP, etc) - because it will block the upstream processing and could lead to data-loss, etc. Instead, you should consider storing the data in some buffer and using a worker thread to do the time consuming task. This way you can separate the two tasks. Probably, the best way to achieve this in CVI is to use a thread safe queue (see the Utility library functions and thread-safe-queue example programs) to store and process the data. Also, DataSocket has a "polling" model (see DS_OpenEx and the DataSocket polling example program) where you can poll for data instead of getting data-updated events in the callback. You may want to consider one of these approaches (thread safe queue or polling DataSocket model) if you need to do some time-consuming tasks with the data.
Best regards,
Mohan
08-05-2005 07:23 AM
08-08-2005 09:22 AM
Hi Rakesh,
I just meant to give some suggestions that might help you solve your application problems. I was not volunteering to consult on your project. In general, when an application has latencies in executing multiple tasks, one possible solution is to partition the tasks on to different threads, and that was what I suggested. If that is not solving your problem, the latencies might be else where in your application, and you need to do more debugging and analyze the time-behavior of your program to come up with a solution.
Thanks,
- Mohan
08-09-2005 02:21 AM