Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

datasocket dll with DataUpdatedEventHandler

I tried to write a Measurement Studio DLL file with DataSocket. Here is a part of my program:

I want to install a data updated event handler in the dll:

void CTestdllApp::DataUpdatedEventHandler (CNiDataSocketData &data)
{

//index is member variants of CTestdllApp
index++;
if(index>10000)
index=0;
}

Here is a JNI (Java Native Interface) function which return index:

JNIEXPORT jlong JNICALL Java_DataSocket_GetUpdateIndex(JNIEnv *env, jobject obj)
{

return theApp.index;
}

And in the java program I call this JNI function in a loop like this:
long i;
for(a=0;a<1000000000; a++)
{
i=aTest.GetUpdateIndex();
//GetUpdateIndex() actually is Java_DataSocke
t_GetUpdateIndex() above
//aTest is a object to call DLL
System.out.println("i is: " +i);
}

But I found that the value of i is always the same (Sometimes it's always 3, somethimes it's always 😎 when the loop starts. That is the DataUpdatedEventHandler is stopped after starting the loop.

Please tell me why this happened? And any idea how to make this DataUpdatedEventHandler keep monitoring?

Thank you very much in advanced!
0 Kudos
Message 1 of 5
(3,468 Views)
Have you installed the event handler via the InstallEventHandler method?

Also, since you're working with DataSocket in Java, you may want to check out the DataSocket JavaBean.

- Elton
0 Kudos
Message 2 of 5
(3,468 Views)
thanks for you answer. Yes, I did installed the handler in the conatructor:

CTestdllApp::CTestdllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_DataSocket.InstallEventHandler(*this, OnDataUpdatedEventHandler (CTestdllApp, DataUpdatedEventHandler));
}

Any idea? Thanks!!
0 Kudos
Message 3 of 5
(3,468 Views)
Just to make sure, have you called Connect before running your test? Also, what access mode are you using? If you're reading data, you will probably want to use CNiDataSocket::ReadAutoUpdate. If you're using CNiDataSocket::Read, you'll have to explicitly call Update before you'll get the event.

- Elton
0 Kudos
Message 4 of 5
(3,468 Views)
Thanks for your relpy. Yes. I have done all these thing. But it didn't work. I have found anohter problem related to this question, would you please take a look my new question:

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=5065000000080000005D550000&USEARCHCONTEXT_CATEGORY_0=_48_%24_7_&USEARCHCONTEXT_CATEGORY_S=0&UCATEGORY_0=_48_%24_7_&UCATEGORY_S=0
0 Kudos
Message 5 of 5
(3,468 Views)