Calling All Test Engineers: Try Visual Studio .NET

June 23, 2003
Become more creative by taking advantage of this open software standard to install, manage, and grow your test-development environment.

DESIGN VIEW is the summary of the complete DESIGN SOLUTION contributed article, which begins on Page 2.

Over the years, engineers developing applications to control T&M equipment have employed a variety of languages and development environments. And it's often the comfort level of those engineers doing the programming that determines just which programming language they choose, rather than overall value, ease of use, scalability, or capabilities.

A number of individuals or groups support products through the entire product life cycle, so often companies must manage and maintain multiple, in-house built applications. This includes the various in-house experts with their numerous programming languages. Also, some 90% of all test equipment connects to a computer or a network.

It needn't be this way, though. The Microsoft Visual Studio .NET open development environment lets T&M programmers boost productivity, reduce costs, and accelerate time-to-market. With this standard, they can install, manage, and grow their environment. More importantly, those working within the .NET platform to create and test new products can focus their creativity on solutions while leveraging a well refined development platform.

This article explores the portions of the .NET platform that are most important to the daily lives of design and test engineers. Discussed are the two parts of the new .NET environment that are key to writing "Plain Old Windows Applications": the .NET Framework comprising the Common Language Runtime (CLR) and Framework Class Library (FCL), and the VS.NET development environment.

Because the .NET platform is language-neutral, all .NET languages are first-class players. Described are the languages provided by Microsoft, which include Visual Basic, C++, the brand-new component-oriented C#, and J#. There are also third parties creating .NET languages for FORTRAN, Perl, Pascal, Python, COBOL, and others.

It's expected that engineers will experience up to a 50% decrease in time spent programming instruments and displaying data by working within the .NET homebase and leveraging .NET code portability.

HIGHLIGHTS:
.NET In A Nutshell The .NET platform has two main parts for writing Windows applications, the .NET Framework and the VS.NET development environment.
Framework Class Library Design Goals A key element within the .NET Framework is the Framework Class Library (FCL). It consists of a huge set of new classes, types, and objects that Microsoft developed over the last four years.
Languages: Visual Basic, C#, C++ The language-neutral .NET platform means that you can use components built from different languages in whatever .NET language you prefer. Microsoft provides Visual Basic, C++, and the new C#. The article digs into the latest advances included in the Microsoft-provided languages.
VS.NET IDE The biggest change in the development environments is that all of Microsoft's .NET languages can be used within the same interactive development environment (IDE).
T&M Toolkit A step-by-step procedure, using the T&M Program-mers Toolkit, is given on how to write a simple application that will query an instrument's IDN string and display it very quickly.

Full article begins on Page 2

Over the years, engineers developing applications to control T&M equipment have employed a variety of languages and development environments. And it's often the comfort level of the engineers doing the programming that determines just which programming language they choose—rather than overall value, productivity, ease of use, scalability, or capabilities. A number of individuals or groups support products through the entire product life cycle, so often companies must manage and maintain multiple, in-house built applications. This includes the various in-house experts with their numerous programming languages. Also, some 90% of all test equipment connects to a computer or a network.

But it doesn't have to be this way. The Microsoft Visual Studio .NET environment, arguably the most open (and certainly biggest market share) development environment, will let T&M programmers boost productivity, reduce costs, and accelerate time-to-market. They will now be able to work with an open software standard to install, manage, and grow their environment. More importantly, developers who choose to work within the .NET platform to create and test new products will be able to focus their creativity on solutions while leveraging a development platform refined over the past five years. This will enable managers to draw upon a larger pool of developers and protect their investment in the creation of intellectual property.

This article explores the portions of the .NET platform that are most important to the daily lives of design and test engineers. But first, a little background information may prove useful.

Microsoft released C# in June 2000. In August, Microsoft, Hewlett-Packard, and Intel co-submitted the specifications for the Common Language Infrastructure (CLI) and C# to the European Computer Manufacturers Association (ECMA) International's programming language technical committee (TC39). Then the co-sponsors, together with other ECMA members, including IBM, Fujitsu, Plum Hall, and Monash University, and expert guests such as ISE and Ximian, refined these specifications for approval as ECMA standards.

