
Chapter 12
181
Using LAN
Controlling the Agilent 4294A
1. Ch
apter
T
itle
12
. Usin
g LAN
3
. Chap
ter T
itle
4
. Chap
te
r T
itle
5. Chap
te
r T
itle
Below are described subprograms corresponding to each step in Figure 12-6:
Startup
The subprogram corresponding to Startup is StartIt (Example 12-2). StartIt uses the version of
WinSock API entered into the part 1 of Figure 12-5 to start up and initialize WinSock API with the
WSAStartup function of WinSock API. This WSAStartup function must always be executed at the
start of WinSock. Parameters for this function are version No. (input) and startup information
(output).
Example 12-2
StartIt
Sub StartIt()
Dim StartUpInfo As WSAData
'Version 1.1 (1*256 + 1) = 257
'version 2.0 (2*256 + 0) = 512
'Get WinSock version
Sheets("Sheet1").Select
Range("C2").Select
version = ActiveCell.FormulaR1C1
'Initialize Winsock DLL
x = WSAStartup(version, StartUpInfo)
End Sub
Socket creation and connection
The subprogram corresponding to socket creation and connection is OpenSocket (Example 12-3).
OpenSocket establishes a connection to the socket of the port specified by PortNumber, an input
parameter, on a machine with the IP address specified by Hostname, an input parameter. Below are
described steps of OpenSocket:
In (1), the inet_aadr function of WinSock API is used to convert an IP address delimited by “.” to an
Internet address.
In (2), the socket function of WinSock API is used to create a new socket and acquire the descriptor
of this socket. If an error occurs during this operation, the function outputs a message and returns
processing to the main program. Parameters for the socket function are Address Family (input),
Socket Type (input) and Protocol No. (input).
In (3), a socket address is set. htons used at setting of the port No. is a WinSock API function that
converts a 2-byte integer from the Windows-type byte order (little endian) to the network byte order
(big endian).
In (4), the connect function of WinSock is used for connection to
the
4294A. If an error occurs
during this operation, the function outputs a message and returns processing to the main program.
Parameters for the connect function are Socket Descriptor (input), Socket Address and Socket
Address Size (input).
Example 12-3
OpenSocket
Function OpenSocket(ByVal Hostname As String, ByVal PortNumber As Integer) As
Integer
Dim I_SocketAddress As sockaddr_in
Dim ipAddress As Long
ipAddress = inet_addr(Hostname) '...................(1)
'Create a new socket
socketId = socket(AF_INET, SOCK_STREAM, 0) '
If socketId = SOCKET_ERROR Then '
Summary of Contents for 4294A
Page 4: ...4 ...
Page 18: ...18 Contents ...
Page 24: ...24 Chapter1 To make effective use of this manual Other manuals attached to this unit ...
Page 94: ...94 Chapter6 Reading Writing Measurement Data Reading Writing Data ...
Page 110: ...110 Chapter7 Processing Measurement Results Analyzing Measurement Results ...
Page 136: ...136 Chapter10 Handling Errors Sample program for error handling ...
Page 246: ...246 13 Application Sample Programs File Transfer Function ...
Page 254: ...254 Chapter15 Setting the Display LCD Sample program for setting the LCD screen ...
Page 507: ...Index Index 507 Index ...
Page 508: ...508 Index Index ...
Page 509: ...Index Index 509 Index ...
Page 510: ...510 Index Index ...
Page 511: ...Index Index 511 Index ...
Page 512: ...512 Index Index ...
Page 513: ...Index Index 513 Index ...
Page 514: ...514 Index Index ...
Page 515: ...Index Index 515 Index ...
Page 516: ...516 Index Index ...
Page 517: ...Index Index 517 Index ...
Page 518: ...518 Index Index ...