Programming for experts
P.
110 of 349
FTP Data streams
Four data streams
Configuration of the transfer
Several strings are summarised in a
line of text
With the help of configurable FTP transfers any ASCII ("plaintext") files can be written to an external
FTP server. The maximum file size is 64 kB.
For this purpose, four different handles (= ID number of transfers) are created, which - by itself
buffered queue - create these files on the server. The files are via timeout earlier (and then fewer
bytes if necessary) written or initiated by flushftp () by the user. The file names are assigned
automatically by the firmware by date and time.
In the following, the procedure must be described in detail when creating and applying these FTP
outsourcing.
First, the stream and its handle must be defined in the program. For this purpose, the function
ftpconfig
(
server
,
user
,
password
,
path
,
timeout
)
is needed (P. 283). A handle refers to a unique number (ID) for a transfer and is about tantamount to
a name.
The first three arguments are used to configure the Tranfers: IP address, user name and password,
then follows the target directory on the server and a timeout parameter. Use this statement to
reserve a 64 Kbyte buffer in Enertex ® EibPC. The transfer of the buffer occurs when either the
buffer was completely filled (more on this below) or the number
timeout
seconds have elapsed since
the last transfer.
// ServerDaten
server=$ftp.enertex.de$
user=$enertex$
password=$enertex$
path=$KNX/Telegramme$
// Timeout in Sekunden
timeout=900u32
// FTP Queue anlegen
// Wenn Handle ungleich Null, dann ist das fehlerfrei gelungen
Handle=ftpConfig(server,user,password,path,timeout)
During operation, the data must now be written into the buffer. Therefore
sendftp
(
handle
,
data1
,
[data2]
,
[...]
)
is needed. The function allows arbitrary strings as arguments, because the target file is also just a
text file.Any data in the form of numerical values must be converted using the
Convert
function. In
this case an LF CR (newline suitable for Windows) is inserted at the end of the data transmission of
sendftp. All call to
sendftp
can pass more than one substring, but no more than 1400 bytes assume
total. Accordingly, the maximum length is 1400 bytes:
// Daten in die Queue schreiben
Data1=$Daten Nr. $
Data2=$ des internen Zählers - $
Nr=0u16
status=3
// minütlich werden die Daten Data1 in den internen Buffer geschrieben
// nach 15 Minuten (timeout) werden die Daten am FTP-Server ausgelagert
if stime(60) then {
status=sendftp(Handle, Data1,convert(Nr,$$),Data2,convert(settime(),$$));
Nr=Nr+1u16;
} endif
If the variable
status
to 1, writing to the buffer of the transfer was successful. However, this has
nothing to do with the fact that the data have arrived on the FTP server.
For this, the status of the FTP data stream must be queried.
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]