In December 2001, the ECMA General Assembly approved the first edition of the C# and CLI standards as ECMA-334 and ECMA-335, respectively. A technical report on the CLI, ECMA-TR84, was also approved. ECMA then submitted the two standards and the technical report to ISO/IEC JTC 1 for Fast-Track adoption. In April 2003, ISO/IEC published the standards, and they will formally be known as ISO/IEC 23270 (C#), ISO/IEC 23271 (CLI), and ISO/IEC TR 23272 (CLI TR).

Given all of the above, productivity in the T&M world would benefit greatly from a move to a programming environment based on an open software standard. Adoption of an open standard established by the computer industry would allow T&M engineers to fully exploit the gains in computer technology that have blossomed over the last decade. More importantly, such tools as the Agilent T&M Toolkit (described later) would let T&M programmers realize large productivity gains by solving T&M specific problems, while remaining in the open-software-standard environment.

.NET IN A NUTSHELL Two parts of the new .NET platform are important to writing those "Plain Old Windows Applications." The first is the .NET Framework comprising the Common Language Runtime (CLR) and the Framework Class Library (FCL). The second is the VS.NET development environment (Fig. 1).

As the name denotes, the CLR is a runtime that's usable by all of the different .NET programming languages. It was built to try to simplify development and is "object-oriented" to the core. That means classes and inheritance are fully supported—even across languages. A class written in VB.NET can be inherited from it in another language such as Managed C++ or C#, and vice versa.

Note: If you have been programming ActiveX/Component Object Model (COM) components or servers, you have probably been using one or more of the following to build those components: C-runtime library, the Visual Basic (VB) runtime library, the Standard Template Library (STL), the Active Template Library (ATL), Microsoft Foundation Classes (MFC), or the Windows Application Programming Interfaces (APIs). Using C# or VB to build those objects eliminates the need for almost all of the very arcane programming knowledge previously required. You won't have to deal with registration of classes, GUIDs, or IDL files. You won't have to check the HRESULTs return codes from functions, cast IUnknown pointers, make sure you have the AddRef/Release reference counting exactly right, or call CoCreateInstance. When you program with C# or VB.NET—or any of the other .NET-connected languages—you needn't waste time learning the arcane minutiae of COM/ATL/MFC programming. Now software engineers can create useful components almost immediately, instead of going up the very steep learning curve required in the past.

Microsoft did a good job of backwards compatibility with COM/ActiveX components. They can be imported easily for use as .NET objects. VS.NET and the freely downloadable .NET Framework SDK provide mechanisms to easily export .NET classes as COM classes with no extra work. There are, of course, a few caveats.

One new feature of the CLR is that all .NET objects are garbage collected. Programmers won't have to deal with stray (dangling) pointers, memory leaks, missing object releases, and so forth. Memory leaks in managed code will be a thing of the past. Traditionally, this consumes a fair amount of time in software development and causes many defects.

The CLR also permits all exception handling to now be "structured." In VB6, you use unstructured exception handling to deal with errors in code. The typical use-case was to place an "On Error GOTO" statement at the beginning of a block of code to handle any errors occurring within that block, with a corresponding label farther down in the block.

