Simple multiple time-baled files scenario
Another typical scenario is to write data files containing a set amount of data and give each file a unique name. For example, every hour write a file containing an hour’s worth of data. These files are sometimes referred to as bales.
(Click image to expand/collapse display)
In the example program, the tables names (highlighted) must match.
FTPResult=
|
The pertinent instruction in Multiple time-baled files is FTPClient()
configured as such:
FTPResult=FTPClient
("computer-name.domain.com"
, "Tutorial"
, "Tutorial_PW"
, "FTPTest2"
, "FTPBale_Num_"
, 2, 0, 1, Hr, 8)
The variable FTPResult
will be –1 if successful, 0 if it fails, or –2 if execution did not occur when the instruction was called (for instance, when the time into interval conditions are not met). In this example, during normal successful operations, you will see a result code of –2 most of the time. It will change to –1 for a few seconds near the top of every hour.
The first three parameters are the same as were used in the Simple single file scenario. These are based on the receiving FTP server. See requirement 1 in Requirements. Your IP address, user name, and password will be different from the following example screenshot.
Next, in LocalFileName specify the name of the DataTable that contains the data to copy to the FTP server. Multiple time-baled files shows the table name in the instruction DataTable
(FTPTest2,1,–1)
. Type the Table Name in quotes, and double-check to ensure there are not any typos.
Because the objective is to have separate files containing a set amount of data, the files on the FTP server will all need unique file names. The RemoteFileName provides the base name for each file. FileOption, specifies how the file will look on the FTP server. Additionally, FileStream affects the name of the files. By default, the file name created on the server will automatically be appended with an incrementing file number and a “.dat” file extension.
Using a RemoteFileName of FTPBale_Num_ (notice the final underscore _) and an FileOption code of 8, as used in this example, the resulting files on the server will have names following this pattern: FTPBale_Num_0, FTPBale_Num_1, FTPBale_Num_2…
The FileOptioncode of 8, generates a data file that looks like the data file collected by LoggerNet using the default settings, which is a full header in ASCII. Other choices include binary, ASCII, XML and JSON formats, and variations on what to include in the header.
The PutGetOption code of 2 specifies storing separate files on the FTP server and using what is called a passive connection. Whether a connection is active or passive depends on how the FTP server is set up. Most data logger-to-computer FTP connections are most successful using passive mode.
The next group of parameters lets you specify how often and when you want the data logger to initiate the connection to the server and stream previously unsent data to it. IntervalStream and UnitsStream determine how often, every 1 hour in this example. NumRecsStream lets you set an offset to the interval if desired. This is commonly kept at 0 so the connection and data streaming takes place at the top of the interval. Other typical intervals would be 0,12,Hr to stream every 12 hours at noon and midnight, or 0,1,Day to stream once a day at midnight. To stream once a day at 8 AM, use 8,24,Hr.
If the Ethernet connection is lost, the data logger will send the unsent data in individual files, as expected, when the connection comes back.