NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for an example C# Dialog

Can anyone point me to an example of creating a dialog box in c# for use with th e.Net adapter?
 
I have written a c# serial number dialog that accepts input from the keyboard or a barcode reader, but I don't know how to pass the window context to the C# code from TestStand 4.0.
 
Consequently I have bad behavior from my dialog box.
 
Thanks!

Message Edited by John J on 07-14-2007 09:36 PM

0 Kudos
Message 1 of 11
(6,431 Views)

Hi John,

I would be glad to help you with this question. It sounds like to would like TestStand to call a .NET assembly that pops up your dialog and gathers user input. Then, the user input should be passed back to TestStand and your sequence should continue. I think it may be helpful for you to read this previous post (specifically the very last entry):

http://forums.ni.com/ni/board/message?board.id=232&message.id=4707&query.id=109415#M4707

Does this help? Is it necessary for your .NET dialog to open within the TestStand window (as a child), or is it ok if your .NET dialog simply opens when called by your .NET assembly? I am sure that we can work together to get your program up and running.

Regards,

Casey Weltzin
Applications Engineer
National Instruments

 

0 Kudos
Message 2 of 11
(6,410 Views)

Casey,

 

I apologize for not getting back to you sooner, but my world class company just switched providers last week and we completely lost our internet access yesterday.

 

As mentioned, I wrote a replacement serial number entry dialog that also accepts input form a barcode reader.  The device uses a virtual COM port to send data to the PC.  The problem is that when using our custom interface based on the Simple OI, the dialog appears to be the active window, but will not accept keyboard input unless you click on it.  I’ve put a couple of hacks into the code to try and work around the problem with no improvement.  I don’t require the window to be a child of TestStand, but it should at least behave correctly.

 

Yes, the example you linked was helpful in showing me that I'm not doing anything significantly different than what others are doing.  Before seeing that example, I also found the following NI provided example which made me question whether TestStand implements a good .Net interface, but I later realized that it’s just an old example that uses timers to do things that should be handled by events (probably written by a LabVIEW programmer). It’s the computer motherboard dialog in Examples\Demo\DotNet.

 

Since I wrote the post, I discovered that the problem apparently only occurs with the C# Simple OI and any modified versions of that code.  I have attached the VS 2005 project along with a TestStand 4.0 test sequence file which is in the release directory of the project.  This should run without VS 2005 installed.  Also included in the project is a C# dialog test application.

 

Since the code works in VS 2005, the standard TestStand interface, and the other provided interfaces (I have not tried them all), I wonder what is different about the Simple OI.  I have not found anything in the provided code that stands out.

 

Thanks for your help,

 

John Jurisoo

Evaluation Engineer

ATK

 

0 Kudos
Message 3 of 11
(6,385 Views)
Hi John,
 
Thank you for attaching your example code; I will take a look and try to reproduce the issue on my end. I'm confident that we can find a solution that allows you to properly set the keyfocus so that your dialog accepts keyboard input.
 
Regards,
 
Casey Weltzin
Applications Engineer
National Instruments
0 Kudos
Message 4 of 11
(6,352 Views)
Hi John,
 
Good news - after doing quite a bit of research on your issue this weekend I think I have found the perfect solution! The TestStand API exposes a method called NotifyStartOfModalDialogEx just for the purpose of sending another application a handle to the TestStand window (and showing a modal dialog box).
 
Therefore, with a few changes I was able to get your program to work as you desired. Essentially, we need to first pass the TestStand sequence context to your C# dialog (by reference) using the ThisContext object. Next, the NotifyStartOfModalDialogEx method can be used to obtain a handle to the TestStand window. Finally, we can call the ShowDialog(handle) function and instruct TestStand that we are done with the modal dialog by calling NotifyEndOfModalDialog.
 
I have attached a modified GetSerialNumber.cs file for your reference. Please note that you will also need to go into TestStand and pass the ThisContext object into the MySequenceContext parameter that the C# dialog application now expects. In addition, note that it is not standard policy for National Instruments Applications Engineers to write customer code; I felt like it would be a fun challenge in this case!
 
Let me know if you have any additional questions, and I would be glad to help in any way possible. Have a great day John!
 
Regards,
 
Casey Weltzin
Applications Engineer
National Instruments
Message 5 of 11
(6,316 Views)

Casey,

Yes, this is a good solution for my situation, and thanks for going beyond the call on this one.  I do appreciate the effort.  You actually answered my original question, although I asked a broader question in my post.  I wasn't expecting anyone to modify my code, but I certainly had no objections.  I would have been happy with a few pointers, since finding things in documentation is not always a speedy adventure.  I have more trouble with the TestStand classes than I usually do with other packages.  I have not been able to establish an intuitive basic understanding of the  "reason for the design" yet.  It seems a little awkward to me, but it's new to me yet.

it's really a moot point now, but I still wonder what is different about the C# simple interface that exposes this symptom.  This is not really something that I need an answere to, since ignoring who the parent window is can get you into trouble.

If I was ambitious and had the time I would use a dialog that allowed an abort from TestStand, but there is no need for this other thatn during debugging.  I'll go with the working Buick rather than the "to be designed" Cadillac.

Lastly, if anone tries to use the updated code, a reference to the "NI TestStand API" has to be added to the GetSerialNumber project.  Also the TestSNDlg project references the debug version of the GetSerialNumber.dll, so do any testing in VS Debug configuration.

JJJ

0 Kudos
Message 6 of 11
(6,297 Views)

Hi John,

I am glad that the solution I posed will work for you! Off hand, I am not sure why your modal dialog acts differently in the TestStand development environment vs the C# simple OI. On my end, I noticed that the focus issue occurred for the C#, VB, and C++ simple OIs (but not for LabVIEW or CVI).

Have a great day!

Casey Weltzin
Applications Engineer
National Instruments

0 Kudos
Message 7 of 11
(6,269 Views)

Casey,

Yes, that is the same behavior that I saw.  I just didn't get a chance to test them all till after I wrote the post.  It's also funny that the full-featured version of the interface works for those same languages.

Thanks agian for your help.

JJJ

0 Kudos
Message 8 of 11
(6,265 Views)

Hi,

As for me, I am testing the related c# barcode generator these days. Do you have any ideas about it? Or any good suggestion? I am totally a green hand on barcode generating field. Any suggestion will be appreciated. Thanks in advance.


Best regards,
Arron

0 Kudos
Message 9 of 11
(3,788 Views)

Arronlee,

 

I would suggest creating a new thread for your question. You're more likely to get a response that way.

 

Regards,

 

Brandon V.

Applications Engineer

National Instruments 

0 Kudos
Message 10 of 11
(3,773 Views)