Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

The right thread use with NI DAQ measurement

Arbo,

 

You might consider looking elsewhere for information on thread locking and file manipulation. I am happy to help you with any problems acquiring data or using National Instruments functions to log it, but I am not a .NET/C# developer. I would recommend posting on MSDN forums or stackoverflow.com.

 

 

0 Kudos
Message 11 of 15
(1,091 Views)

HI

thanks for your helpful notes. i will post related post about threads in stackoverflow com

 

but do u know something about strange behaivior of NI DAQ

when i'm using continuous mode for generation and acquisition of NI DAQ 6343 i get more precise data.

 

when i'm using finite mode for something 4000-6000 samples, the precision downgrades,  the differences about 0.1 up to 1%

 

0 Kudos
Message 12 of 15
(1,088 Views)

Arbo,

 

That sounds like a great question for the DAQ forums.

 

http://forums.ni.com/t5/Multifunction-DAQ/bd-p/250

0 Kudos
Message 13 of 15
(1,085 Views)

I don't know if this is related to the wrong result you get but I see a potential problem in your code:

 

the line 

 

 WriteTextAsync(data[i].ToString(), tx, pass_freq);

initiates an asynchronous write but uses data contained in global class variables. At the time the writing is performed it is not guaranteed that these variables will have the right values because in principle the next callback may occur because the write is done.  

 

To correct this you need to pass a copy these variables along with the delegate. In other words,  if you define a delegate like in

 

 inputCallback = new AsyncCallback(InputRead);

 

but you want each instance of inputCallback to access  different copies of these variables, you should encapsulate the delegate (here InputRead) in a new class containing the copy of the data needed by the callback and pass the class instance, this is a standard procedure. So you would have something like this:

 

myCallbackDelegate  = new  myCallbackClass(data, tx, pass_freq);  //initialize with copies of the data needed by the callback 
inputCallback = new AsyncCallback(myCallbackDelegate.InputRead);

The new class myCallbackClass to create will contain only copies of the data and the callback function InputRead. Then InputRead callback will be called as a member of the new instance of the class so that it will get access to the copies you created before.

 

Otherwise you can of course use a simple synchronous "WriteText" and see if it helps. 

 

 

0 Kudos
Message 14 of 15
(914 Views)

it should rather be

myCallbackDelegate  = new  myCallbackClass(tx, pass_freq); 

and "data" should be only copied after it is read in the InputRead function 

0 Kudos
Message 15 of 15
(912 Views)