DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

C# application doesn't start if DIAdem is not installed on the computer

Solved!
Go to solution

Hello,

 

I made a C# application including measurement studio forms.

One feature of the application is that I can start DIAdem and open then a tdms file - that is working.

But if I install the application on a computer without a DIAdem installation the C# application doesn't start anymore.

 

Is there are opportunity to tell C# not to load the diadem.dll or is there a pseudo DIADEM what tells the DLL DIAdem is not accessible?

 

Best Regards Joerg Koch

0 Kudos
Message 1 of 8
(5,031 Views)

Hi Joerg,

 

What is this "diadem.dll" that you refer to?  the normal mechanism to communicate with DIAdem from an outside compiler is to use the DIAdem ActiveX servers (DIAdem.ToCommand and DIAdem.ToDataSheet).  If you use this method, then you can attempt to connect to either of these ActiveX servers with error suppression engaged-- you either get back an object variable or you don't.

 

The other point is that you don't really need DIAdem to open a TDMS file.  You mention that you have MeasurementStudio forms, but MeasurementStudio has a built-in API to read and write TDMS files.

 

How is your C# application really communicating with DIAdem?

Brad Turpin

DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 8
(5,011 Views)

Hey Brad,

 

if you add the Reference DIAdem in your visual studio project, the file Interop.DIAdem.dll is added to your executable later.

See the the attached picture.

 

I like to open the selected TDMS file in DIAdem for more analysis with the following code

 

private

{

    // Bring DIAdem to front when we open it and display the View window

void ButtonOpenTdmsInDiadem_Click(object sender, EventArgs e)

   oDIAdem.CmdExecuteSync("WndShow('SHELL','MINIMIZE')");

   oDIAdem.CmdExecuteSync("WndShow('VIEW','Show')");

   // delete all entries

   oDIAdem.CmdExecuteSync(

   // open the selected Diadem file

   oDIAdem.CmdExecuteAsync("DataFileImport('" + tdmsFileName + "')");

"DATADELALL(True)");

 

The problem isn't to find out if DIAdem is installed, the problem is the application is starting the DIAdem interface when it is lunched.

 

Best regards

Joerg

 

0 Kudos
Message 3 of 8
(4,997 Views)

Hi Joerg,

 

Unfortunately I'm advising you with one hand tied behind my back, because I've only dabbled in C and never to the extent of calling out to any other program's ActiveX interface.  I have controlled DIAdem many times from LabVIEW and VBScript using DIAdem's ActiveX servers, and the commands sent are identical to what would be sent from C.  What's not identical is the linking and compiling details, which are completely hidden or absent in LabVIEW and VBScript.

 

Still, I really don't understand why DIAdem would launch when you start your C# program, unless your C# program is invoking an ActiveX object immediately when it launches.  If you are intentionally doing this, then I'd like to recommend that you restructure that command so that your program has a chance to launch without DIAdem.  When you run a LabVIEW or VBScript program that controlls DIAdem, the DIAdem icon never appears in the system tray UNTIL the first ActiveX call is made to DIAdem, so I have to believe there is a way to organize your C# code to achieve the same result.  I suppose it's possible C# may automatically launch all servers declared in the compiled code, but I would consider that a language architecture flaw for this particular application.

 

Can you comment on when your first DIAdem.ToCommand or DIAdem.ToDatSheet call occurs in your C# code?

 

Brad Turpin

DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 4 of 8
(4,986 Views)

Hi Brad,

 

 

 

thanks for your comments.

You are right, the problem was the location of the intialization of the DIAdem class.

Also I haven't had an exception handler.

 

The following code is now working.

 

It has only one little issue now, that to keep DIAdem open you have to start it first before you push the butten.

If not DIAdem will close as soon as you click on the C# application again, because the DIAdem instance is destroyed after the sub programm is finished.

 

 

using DIAdem;

 

private void ButOpenTdmsInDiadem_Click(object sender, EventArgs e)

 

{

 

  try

 

  {

 

 

    this.Cursor = Cursors.WaitCursor;

    // the new command will cause an exception if there is no DIAdem installed on the computer

 

 

    DIAdem.TOCommand oDIAdem = new DIAdem.TOCommand();

 

 

 

    // Bring DIAdem to front when we open it and display the View window

 

 

    oDIAdem.CmdExecuteSync("WndShow('SHELL','MINIMIZE')");

 

 

    oDIAdem.CmdExecuteSync("WndShow('VIEW','Show')");

 

    // delete all entries

 

    oDIAdem.CmdExecuteSync("DATADELALL(True)");

 

    // open the selected Diadem file

 

    oDIAdem.CmdExecuteAsync("DataFileImport('" + tdmsFileName + "')");

 

    this

  }

  catch

  {

.Cursor = Cursors.Default;

    // if there is no DIAdem installed we hide the control to move open the tdms file in DIAdem

    ButOpenTdmsInDiadem.Visible = false;

  }

}

0 Kudos
Message 5 of 8
(4,983 Views)
Solution
Accepted by topic author JoergLee

Hi Joerg,

 

I'm glad you hear you're making progress.  The DIAdem ActiveX servers will by default connect to any already existing DIAdem instance and leave it unmolested when they end.  If instead no DIAdem instance exists when the ActiveX server is invoked, then the ActiveX request will start a dependent child DIAdem instance that shuts down automatically when the calling program ends.  What most people do is create the ActiveX connection variable at the beginning of the application and hang onto it until the very end of the application, even if no DIAdem activity is happening for long stretches of time.  If the connection object variable persists, so will the DIAdem instance, even a dependent child DIAdem instance.  Do you think that would be an option for you?

 

Brad Turpin

DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 6 of 8
(4,963 Views)

Hi Joerg,

 

Can you please tell me where did you the diadem.dll or interop.DIAdem.dll??

 

Thanks in advance.

EagleEye.

0 Kudos
Message 7 of 8
(4,176 Views)

Hello EagleEye,

 

I can find the Interop.DIAdem.dll in the ../obj Folder of my C# project. Later the compiler transfers it to the .../bin folder.

 

Cioa Joerg

0 Kudos
Message 8 of 8
(4,150 Views)