In VB.NET (as well as C#), structured exception-handling code detects and responds to errors during execution by combining a control structure with exceptions, protected blocks of code, and filters. Structured exception handling happens via a "Try" statement, which consists of three kinds of blocks: Try, Catch, and Finally.

A Try block is a statement block that contains the statement to be executed. A Catch block is a statement block that handles an exception. A Finally block contains statements to be run when the Try statement is exited, regardless of whether or not an exception occurs. The Throw statement, used in conjunction with a Catch block, raises an exception that's represented by an instance of a type derived from the System Exception class.

Exceptions are fully built into the languages, which means you don't have to check every function return value using Boolean data types or HRESULTs from COM objects. This is much better than in the past. How many times have you not bothered to check to see if the function you call returns a "pass" or a "fail" because you "know it will never fail"? And then you find out it does fail?

The CLR is also usable with any language built for .NET. This lets application components written in one language be used in multiple other languages. So it's now much easier to share the components among different languages.

In the past, it was pretty difficult to write components that could be shared between C++ and VB. This should now be a thing of the past. You can choose to write some components in VB.NET and use them (and extend them through inheritance) in C#, MC++, or any of the other .NET languages. The tools in the environment are also the same for all languages. Therefore, the debuggers, profilers, code-coverage analyzers, etc., work for all languages. Finally, there's also only one development environment to learn—Visual Studio .NET. Many developers often didn't use more than one environment, but when they did, it took quite a bit of mental "energy" to rapidly switch between environments.

FRAMEWORK CLASS LIBRARY DESIGN GOALS The second main part of the .NET Framework is the FCL. This library is the huge set of new classes, types, and objects that Microsoft developed over the last four years. It should make programming quite a bit easier because it creates easy-to-use objects that handle lots of the low-level work you would have had to write yourself with earlier programming languages. Another benefit of the FCL is that it unifies all of the application programming models. Figure 2 shows the migration over time for the different application programming interfaces (APIs). In the past, you had to learn different APIs depending on what language you used. The consistent API available in any .NET language really makes it simple to use. It's also factored and extensible because most of the framework allows you to inherit from it, as well as make changes if you don't like what the base classes are doing. SIMPLE TO USE The FCL is organized in hierarchical namespaces and classes. It's far easier to find the API you're interested in compared to the "old days" of looking through the Windows API, which organized its 3000+ functions alphabetically. (The help system did organize things a little bit better, but the API wasn't organized like the Framework object hierarchy.) The Framework also has a unified-type system, which means that everything is an object. So, there are no Variant data types; there is exactly one string type; all character and string data is Unicode; etc. For those COM and MFC programmers out there, this is a huge improvement. All properties, methods, events, and attributes are first-class constructs. Many .NET classes are available for you to extend through inheritance. Unlike COM, you're using and extending the class itself, not a "wrapper" on the class. This allows for cross-language inheritance.

With approximately 2200 public classes, 33,200 methods, 16,400 properties, and 4200 events inside this framework, the FCL is enormous. Therefore, a challenge for those who want to become proficient in .NET is to find the parts of the .NET framework that are going to be immediately useful to them—and learning those well. Engineering teams have found that they have sometimes implemented a class or data structure thinking that it didn't exist in the FCL, only to find out later that it did. It pays to spend some time searching the documentation and asking other .NET-savvy programmers before embarking on a new class/data structure design.

LANGUAGES Because the .NET Platform is language neutral, all .NET languages are first-class players. This means you can use components built from different languages in whatever .NET language you prefer. Consider that you can leverage your existing skills far easier than if you had to learn another language and development environment. The language neutrality of the framework allows consumers of .NET components to easily use all of the components in any language.

Microsoft is providing Visual Basic, C++, C#, and J#. Third parties are creating .NET languages for FORTRAN, Perl, Pascal, Python, COBOL, and a host of others. See the complete list at http://msdn.microsoft.com/vstudio/
partners/language/default.asp
.

VISUAL BASIC .NET Some pretty big enhancements were made to the Visual Basic language, many of which have been requested by the Visual Basic user community over the years. VB.NET is a "peer" language to C#.NET and C++ because it offers all the advantages of the .NET Framework while retaining the VB syntax. VB.NET has been improved to support object-oriented programming with new features such as implementation inheritance, overloading, and parametrized constructors. It includes true structured exceptions, optional stricter type checking, and a single form of assignment. For instance, in VB.NET,
Dim X As Integer = 1

is equivalent to these statements in VB6:

Dim X As Integer 
X = 1

The language changes are heavily documented on the Web and in print. Go to http://msdn.microsoft.com/vbasic and look for links pointing to language changes. The book Upgrading VB6 to Visual Basic .NET covers the subject very well.

The VB runtime (named msvbvm60.dll) is replaced by the CLR, and every feature of the .NET Framework is directly available to VB.NET programmers. This is a boon for VB programmers who have seen several important Microsoft APIs primarily target C/C++ programmers in the past. With the .NET Framework, any new Microsoft API—and everything we hear from Microsoft indicates that most new APIs in the future will be introduced as a .NET API—will be equally usable by VB.NET as it is by C# or Managed C++. The Framework is substantially larger than the old VB runtime.

When moving existing code to the .NET Framework, Visual Studio .NET Professional and higher editions provide an Upgrade Wizard that will "upgrade" code to VB.NET. Anything the upgrade wizard doesn't know how to convert is marked with "TODO" in the upgraded code. In addition, it builds a report of any issues that it found. Note that this wizard isn't available in the VB.NET 2002 Standard Edition but has been added to all editions of VB.NET 2003. Microsoft routinely says that the conversion handles 95% of the job.

According to Microsoft, the VB.NET Upgrade Wizard has been improved in Visual Studio .NET 2003 (over VS.NET 2002) to enable even more existing VB 6.0 code to be upgraded. VB.NET 2002 didn't support converting VB6 User Control Projects, but this was added in VB.NET 2003.

Microsoft's Web site contains extensive documentation on making the transition from VB6 to VB.NET. Many books that cover the subject are available as well (see the Recommended Reading section at the end of the article).

C# A brand-new language developed for .NET, C# is the first component-oriented language in the C/C++ family. C# has all of its properties, methods, events, attributes, and XML documentation in one place. There are no header files and no IDL files. It can be embedded in ASP.NET pages. The language was built to simplify C++, yet preserve its heritage. Use of legacy C/C++/COM code can be accomplished through P/Invoke and COM Interop. Also, the .NET Framework contains millions of lines of C#.

For a good white paper on the differences between VB.NET and Visual C# .NET, search the Microsoft site by keying in Microsoft Knowledge Base Article (white paper) 308470 "Differences Between Visual Basic .NET and Visual C# .NET." There is a good white paper on the Agilent ADN Web site that further explores features of both C# and the .NET Framework, illustrating how C# can be more productive and safer than C/C++ for test and measurement software development. Go to www.agilent.com/find/adn and search for the white paper titled "C#: A More Productive Alternative to C/C++ for T&M Software Development."

C++ The short answer is that it's still C++. Microsoft added 14 new keywords to the language that make up the "managed extensions for C++" (MC++). Nothing was taken away from the language. In fact, you can still compile native applications (that don't use .NET) via VC 7.0. MC++ lets you mix native C++ and managed code, allowing you to gradually migrate code to .NET instead of porting the entire code base. The ability to mix existing C++ code with new managed code allows you to get full access to the .NET Framework Class Library in your C++ application. There's a lot of material written about how and when to mix managed code and unmanaged code, as well as how to port an application into the managed world of .NET. Go to the Microsoft MSDN site (www.msdn.microsoft.com) and search for "C++ managed port."

Visual Studio .NET 2003 added support for the Windows Forms designer, which offers C++ developers the same ease in building rich Windows-based applications as VB.NET or C# developers. In VS.NET 2003, developers using Visual C++ will also find that the key metric for measuring code portability, ANSI/ISO compliance, is increased significantly. The ANSI/ISO C++ standard is the generally accepted standard for the C++ language, and all C++ compiler vendors measure compatibility against this standard. See the Recommended Reading section for a link to a 1991 article on C++ conformance.

VS.NET INTERACTIVE DEVELOPMENT ENVIRONMENT The biggest change in the development environments is that all of Microsoft's .NET languages can be used within the same Interactive Development Environment (IDE). In fact, a number of non-Microsoft languages integrate into the VS.NET IDE. There aren't separate environments for VB, C++, and VJ++, as in Visual Studio 6. The new environment most closely resembles the Visual Basic development environment, so most VB programmers will be immediately comfortable with it.

The IDE is fully extensible and programmable. It has a new feature called dynamic help. This is where the IDE "knows" what language keyword/component you're working on and changes the dynamic help pane accordingly. Debugging with different languages is done easily—in the same debugger. You won't have to hassle with the mechanics of debugging a project built with VB and C++ components. Remote debugging is also much easier. This was possible in C++, though nontrivial, and not possible in VB6. The bottom line for debugging is that you can simultaneously debug multiple programs, using multiple languages, on multiple machines.

A FULLY EXTENSIBLE AND PROGRAMMABLE IDE Microsoft has "opened up" the IDE and published an API so that tool vendors can easily integrate their languages and tools into the environment. This makes it possible to have many non-Microsoft created programming languages in one IDE. Opening up the IDE also lets tool vendors develop tools that are targeted specifically at the T&M programmer—and are totally and seamlessly integrated into the environment. We have created the Agilent T&M Programmers Toolkit for VS.NET. It's a series of tools and APIs that are part of the .NET programming environment. Our extensions to the .NET Framework Class Library is called the T&M Framework. It's a programming API built for the T&M programmer. T&M PROGRAMMERS TOOLKIT Let's take a look at how this new environment can be used with the T&M Programmers Toolkit to write a simple application to query an instrument's IDN string and display it very quickly. It's also a good idea to explore some of the integration points that the Toolkit adds to VS.NET. The steps to write this application are:
  1. Start a new project.
  2. Find the instrument you want to communicate with.
  3. Put a button on a form.
  4. Create the code to talk to the instrument on the button's "Click" event.
  5. Display the result.

Let's get to work!

Step 1. The Toolkit extends the VS.NET New Project Wizard with guided steps to create skeleton programs, which include all necessary references to T&M Assemblies you will need to use. See Figure 3 for how to create a new project via the New Project Wizard. Step 2. Use the Instrument Explorer to find the instruments attached to your PC. It also allows you to configure drivers (VXIplug&play, IVI-COM, or IVI-C). If you already know the VISA address for your instrument, you can skip this step. See Figure 4 for a view of this integrated tool.Step 3. On the blank form that was created in Step 1, drag a button from the Toolbar onto the form. Then double-click the button. This will open up the code window and your cursor will be in the "Button1_Click" event. This is the code that Visual Basic will execute when you click on the button while the program is running. Step 4. In this step we want to write some code to talk to the instrument. I'm using the Toolkit DirectIO class to communicate with the instrument. It's an API built to handle simple communication with instruments using SCPI (or any other ASCII-based command set). I used the Instrument Explorer to configure a DirectIO session to talk to the instrument and then to drag-and-drop code into my code window. See "Step 4 Code Listing" to look at the resulting code.Step 5. The final line in the subroutine will display a message box with the results of the "IDN" (Identification) string that was queried from the instrument. It would display a string such as: HEWLETT-PACKARD,34401A,0,2-1-1.

That's it! Five simple steps to set up communication with your instrument in VS.NET.

The T&M Programmers toolkit also contains an Interactive IO tool, IO Monitor, Engineering Graphs, Data Analysis, DSP functions, Complex Numbers, and Engineering Formatter. The help documentation is fully integrated into the environment, so all of the tools that Microsoft invents to work on the help system will also work on the Toolkit.

THE BOTTOM LINE By adopting the .NET Framework and the opportunities it affords, such as the T&M Toolkit, the T&M community can immediately access a wealth of innovations, secure its investment, and accelerate design and test productivity. It's expected that engineers will experience up to a 50% decrease in time spent programming instruments and displaying data by working within the .NET homebase and leveraging .NET code portability, its inherent functionality, and its growing user community.

Developers who choose to work within the .NET Framework to create and test new products can focus their creativity on T&M solutions and leverage a well defined development platform. As for managers, they can draw upon a larger pool of developers that know this standard environment and protect their investment in the creation of intellectual property.

Recommended Reading:
Richter, Jeffrey, Applied Microsoft .NET Framework Programming, Microsoft Press, 2002.

Hollis, Billy S., and Lhotka, Rockford, Fast Track Visual Basic .NET, Wrox Press Ltd., 2002.

Platt, David S., Introducing Microsoft .NET, Microsoft Press, 2002.

Nathan, Adam Sams, .NET and COM, 2001

Visual Basic .NET Technology Map (http://msdn.microsoft.com/library/techmap_vbnet_topic4); select the link: Upgrading from Visual Basic 6.0.

Robinson, Ed, Bond, Michael, and Oliver, Robert Ian, Upgrading VB6 to Visual Basic .NET, Microsoft Press, 2002.

Grimes, Richard, Programming with Managed Extensions for Microsoft Visual C++ .NET—Version 2003, Microsoft Press, 2003.

Templeman, Julian, and Olsen, Andy, Microsoft Visual C++ .NET Step by Step—Version 2003, Microsoft Press, 2003.

"C++ Conformance Roundup," Herb Sutter (ed), C/C++ Users Journal, April 2001 (www.cuj.com/roundup/).

European Computer Manufacturers Association (ECMA) standards are available at www.ecma-international.org.

International Organization for Standardization (ISO) certifications are available at www.iso.org.

Sponsored Recommendations

Near- and Far-Field Measurements

April 16, 2024
In this comprehensive application note, we delve into the methods of measuring the transmission (or reception) pattern, a key determinant of antenna gain, using a vector network...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Empowered by Cutting-Edge Automation Technology: The Sustainable Journey

April 16, 2024
Advanced automation is key to efficient production and is a powerful tool for optimizing infrastructure and processes in terms of sustainability.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!