External DLL calls eventually crash DF


Recommended Posts

I am using external function calls to a DLL driver so that I may communicate with an Omega TC-08 USB device. I have set up Test channels with timing of zero. I am using a sequence that loops in order to repetitively read the data from the driver. It will work for a few minutes, and then it starts acting strange.

The problem I am having is that DF will freeze up intermittently when this sequence is running. I get all sorts of errors such as the Timing Lag error, "unknown error in the DLL", and "comm thread error". About half the time, DF will halt and then just terminate. The other half the time, it just consumes 99% of my CPU time.

My sequence loop is set to repeat every 5 seconds, I am using the Delay() function. I have the "Sequence Loop Check" checkbox checked in the Preferences window, and set to 200 steps per second.

Should I adjust the timing on my Test channels?

I have all errors set to be ignored by using ignore("all"). However, I will still get the comm thread error and unknown error in the DLL errors on the Alert window. I cannot seem to find out what error code they have. All this instruction seems to do is to get rid of the Timing Lag error.

Any insight would be great, thanks.

Link to comment
Share on other sites

First of all, never use ignore("all"). The only reason that function even exists is for backwards compatability between release 3 apps and release 4. If you have errors, you want to know about them, or you want to do something productive with them. You should use try/catch instead and at a minimum put ? strLastError in the catch block so you can see the error.

DLL issues are always tricky because DAQFactory can only do so much to protect against them. I've seen a case where the DLL had a memory leak and gradually killed DAQFactory. Anyhow, in your case the most likely cause is that the DLL is not thread safe, meaning you can't call into it from different threads. If this is true, you need to put all your DLL calls in a single sequence. You can't call them from channel events, multiple sequences, button actions or any where else. You can create sequence functions if you wanted, but those need to be called from an overall base sequence that runs in a loop. This ensures that the DLL only gets called from one sequence and thus one thread. It also may be possible that the DLL can only be called from the primary thread of the application, but hopefully this is not true.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.