Section 6: Instrument programming
Models 707B and 708B Switching Matrix Reference Manual
6-60
707B-901-01 Rev. A / August 2010
Example: Using tspnet commands
function telnetConnect(ipAddress, userName, password)
-- Connect through telnet to a computer
id = tspnet.connect(ipAddress, 23, "")
-- Read the title and login prompt from the computer
print(string.format("from computer--> (%s)", tspnet.read(id, "%n")))
print(string.format("from computer--> (%s)", tspnet.read(id, "%s")))
-- Send the login name
tspnet.write(id, userName .. "\r\n")
-- Read the login echo and password prompt from the computer
print(string.format("from computer--> (%s)", tspnet.read(id, "%s")))
-- Send the password information
tspnet.write(id, password .. "\r\n")
-- Read the telnet banner from the computer
print(string.format("from computer--> (%s)", tspnet.read(id, "%n")))
print(string.format("from computer--> (%s)", tspnet.read(id, "%n")))
print(string.format("from computer--> (%s)", tspnet.read(id, "%n")))
print(string.format("from computer--> (%s)", tspnet.read(id, "%n")))
end
function test_tspnet ()
tspnet.reset()
-- Connect to a computer via telnet
telnetConnect("192.0.2.1", "my_username", "my_password")
-- Read the prompt back from the computer
print(string.format("from computer--> (%s)", tspnet.read(id, "%n")))
-- Change directory and read the prompt back from the computer
tspnet.write(id, "cd c:\\\r\n")
print(string.format("from computer--> (%s)", tspnet.read(id, "%s")))
-- Make a directory and read the prompt back from the computer
tspnet.write(id, "mkdir TEST_TSP\r\n")
print(string.format("from computer--> (%s)", tspnet.read(id, "%s")))
-- Change to the newly created directory
tspnet.write(id, "cd c:\\TEST_TSP\r\n")
print(string.format("from computer--> (%s)", tspnet.read(id, "%s")))
-- if you have a data print it to the file
-- 11.2 is an example of data collected
cmd = "echo " .. string.format("%g", 11.2) .. " >> datafile.dat\r\n"
tspnet.write(id, cmd)