Series 2600B System SourceMeter® Instrument Reference Manual
Section 6: Instrument programming
2600BS-901-01 Rev. B / May 2013
6-61
To setup communication to a remote ethernet device that is not TSP enabled:
1. Send the command:
connectionID
= tspnet.connect(
ipAddress
,
portNumber
,
initString
)
Where:
•
connectionID
is the connection ID that will be used as a handle in all other TSP-Net function calls.
•
ipAddress
is the IP address of the remote device.
•
portNumber
is the port number of the remote device.
•
initString
is the initialization string that is to be sent to
ipAddress
.
See
tspnet.connect()
(on page 7-367) for additional detail.
To communicate to a remote ethernet device from the Series 2600B:
1. Connect to the remote device using one of the above procedures. If the Series 2600B cannot
make a connection to the remote device, it generates a timeout error. Use
tspnet.timeout
to
set the timeout value. The default timeout value is 20 seconds.
2. Use
tspnet.write()
or
tspnet.execute()
to send strings to a remote device. If you use:
•
tspnet.write()
: Strings are sent to the device exactly as indicated, and you must supply any
needed termination characters.
•
tspnet.execute()
: The Series 2600B appends termination characters to all strings that are sent.
Use
tspnet.termination()
to specify the termination character.
1. To retrieve responses from the remote instrument, use
tspnet.read()
. The Series 2600B
suspends operation until the remote device responds or a timeout error is generated. To check if
data is available from the remote instrument, use
tspnet.readavailable()
.
2. Disconnect from the remote device using the
tspnet.disconnect()
function. Terminate all
remote connections using
tspnet.reset()
.
Example script
The following example demonstrates how to connect to a remote device that is not TSP
®
enabled,
and send and receive data from this device:
-- Disconnect all existing TSP-Net connections.
tspnet.reset()
-- Set tspnet timeout to 5 seconds.
tspnet.timeout = 5
-- Establish connection to another device with IP address 192.168.1.51
-- at port 1394.
id_instr = tspnet.connect("192.168.1.51", 1394, "*rst\r\n")
-- Print the device ID from connect string.
print("ID is: ", id_instr)
-- Set the termination character to CRLF. You must do this
-- for each connection after the connection has been made.
tspnet.termination(id_instr, tspnet.TERM_CRLF)
-- Send the command string to the connected device.
tspnet.write(id_instr, "*idn?" .. "\r\n")
-- Read the data available, then print it.
print("instrument write/read returns: ", tspnet.read(id_instr))
-- Disconnect all existing TSP-Net sessions.
tspnet.reset()
Содержание System SourceMeter 2601B
Страница 841: ......