Using the SysLibFile.lib and the WagoLibFtp.lib for file access, English Version 1.0.0
2 General Copyright 2006 by WAGO Kontakttechnik GmbH & Co. KG All rights reserved. WAGO Kontakttechnik GmbH & Co. KG Hansastraße 27 D-32423 Minden Phone: +49 (0) 571/8 87 0 Fax: +49 (0) 571/8 87 1 69 E-Mail: info@wago.com Web: http://www.wago.com Technical Support Phone: +49 (0) 571/8 87 5 55 Fax: +49 (0) 571/8 87 85 55 E-Mail: support@wago.com Every conceivable measure has been taken to ensure the correctness and completeness of this documentation. However, as errors can never be fully excluded we would appreciate any information or ideas at any time. We wish to point out that the software and hardware terms as well as the trademarks of companies used and/or mentioned in the present manual are generally trademark or patent protected. 114100
Table of Contents 3 TABLE OF CONTENTS 1 Important comments...4 1.1 Legal principles...4 1.1.1 Copyright...4 1.1.2 Personnel qualification...4 1.1.3 Intended use...4 1.1 Range of validity...5 1.2 Symbols...5 2 Description...6 2.1 Reference Material...6 3 Writing files...6 4 Sending files via ftp...7 5 Examples...9 5.1 Write data into file and send it via ftp...9 5.2 Converting data...10 5.2.1 Data visualization...11 5.2.2 Reading a CSV file...12
4 Important comments 1 Important comments 1.1 Legal principles 1.1.1 Copyright To ensure fast installation and start-up of the units described in this manual, we strongly recommend that the following information and explanation is carefully read and adhered to. This manual is copyrighted, together with all figures and illustrations contained therein. Any use of this manual which infringes the copyright provisions stipulated herein, is not permitted. Reproduction, translation and electronic and phototechnical archiving and amendments require the written consent of WAGO Kontakttechnik GmbH & Co. KG. Non-observance will entail the right of claims for damages. 1.1.2 Personnel qualification 1.1.3 Intended use The use of the product detailed in this manual is exclusively geared to specialists having qualifications in PLC programming, electrical specialists or persons instructed by electrical specialists who are also familiar with the valid standards. WAGO Kontakttechnik GmbH & Co. KG declines all liability resulting from improper action and damage to WAGO products and third party products due to nonobservance of the information contained in this manual. For each individual application, the components supplied are to work with a dedicated hardware and software configuration. Modifications are only admitted within the framework of the possibilities documented in the manuals. All other changes to the hardware and/or software and the non-conforming use of the components entail the exclusion of liability on part of WAGO Kontakttechnik GmbH & Co. KG. Please direct any requirements pertaining to a modified and/or new hardware or software configuration directly to WAGO Kontakttechnik GmbH & Co. KG.
Important comments 5 1.2 Range of validity 1.3 Symbols This application note is based on the stated hardware and software of the specific manufacturer as well as the correspondent documentation. This application note is therefore only valid for the described installation. New hardware and software versions may need to be handled differently. Please note the detailed description in the specific manuals. Danger Always observe this information to protect persons from injury. Warning Always observe this information to prevent damage to the device. Attention Marginal conditions must always be observed to ensure smooth operation. ESD (Electrostatic Discharge) Warning of damage to the components by electrostatic discharge. Observe the precautionary measure for handling components at risk. Note Routines or advice for efficient use of the device and software optimisation. More information References to additional literature, manuals, data sheets and INTERNET pages
6 Description 2 Description This document illustrates how to use the SysLibFile.lib and the WagoLibFtp.lib libraries in a WAGO 750-841 Ethernet Controller. It describes how to write, read, and send a file. 2.1 Reference Material The following hardware and software components were used to develop and test this application note: Assigned hardware components Producer Type Ethernet-Controller WAGO 750-841 SysLibFile.lib 3S WagoLibFtp.lib WAGO 3 Writing files - Using the SysLibFile.lib - This section shows how to write data to a file. The input variable filename specifies the name of the file that will be stored in flash. The writing process is initiated by setting the input variable write to TRUE. The delete_file input can be used to delete the file. The output variables file_ok and file_empty specify whether the file closed successfully or whether the file was deleted.
Sending files via ftp 7 To write a file there are three basic steps: 1. open a file 2. write to the file 3. close the file When the input variable write is set to TRUE, the function SysFileOpen is called, which opens the file. It requires the filename and the access mode ( a, r, w, or rw ) for inputs. If the file does not already exist, it creates a new one. The return value is a file number that is used by other file functions. In the next step, the function SysFileWrite is called. This function needs the file number (returned from SysFileOpen ), the address of the data (in this example ADR(bytearray)), and the number of bytes to write. The file is then closed with the function SysFileClose. This function needs the file number from SysFileOpen. The return value file_ok is TRUE if it s successful and FALSE if an error occurs. Note These functions are blocking instructions, therefore, it is strongly recommended to execute file-operations in a separate task. When the input variable delete_file is set TRUE, the function SysFileDelete is called. This function needs the input variable filename and returns the status in file_empty. This output variable returns TRUE if the file was successfully deleted and FALSE if an error occurred. 4 Sending files via ftp - Using the WagoLibFtp.lib - This section illustrates how to send a file via FTP. The file_send_read function block shown below internally uses the FTP_CLIENT function block, which is part of the WagoLibFtp.lib library. The input variable send starts the transmission of the local file (filename_source) to the server that is specified by ftpserver_ip_adr. The read input is used to read the file back from the remote server and store it on the local flash. The return values file_send and file_read indicate whether the file was sent/read successfully.
8 Sending files via ftp Internally the following occurs in this function block: To send or read a file there are four steps: Open a connection to the Server Open an account on the Server and login Send / Read files Close the ftp connection To open a connection, an instance of the function block FTP_CLIENT is created from WagoLibFtp.lib. The function block is then assigned the destination IP address ( ftpserver_ip_adr = HOST_IP ) and port number ( PORT_NUM ). A connection is initiated with the Action called OPEN. Next the program opens an account (via Action LOGIN ) on the remote server using the inputs USERNAME and PASSWORD. If the controller login is successful, sending/reading is started via the Action PUT / GET. These actions need the source and destination filenames ( filename_source = LPATH ; filename_destination = RPATH ). When the file transfer is complete, the connection is closed via the Action CLOSE.
Examples 9 5 Examples This section illustrates three example programs that use the SysLibFile.lib library for file access. The first example talks more about the function blocks used in section 3 and 4 ( file_write and file_send_read ). The second and third example covers data conversion and reading data from a CSV file. These function blocks can be used as is, or modified to meet your specific application need. 5.1 Write data into file and send it via ftp In this example (filewritesend.pro) a byte array is saved to the local flash drive using the function block called file_write. The filename is specified as an input to the function block. When the write input is set TRUE, the file is saved. If successful, the output file_ok returns TRUE. After the file is saved in flash, it can be sent to the FTP server using the file_send_read function block. This function block requires the following inputs: the local filename, the destination filename, the FTP server s IP address (in this example 10.1.6.200), the username, and password. When the send input is set TRUE, the file is sent. If successful, file_send returns TRUE. This variable is then used to activate the deleting of the file on the local flash drive with the file_write function block. When complete, the original file is saved on the server and the local file is deleted. To copy the file back to the local drive, set the read input of the file_send_read function block to TRUE. 750-841 IP:10.1.6.200, Port 21 Server 750-841 IP: 10.1.6.205 Client example: filewritesend.pro
10 Examples 5.2 Converting data In this advanced example (Datenverarbeitung.pro) an array of a structure (messw: INT; timestamp: DT; ms: TIME) is used to hold measured values. The array is then saved to a file. Because the file_write function block expects an array of bytes, our array must be converted to bytes. For this conversion the function block convert_to_byte is used. The array dataarray contains the measured values and the array result will hold the converted data. Setting start to TRUE starts the conversion. The input variable trenner specifies a separator (e.g. ; ) that separates itemized data. Internally the function block convert_to_byte starts by clearing the array bytearray. A pointer is then set to the beginning of the byte array. Using a loop, a value is read, converted to bytes, and the pointer is set to the new position. The separator is then copied and the pointer is set again. This process continues for all the data. Example: Datenverarbeitung.pro
Examples 11 5.2.1 Data visualization Additionally in the example datenverarb.pro, a visualization is implemented. There are two signal-curves (from the function block measured_value, built by signal-generators in signals ) shown. It is possible to switch between the curves. Furthermore, you can scroll along the data-array and change the resolution. Both signal-curves are references of the visualization signal. You can watch variables of each function block via this visualization placeholder (for more information on visualization placeholders, see CoDeSys online help). example: Datenverarbeitung.pro
12 Examples 5.2.2 Reading a CSV file In this example (CSV_Datei_Lesen.pro) data from a CSV file will be read and stored in an array of type typcsv. One line of data (one data set) consists of a DATE_AND_TIME variable and 5 word parameters. A semicolon separates the values. Each line is terminated with a CR and LF character. The input variable xstart of the function block ReadCSVFile starts the reading process. The variable bseperator is the ASCII value of the seperator character (in this example 59 for the semicolon). In the global variable area of the CoDeSys program, three constants are defined that describe the CSV file.
Examples 13 gc_rawdatasize:uint:=500; gc_parametercount:int:=5; gczeilenexcel:int:=5; gc_rawdatasize is the maximum number of bytes in the file gc_parametercount is the number of parameter values gczeilenexcel is the number of data sets Example: CSV_Datei_Lesen.pro, Datensatz1.csv
WAGO Kontakttechnik GmbH & Co.KG Postfach 2880 D-32385 Minden Hansastraße 27 D-32423 Minden Telefon: 05 71/8 87 0 Telefax: 05 71/8 87 1 69 E-Mail: info@wago.com Internet: http://www.wago.com