Building ActiveX Client/Servers With HP VEE

Atest engineer is tasked with developing an automated test routine in HP VEE 5.0 to examine self-blocking in a receiver. The receiver must be tuned to 60,000 frequencies, and the test program will examine the IF spectrum at each frequency. But the radio can only be controlled via a virtual front panel—no knobs, switches, or conventional remote-control capability. However, the panel designer did include sockets in his code for remote control via the Internet.

What do you do? If you don’t have prior networking experience with C++, Visual Basic, or other development languages, you think you are doomed. Not necessarily. HP VEE has built-in socket capabilities thanks to ActiveX. While most of the available HP VEE literature focuses on ActiveX automation, such as sending data from VEE to Excel or running a VEE program from within Word, there are a host of ActiveX controls, including Winsock, that can vastly expand your programming horizons.

The Winsock ActiveX control is a Microsoft product supplied in several Microsoft development tools including Visual Basic and Visual C++. The Winsock component is licensed, so you must have one of these development tools already loaded on your machine to access it. Microsoft C++ Version 6.0 is a good choice. It provides access to a host of ActiveX controls and can generate specialized or speed-critical dynamic link libraries (DLLs) for HP VEE.

Sockets

Sockets are used when one process has data that another process needs. A socket is an interprocess communications mechanism that allows programs and applications to talk to each other, even if they’re written in different languages or hosted on different machines.

Sockets use a two-part identifier consisting of a computer address and a port number. The computer address uses the familiar Internet protocol (IP) format; for example, 214.63.115.41. However, if two active processes are going to reside on the same computer, use the default IP address: 127.0.0.1. With this address, your co-resident application(s) will talk to each other even if you change computers or Ethernet cards.

The second part of the socket identifier is the port number that allows many sockets to exist simultaneously on one computer without data collisions. Standard port numbers already have been defined for some common Internet applications. For example, the hypertext transfer protocol (HTTP) for requesting pages on the worldwide web uses port number 80; the file transfer protocol (FTP) uses port numbers 20 and 21. When building ActiveX sockets for HP VEE, use port numbers above 1,000 to avoid conflicts.

Transmission Protocols

Once you’ve established the correct IP address and port number for your socket, specify the communications protocol you will use. The Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) are supported by the Winsock ActiveX control.

TCP is a connection-based, error-handling protocol. This means that data packets originating at one end will be received and reassembled at the other end in the proper order. In addition, if the sender does not receive an acknowledgment message within a predetermined period of time, the missing packet(s) will be retransmitted automatically.

The TCP protocol is analogous to a telephone call: one party (the client) initiates a connection, the other party (the server) responds, and then both parties communicate over a dedicated channel. TCP provides a robust, bidirectional communications channel, but this robustness comes at a price. Error handling requires the client to acknowledge that it correctly received all the data sent by the server. This handshaking requires extra time and imposes an upper limit on the data transfer rate using TCP.

If maximizing the data transfer rate is critical to your application, UDP may be the answer. UDP is connectionless; data packets are transferred without error handling. While UDP is significantly faster than TCP, the maximum size of individual UDP data transmissions is network-limited, and messages can be lost, delayed, duplicated, or re-ordered in transit. Streaming audio and video applications often use UDP to squeeze as much bandwidth as possible from a standard Internet connection.

Properties, Methods, and Events

Object-oriented development languages such as Visual Basic and C++ view the world in terms of classes and objects. Active-X controls available in HP VEE also use object-oriented terminology, but the underlying concepts are easy to grasp. Think of classes as templates used to create objects. Objects, in turn, may contain properties, methods, and events. Each object is distinguished by its properties.

ActiveX objects generally can do things like multiply an input value by 5.7 and return the result. That sounds like a function; but in object-oriented terminology, it’s called a method. The final concept is the event, a software response to a specific action much like an interrupt service routine.

Accessing Winsock From HP VEE

Accessing the Winsock control from HP VEE is a two-part process. First, make the Winsock ActiveX control library available by choosing ActiveX Control References from the Device option on the menu bar. Then, select ActiveX Controls from the Device option and drag a Winsock form onto the HP VEE Main window. The title of the panel is Winsock: Winsock1.

Example 1. UDP Client/Server

The UDP client/server consists of two separate HP VEE programs. The Server Program sends data (time of day) continuously to the Client Program via the connectionless UDP protocol.

