High Voltage SourceMeter Instrument Reference Manual Section 14:
2470-901-01 Rev. A / May 2019 14-77
file.flush()
This function writes buffering data to a file on the USB flash drive.
Type TSP-Link accessible
Affected by Where saved Default value
Usage
file.flush(fileNumber)
The file number returned from the
function to flush
Details
The file.write() function may be buffering data instead of writing immediately to the USB flash
dr
ive. Use file.flush() to flush this data. Data may be lost if the file is not closed or flush
ed
before a script ends.
If there is going to be a time delay before more data is written to a file, flush the file to prevent loss of
data because of an aborted test.
Example
-- Fix the range to 10 V
smu.measure.range = 10
-- Set the measurement count to 100
smu.measure.count = 100
-- Set up reading buffers
-- Ensure the default measurement buffer size matches the count
defbuffer1.capacity = 100
smu.measure.read()
testDir = "TestData5"
-- create a directory on the USB drive for the data
file.mkdir(testDir)
fileName = "/usb1/" .. testDir .. "/myTestData.csv"
buffer.save(defbuffer1, fileName)
if file.usbdriveexists() != 0 then
--testDir = "TestData3"
-- Create a directory on the USB drive for the data
--file.mkdir(testDir)
-- Open the file where the data will be stored
--fileName = "/usb1/" .. testDir .. "/myTestData.csv"
fileNumber = file.open(fileName, file.MODE_APPEND)
-- Write header separator to file
file.write(fileNumber,
"\n\n====================================================================\n")
-- Write the string data to a file