08-15-2007 07:35 AM
Obviously, the Specify module dialog does more than only setting the FunctionName property when I choose a function. I have tried to find a TestStand API function that I can call in order to get it working, but without success. Unloading the module doesn't help, nor does LoadPrototype (which returns false as my dll functions are declared extern "C").
There is another little problem that might be related to this: The step description in the sequence view is not updated. It should show "FunctionName (ModuleName)", but when changing the function name via the API, it keeps the old value. The tooltip works, though! This reminds me of an older post, but the answer doesn't help me:
http://forums.ni.com/ni/board/message?board.id=170&message.id=203375&query.id=334292#M203375Thanks for your help!
Matthias
08-24-2007 03:21 AM
08-27-2007 06:11 AM
Hello Nikolai,
I have been able to simplify the problem:
As it seems, changing the DllModule.AsCommonCModule().FunctionName does not work. After changing the function call via the API, the previous function is still called until you reload the sequence.
I have attached two VS2005 projects:
One .NET project containing the edit dialog (EditTestFunctions)
One C project containing two exported functions (TestFunctions). Each function does nothing but showing a Message box with the function name.
I also included a sample sequence in the zip file.
If you follow these steps, you will (hopefully) see my problem: Open the sequence, run it and check that the test step shows the correct function name. Open the edit dialog, check the other radio button, click OK. In the specify module dialog, you will see that the function name was actually changed. Running the sequence again still shows the other function name. Save the sequence, close and re-open it, and the sequence will run correctly.
I am using TestStand V3.5
Thanks
Matthias
08-27-2007 09:08 AM
08-27-2007 09:50 AM
08-27-2007 10:14 AM
Hi,
you are right. If I call UnloadAllModules or Module.Unload, the correct function will be executed. But there is another problem that still isn't solved (I simplified my example a bit too much):
If the two functions have different parameters, they are not called correctly. I have changed my code like this:
private
void ConfigDialog_FormClosing(object sender, FormClosingEventArgs e){
_seqContext.Engine.UnloadAllModules();
DllModule dllModule = _seqContext.Step.Module as DllModule; if (dllModule != null){
while (dllModule.Parameters.Count > 1){
dllModule.Parameters.Delete(1);
}
if (rbOne.Checked){
dllModule.AsCommonCModule().FunctionName =
"FunctionOne";dllModule.Parameters.New(1,
"param1", "1", DllParameterCategories.DllParamCategory_Numeric, CommonCParameterPassOptions.CParamPass_ByVal, CommonCParameterTypes.CParamType_Int32);}
else{
dllModule.AsCommonCModule().FunctionName =
"FunctionTwo";dllModule.Parameters.New(1,
"param1", "2", DllParameterCategories.DllParamCategory_Numeric, CommonCParameterPassOptions.CParamPass_ByVal, CommonCParameterTypes.CParamType_Int32);dllModule.Parameters.New(2,
"param2", "3", DllParameterCategories.DllParamCategory_Numeric, CommonCParameterPassOptions.CParamPass_ByVal, CommonCParameterTypes.CParamType_Int32);}
}
base.OnClosing(e);}
The functions in the C dll look like this, now:
__declspec
(dllexport) void FunctionOne(int param1){
AFX_MANAGE_STATE(AfxGetStaticModuleState());
char buffer[100];sprintf(buffer,
"FunctionOne, param1 = %d", param1);AfxMessageBox((LPCTSTR)buffer);
}
__declspec (dllexport) void FunctionTwo(int param1, int param2){
AFX_MANAGE_STATE(AfxGetStaticModuleState());
char buffer[100];sprintf(buffer,
"FunctionTwo, param1 = %d, param2 = %d", param1, param2);AfxMessageBox((LPCTSTR)buffer);
}
Now, after changing the function name, the correct function is executed, but with wrong parameters. If I execute FunctionTwo first and then switch to FunctionOne, param1 of FunctionOne is 0 instead of 1. When I look at the RAM in the debugger, I can see that the parameter value 1 is at an address 4 bytes too high. The other way round (first FunctionOne then FunctionTwo), param1 of FunctionTwo gets the value for param2 (3), param2 is 0.
Are there more Unload functions that take care of the parameters as well?
Thanks!
Matthias
08-28-2007 02:29 AM
08-28-2007 03:22 AM
Hello,
the error with Function Two occurs when you save the file while Function One is selected, close it and open it again. After that, Function One works and Function Two doesn't. But even if the error was only with Function One: There must be a possibility to get this to work because when I do the changes manually in the Specify Module dialog, everything works. As far as I know, the sequence editor also uses the TestStand API, so if I find out which API functions it uses, my code should work, too.
I'm afraid I cannot switch to TestStand 4.0 in this project.
Regards,
Matthias
08-29-2007 10:05 AM
// Unload module because we changed the module specification.
_seqContext.Step.Module.Unload();
// Clone module and replace it with the clone to clear the cached parameter information.
PropertyObject module = dllModule as PropertyObject;
PropertyObject moduleClone = module.Clone(string.Empty, PropertyOptions.PropOption_CopyAllFlags | PropertyOptions.PropOption_DoNotShareProperties);
module.SetPropertyObject(string.Empty, 0, moduleClone);
// Increment change count so Sequence Editor refreshes.
_seqContext.SequenceFile.IncChangeCount();
08-29-2007 11:21 AM
Thanks a lot, that solves all the issues!
Regards, Matthias