Figure 1 shows the UDP server code. The box labeled WinsockInit is a formula box. Each line in this box requires a terminating semicolon. After initializing a socket connection with this code, data may be transferred through the socket at any time using the SendData method. In this server example, a simple loop has been implemented to send a text string containing the time of day once per second. No event-handling routines are required.

The UDP client must bind to the socket so that it will be ready to receive data whenever it arrives. The code is shown in Figure 2
Event: Winsock1_DataArrival( )

The Winsock1_DataArrival Event is fired when data arrives from the server (Figure 3). newTime holds a text string containing the time string sent from the server while printData is used as a flag to cause the main program to periodically print out the new time information.

Example 2. TCP Client/Server

In this example, a client establishes a TCP connection with a server and then sends a server command consisting of a single integer. The server accepts the integer, multiplies it by 5, and returns it to the client.

Since the server must continuously listen for client requests, an Until Break loop keeps the server alive indefinitely (Figure 4).

The server needs to respond to the three events listed here along with the corresponding HP VEE Event Handler UserFunction code needed for responding to the events. All HP VEE code should be placed in formula boxes.
Event: Winsock1_Close()
Winsock1.Close(); Closes an open socket
Winsock1.Listen(); Reopens socket and returns to listen mode

Event: Winsock1_ConnectionRequest( )
Winsock1.Close(); Closes an open socket
Winsock1.Accept(A); When the Client issues a connection request, its requestID is made available to the Event Handler via the “requestID” input pin. This is provided as an input to the Winsock1.Accept() Method, which uses it to accept the Client’s connection request

Event: Winsock1_DataArrival()
Data = 0; Initialize the data variable to 0
Winsock1.GetData The “GetData” method is the most common response to the “DataArrival” event. The GetData method contains three arguments (ByRef data, [type], [maxLen]), where: 
data: a variable used to store the data retrieved from the socket (after the method returns successfully).
type: [Optional]. Type of data to be retrieved. 
maxLen: [Optional]. Specifies the desired size when receiving a byte array or a string. As implemented in the HP VEE Winsock1_DataArrival Event Handler UserFunction, the “maxLen” information is automatically supplied on the input pin labeled “bytesTotal”.

The entire server transaction takes place in the Winsock1_DataArrival Event Handler Userfunction. When the DataArrival Event is fired, the GetData() Method retrieves the data from the socket and makes it available at a Data output pin. A formula box multiplies this value by 5 and returns the new value to the client using the SendData() Method. This completes the server-side code.

The TCP client in Figure 5 must connect with the server before it can send any data to the server. The first argument in the Connect() method is the IP address of the server. Since both processes (client and server) are hosted on the same machine, the default IP address is used. The port number is chosen to match the server’s socket port number.

After making a connection request, the client enters a loop that repeatedly checks the state of the socket. When the Winsock1.State property equals 7, implying that a remote connection has been established, the loop breaks, and the user’s data (the integer 3) is sent to the server using the SendData method.

The client then enters another loop that waits for the server to process the data and return the result. It is very important that the client program stays alive long enough for the server to return its data. Finally, the response from the server is displayed, and the client routine ends.
Event: Winsock1_DataArrival( )

The DataArrival Event is fired when data returns from the server. The code for obtaining data, the GetData() method, is identical to the code used in the server.

Conclusion

ActiveX controls can add an entirely new dimension to your HP VEE programming capabilities. By studying these socket examples, familiarizing yourself with object-oriented terminology, and mastering HP VEE’s ActiveX interface, you have the tools necessary to harness the extraordinary capabilities of ActiveX controls.

About the Author

Greg Bonaguide is an RF engineer in the Microwave Remote Sensing Group at Raytheon Data Systems. He received a B.S.E.E. from the University of Hartford and master’s degrees in engineering management in 1989 and microwave engineering in 1996 from the University of South Florida. Raytheon Data Systems, 1501 72nd St. N, St. Petersburg, FL 33710, (727) 302-3367, e-mail: [email protected].

Return to EE Home Page

Published by EE-Evaluation Engineering
All contents © 2000 Nelson Publishing Inc.
No reprint, distribution, or reuse in any medium is permitted
without the express written consent of the publisher.

April 2000

Sponsored Recommendations

Comments

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