Direct Printing with FTP Server Printers. Brother model HL-L3240CDW

Hi community!

The direct printing from a B&R PLC to a Printer has been historically a problem. Sometimes has been solved using printers with PCL5 protocol, but nowadays this ones are difficult to find.

In order to solve that we have find a different solution to make automatic prints directly from a PLC connected to a printer without the need of human interaction. This solution is using printers that host a FTP Server. This printers print the documents shared in the FTP server and after the print it deletes the document from the server.

1. Supported Files

This post is to share a Template Project to do a direct printing of a PDF file without Internet connection via printer with FTP server and with no human interaction with the printer.

Some types of files are supported to print it directly and others are not.

Supported files

  • PDF
  • JPG (printed escalated in A4 format)
  • TXT (Read Note 1*)
  • XML (Read Note 1*)
  • HTML (Read Note 1*)
  • CSV (Read Note 1*)

Note 1) This type of documents could be printed but could miss information if the line length is greater than the A4 format. Is the user the responsible of editing the file to fit it in A4 format to do a correct printing.

Not supported files

  • DOC
  • DOCX
  • BMP
  • PNG

2. Used Hardware

For this Template project has been used:

Regarding the CPU, it will use mappReport (AR >= 4.0) and the library FileIO (AR >= A2.85).

This specification is only for this project because it is used mappReport to generate the PDF file, but if in your project it is any other file type (.txt, .jpg…) or the PDF it is generated with other tools the only restriction is the user of the FileIO Library.

Regarding the BROTHER printer, has been selected this model mainly because it has the feature of FTP Server to send the files and directly print it. Also the initial settings are quite easy so it is a recommended model. Nevertheless any other printer with FTP Server should be OK for this purpose.

2.1. Possible models

Here it is a list of Brother printers that also had the functionality of FTP Server, so it is suitable to work with this Sample Project with the recommended retail price.

2.1.1. Color Models

2.1.1. Monochrome Models

3. Printer Settings

Follow the user guide of the printer provided by BROTHER in order to do the first steps to configure the printer and let it ready to use.
When all the initial steps are done, download the software as the guide says.

In this screen you can set an initial IP, but later it is very easy in the LCD screen of the printer.

3.1. Web Server Access

With the IP configured and with a direct Ethernet cable from the PC to the Printer, it is necessary to access to the Web Server of the printer putting the IP in any Web Browser.
In this example the IP is the 10.10.10.100.

You will see the following page:

In the “Login” field you need to put the default password of the printer. It can be found in the rear label of the printer.

It is possible that the browser detects this web page as not safe. Accept the risk and continue to the page.

3.2. Change Password

It is recommended to change the password, not only to access to the Printer’s web server but also because this will be the password used in the Automation Studio program to connect to the FTP server.

Go to the following path in the web server and generate a password that fulfill the requirements.

In order to keep it simple, for this template the password is “adminadmin”

3.3. FTP Server Activation

Go to the following path to activate the FTP Server. Click on Submit after that:

From now on, the FTP server it is activated with the following credentials:

  • User: admin (default user)
  • Password: adminadmin (defined in the previous point)

Before continuing with the PLC direct connection, it is recommended to check if the FTP server is properly configured from the PC. In order to do that with Filezilla (or any other FTP client) try to connect to the FTP Server.

If it is properly configured it will look like this:

if you don’t get any error you can try to send a PDF file to the server and check that it is printed. In this case skip the next point.

Could be that when you try to connect to the FTP server from Filezilla it achieve to make the connection but may not be able to retrieve the directory list (this messages will be shown in the Filezilla logger). In this case it is necessary to make a Time synchronization.

3.4. Time Synchronization

It is possible that the printer does not have the correct time and this prevent the FTP connection to be done. In this case there are 2 ways to solve it:

3.4.1. Internet connection

Just by connecting the printer to a Ethernet network with internet access, it will be automatically synchronized.
In order to do that it is important set the IP of the printed as DHCP and after that connect the printer to the internet. This is a quick process but it could take a few seconds.
After this you can configure the IP of the printer as before (Static and 10.10.10.100) and connect again to the PLC or PC.
With this procedure you need to be sure that the PLC is also with the correct date and time.

3.4.1. PLC as NTP server

Some of the B&R PLCs had the feature of being NTP servers. In this way, any machine connected as a NTP client could get date and time from the PLC.

After that, activate the printer as NTP Client, in the Protocol page. Check the "SNTP and go to Advanced settings

4. Automation Studio

In this template the Ethernet interface of the CPU has been set to fixed IP and in the same subnet as the printer: 10.10.10.104

4.1. Workflow Overview

4.2. Mapp Report

The easiest way to generate PDF reports is using mapp Report. In this template has been configured a simple report with some text lines and some different styles, but you can also configure graphics, tables etc.

This is the main page of the online help of the mapp Report where you can expand this knowledge with example, tutorials and all the technical documentation about this mapp Service.

mapp Report - B&R Online Help

In the template, the Report task has 2 Actions called MpReportInit and MpReportCyclic where all the necessary function blocks are executed.

The Report configuration could be found in the Configuration View → mappServices → RptConfig.mpreportcore

4.3. State machine

As it is shown in the Workflow Overview, the creation and sent of a PDF file should be done in the correct order. This is because the Function Blocks DevLink and DevUnlink handle FileDevies of the system and could generate errors if they are not correctly handled. For example opening againt a FileDevice without first closing it.

In order to simplify it has been generated a simple state machine that only with the activation of the boolean GenerateAndPrint it makes all the sequence in the correct order.

As it is also said in the Report task, this is a template, not a finished program, so the error handling it is not implemented because every user may want to act in different terms when an error happens. It is supervised the Function Block errors, and if it is caught some of them it brings the state machine to “PRINT_ERROR” but it is responsibility of the programmer to manage the error handling to go out of this state.

4.4. Connection Settings

It is importat to set the correct parameters in the DevLink function block. In the template this variable is only set in the Init of the task because it is only configured one printer, and it is not going to change:

DevLink parameters

If you have 2 printers in the code you can change this variable in the cyclic part of the program in order to connecto each time to the correct one.
In the parameters it is specified:

  • FTP Server IP: 10.10.10.100
  • Communication protocol: FTP
  • User: admin
  • Password: adminadmin (configured in point 2.2 of this post)

If you want to know more about this paremeters it is available in the following link
DevLink Parameters - B&R Help

4.5. HMI

To test the the program has been created a simple visualization in Visual Components 4

To print the PDF generated with mapp Report, it is necessary to fill the fields of information and press Generate and Print.

The resulting PDF looks something like this:

If everything is fine the report will be printed directly.

5. Link to the Project

In the following GitHub link you can download the template to test it
DirectPrintFTP - GitHub Link

6. Reporting bugs / Feedback
If you have any doubt or want to give any feedback to improve the template it will be grateful.

If you want to report any bug you can contact me, write here in comments or make an entry in this link of the repository DirectFTP - issues

I hope this information can be useful or interesting to someon

9 Likes

Thanks for sharing :slight_smile: