Codesys#Let’s send a File to the FTP Server!

This article uses the OSCAT NETWORK library for the Berghof Controller and sends CSV Files stored on USB to the FTP Server The FTP Server is a SeeedStudio RecomputerR1125.

Come on, let’s enjoy FA.

Reference Link

Berghof#Let’s List up all items in the Directory!

What is OSCAT?

OSCAT=”Open Source Community for Automation Technology”, an open source library compliant with the IEC61131-3 standard has been created. The library eliminates vendor-specific features and can therefore be ported to all IEC61131-3 compatible programmable logic controllers.

The trend of PLCs using vendor-specific libraries is usually efficiently resolved and these libraries are also partly free of charge, but there are still significant drawbacks to using them.

  1. Most manufacturers’ libraries are protected and the source code is not freely accessible, this is the case when errors occur and error correction is extremely difficult and often impossible.
  2. The development of graphical programmes using vendor-specific libraries can quickly become confusing, inefficient and error-prone, as existing functionality cannot be tailored or extended to suit actual needs, and source code is not available.
  3. Hardware changes, especially migration to other manufacturers, are hampered by proprietary libraries, which also limit the benefits offered by standards such as IEC 61131. Replacing a competitor’s proprietary library is often ruled out because the scope and content of the manufacturer’s library differs significantly.
  4. Understanding complex modules without understanding the source code is often very difficult, which makes programmes inefficient and error-prone.

OSCAT creates a powerful and comprehensive standard for PLC programming with the open OSCAT library. The standard is available in source code and has been validated and tested in detail by a wide range of applications.

FTP_CLIENT

The module FTP_CLIENT is used to transfer files from the PLC to the FTP server and from the FTP server to the PLC. It also starts the transfer process if a TRUE edge is sent to ACTIVATE.

VAR_INPUT

VariableTypeDescription
ACTIVATEBOOL Start up and start communicating.
FILE NAMESTRINGFile path/file name
FTP_URLSTRING(STRING_LENGTH) FTP access path
FTP_DOWNLOAD BOOL UPLOAD = 0 DOWNLOAD = 1
FTP_ACTIV BOOL PASSIV = 0ACTIV = 1
FILE_DELETEBOOL 1 = Delete File after transmission.
TIMEOUTTIME Timeout setting
Dns_ip4DWORD IP4 address of the DNS server
PLC_ip4DWORD IP4 address of the DNS server

VAR_OUTPUT

VariableTypeDescription
DONEBOOL 1 = Transfer completed without error.
BUSYBOOL 1 = Transferring.
ERROR_CDWORDError Code
ERROR_TBYTE Error Type

URL examples

This is an example of a URL setting.

ftp://username:password@servername:portnummer/directory/
ftp://username:password@servername
ftp://username:password @ servername / directory /
ftp://servername
ftp://username:password@192.168.1.1/directory/
ftp://192.168.1.1

Implementation

FTP Server Side

The first step is to install the FTP Server.

Install FTP Server

Install the FTP Server on the SeeedStudio Recomputer with this command.

sudo apt-get update
sudo apt-get install vsftpd

Configuration

The next step is to configure the FTP Server settings.

sudo nano /etc/vsftpd.conf
listen=NO
listen_ipv6=YES
local_enable=YES
write_enable=YES

Codesys Side

The next step is to build the Codesys side.

Install OSCAT NETWORK Library

Download the OSCAT Network library from the Link below.

https://store.codesys.com/en/oscat-network.html

Start the OSCATNetwork.package.

Select the CODESYS version in which you want to install the OSCAT NETWORK library.

Select the CODESYS version in which you want to install the OSCAT NETWORK library.

Please wait a moment…

Done!

Install Library

The next step is to start the Library Manager in order to import the OSCAT NETWORK library into the Codesys project.

Click Add Library.

Add the OSCAT NETWORK library.

Done!

Go ahead and add the OSCAT_BASIC library as well.

Program

This is the FTP Server communication program created in this article.

VAR

This is a variable defined programmatically. fbFtpClient is an Instance of OSCAT_NETWORK.FTP_CLIENT.

PROGRAM pFTP
VAR
fbFtpClient:OSCAT_NETWORK.FTP_CLIENT;
PLC_IP:DWORD;
DNS_IP:DWORD;
xActivate:BOOL;
x1:BOOL;
FILENAME : STRING;
xDownload:BOOL;
xCommand:BOOL;
xDone:BOOL;
END_VAR

Network1

Network1 uses OSCAT_BASIC.DWORD_OF_BYTE to convert DNS addresses to DWORDs.

Network2

Network2 uses OSCAT_BASIC.DWORD_OF_BYTE to convert the IP address of the FTP Server into a DWORD.

Network3

Network3 determines whether the operation that is about to be performed is Download or Upload.

Network4

For Download operations, FILENAME sets the storage location of the File downloaded from the FTP Server; FTP_URL is the Path of the File you want to download to the FTP Server.

fbFtpClient.FILENAME:=

‘/media/usb1/datafromFtp.csv’;

fbFtpClient.FTP_URL:=

‘ftp://kali:kali@192.168.0.202/home/kali/datafromFtp.csv’;

Network5

For Upload operations, FILENAME is set to the Path of the File you want to upload to the FTP Server; FTP_URL is the destination Path of the File you have uploaded to the FTP Server.

fbFtpClient.FILENAME:=’/media/usb1/test2.csv’;

fbFtpClient.FTP_URL:=

‘ftp://kali:kali@192.168.0.202/home/kali/’;

Network6

Finally, We can call the  OSCAT_BASIC.FTP_CLIENT.

Login

Download the project at Online>Login.

Result

ERROR_C and ERROR_T to get information on when the FTP_CLIENT FB encounters an execution error.

The exchange between Codesys Runtime and FTP Server can also be viewed from Wireshark.

Done!Transfer Complete replies.

シェアする

  • このエントリーをはてなブックマークに追加

フォローする