
182
Chapter 12
Using LAN
Controlling the Agilent 4294A
MsgBox ("ERROR: socket = " + Str$(socketId)) '...................(2)
OpenSocket = COMMAND_ERROR '
Exit Function '
End If '
'Open a connection to a server
I_SocketAddress.sin_family = AF_INET '
I_SocketAddress.sin_port = htons(PortNumber) '...................(3)
I_SocketAddress.sin_addr = ipAddress '
I_SocketAddress.sin_zero = String$(8, 0) '
x = connect(socketId, I_SocketAddress, Len(I_SocketAddress)) '
If socketId = SOCKET_ERROR Then '
MsgBox ("ERROR: connect = " + Str$(x)) '..........(4)
OpenSocket = COMMAND_ERROR '
Exit Function '
End If '
OpenSocket = socketId
End Function
Communication
The subprogram corresponding to transmit in communication is SendCommand (Example 12-4).
SendCommand uses the send function of WinSock API to transmit a message (GPIB command)
specified by command, an input parameter, to the
4294A
. Parameters for the send function are
Socket Descriptor (input), Transmit Message (input). Message Length (input) and Flag (input).
Example 12-4
SendCommand
Function SendCommand(ByVal command As String) As Integer
Dim strSend As String
strSend = c vbCrLf
count = send(socketId, ByVal strSend, Len(strSend), 0)
If count = SOCKET_ERROR Then
MsgBox ("ERROR: send = " + Str$(count))
SendCommand = COMMAND_ERROR
Exit Function
End If
SendCommand = NO_ERROR
End Function
Subprograms corresponding to receive in communication are RecvAscii (Example 12-5) and others.
RecvAscii receives a message in the ASCII format, and store it dataBuf, an output parameter. The
maximum length of a message it receives is specified through maxLength, an input parameter. Below
are described steps of RecvAscii:
In (1), the recv function of WinSock API is used to receive a message (response to Query, an GPIB
command) on a character-by-character basis. If an error occurs during this operation, the function
outputs a message and returns processing to the main program. Parameters for the recv function are
Socket Descriptor (input), Receipt Message (output), Message Length (input), and Flag (input).
In (2), whether a received character is LF (ASCII code No.: 10) is determined, and if LF, NULL
(ASCII code No.: 0) is added to the tail of the character string dataBuf, receipt is ended, and
processing returns to the main program.
In (3), the number of characters read immediately before is added to the count for checking the
number of received characters, and characters read are added to the tail of the character string
dataBuf.
Содержание 4294A
Страница 4: ...4 ...
Страница 18: ...18 Contents ...
Страница 24: ...24 Chapter1 To make effective use of this manual Other manuals attached to this unit ...
Страница 94: ...94 Chapter6 Reading Writing Measurement Data Reading Writing Data ...
Страница 110: ...110 Chapter7 Processing Measurement Results Analyzing Measurement Results ...
Страница 130: ...130 Chapter9 Communication with External Equipment Using the I O Ports Sample Program to Use the I O Port ...
Страница 136: ...136 Chapter10 Handling Errors Sample program for error handling ...
Страница 246: ...246 13 Application Sample Programs File Transfer Function ...
Страница 254: ...254 Chapter15 Setting the Display LCD Sample program for setting the LCD screen ...
Страница 507: ...Index Index 507 Index ...
Страница 508: ...508 Index Index ...
Страница 509: ...Index Index 509 Index ...
Страница 510: ...510 Index Index ...
Страница 511: ...Index Index 511 Index ...
Страница 512: ...512 Index Index ...
Страница 513: ...Index Index 513 Index ...
Страница 514: ...514 Index Index ...
Страница 515: ...Index Index 515 Index ...
Страница 516: ...516 Index Index ...
Страница 517: ...Index Index 517 Index ...
Страница 518: ...518 Index Index ...