B&R

For B&R PLCs programmed in Automation Studio, SQL4automation provides the SQL4BR library. The sample project is configured to run immediately on the AR000 simulation controller — no hardware is required for testing. The library requires B&R Automation Studio V3.0.80.25 or higher and Automation Runtime V3.00 or higher. SQL4BR supports SELECT, INSERT, UPDATE, and DELETE operations.

Connecting B&R PLC to SQL Databases, MES, ERP

For B&R PLC controllers, SQL4automation provides a sample project and a library. The sample project is configured to run immediately on the AR000 simulation controller. No hardware is required for testing. SQL4BR  connects B&R PLCs directly to SQL databases via TCP/IP through the  SQL4automation Connector. The library is installed in the Automation Studio  Library directory and integrated into the project. The dependent libraries  AsTCP, asstring, and standard are automatically integrated when SQL4BR is  added to the project. Communication is initiated by setting xExecute and  results are returned in the saTableValues array.

Integration of the SQL4BR Library

The SQL4BR library file must be copied into the Automation Studio Library directory (default: C:\Programme\BrAutomation\AS\Library). After adding it to the project, configure the SQL request in the saRequest string array, set the IP addresses for both the PLC and the Connector, the port number, and call the SQL4BR function block cyclically. Results are returned in saTableValues (rows x columns).

SQL4automation Link Settings

The SQL4automation Connector is operated with the target setting "Standard" for B&R Automation Studio controllers. The configuration is completed in just a few clicks. Detailed integration instructions are available in the download section.

FAQ's

Frequently Asked Questions to B&R

Which B&R Automation Studio and Automation Runtime versions are required?

B&R Automation Studio V3.0.80.25 or higher and Automation Runtime V3.00 or higher are required. The SQL4BR library must be placed in the Automation Studio Library directory (C:\Programme\BrAutomation\AS\Library). The dependent libraries AsTCP, asstring, and standard are automatically integrated when SQL4BR is added to the project.

How are the IP addresses configured in SQL4BR?

SQL4BR requires two IP addresses: sIPAddressPLC (the IP address of the B&R PLC) and sIPAddressCon (the IP address of the SQL4automation Connector). Both are configured as input variables when calling the SQL4BR function block. The default port is 11001.

How are SQL query results returned to the B&R program?

Results are returned in the saTableValues array (rows x columns as strings) and column names in saColumnsName. diResultRows and diResultColumns report the dimensions. diResultState contains the status code (0 = success). The saRequest string array holds the SQL query and must be populated before setting xExecute.

Can SQL4BR be tested on the B&R Soft PLC?

Yes. The SQL4BR sample project (SQL4BRSample) can be tested on the Soft PLC AR000 included in B&R Automation Studio. The SQL4automation Connector must be running and connected to the sample database S4A_Test_DB.mdb. Setting xExecute to TRUE triggers the test query; xAbort resets on error.

Which SQL databases can a B&R PLC connect to via SQL4automation?

All ODBC-compatible databases are supported, including Microsoft SQL Server, MySQL, MariaDB, PostgreSQL, Oracle, and SQLite. The database is configured in the SQL4automation Connector. No changes to the B&R Automation Studio project are required when switching databases.

Which B&R controllers has SQL4automation been tested on?

SQL4automation has been tested on the B&R Soft PLC AR000 included in B&R Automation Studio (using the SQL4BRSample project). B&R hardware PLCs running Automation Runtime V3.00 or higher are also supported. The library requires B&R Automation Studio V3.0.80.25 or newer. The dependent libraries AsTCP, asstring, and standard are automatically integrated.

Technical Data

REQUIREMENTS & VERSION INFO
Automation Studio V3.0.80.25 or higher
Automation Runtime V3.00 or higher
Library path Copy SQL4BR library to C:\Programme\BrAutomation\AS\Library
Auto-integrated libs AsTCP, asstring, standard are automatically added when SQL4BR is included
FUNCTION BLOCK PARAMETERS
Parameter Type Description
xExecute BOOL Executes the SQL request
xAbort BOOL Reset
sIPAddressPLC STRING[15] IP address of the PLC
sIPAddressCon STRING[15] IP address of the SQL4automation Connector
iPort INT Port number of the SQL4automation Connector
xHoldConnection BOOL Keeps the socket connection open after a database request
timTimeOut TIME Timeout in seconds (default: 30 s)
saRequest ARRAY SQL request string array
xReady BOOL Output: ready for a new SQL request
xBusy BOOL Output: SQL request in progress
xDone BOOL Output: SQL request completed successfully
xError BOOL Output: SQL request ended with an error
diResultState DINT Output: status / error code (0 = no error)
diResultRows DINT Output: number of result datasets
diResultColumns DINT Output: number of result columns
saColumnsName ARRAY Output: column names array
saTableValues ARRAY Output: result data array (rows x columns)
diCycle DINT Output: cycle time
BUFFER & GLOBAL CONSTANTS
Constant Default Description
diMaxRows 50 Maximum number of datasets from the table array
diMaxColumns 15 Maximum number of columns from the table array
diStringLength 256 String length in the table array
diUBoundRequestArray 5 Upper boundary of the request string array
diRequestStringLength 256 String length of request string array entries
diReadDataBuffer 1024 Data buffer for reading data (bytes)
diWriteDataBuffer 1024 Data buffer for writing data (bytes)
ERROR CODES (diResultState)
Error Code Description
1 Unknown SQL command
2 Query returns more records than MaxRows. Adjust query or increase MaxRows.
3 Query returns more columns than MaxColumns. Adjust query or increase MaxColumns.
5 Query returns at least one value larger than MaxStringLength. Adjust query or increase MaxStringLength.
10 Internal Connector error
11 Internal Connector error; database cannot be opened
21 No IP address defined for PLC and/or Connector
22 No port number defined
23 Request string is empty
24 MaxRows not defined
25 MaxColumns not defined
26 MaxStringLength not defined
27 MaxBytes not defined
28 Too much data written to the send data buffer
41 Error opening the controller port
42 No connection to SQL4automation Connector. Check firewall.
51 Error during sending of request
71 Connection to SQL4automation Connector cannot be closed
99 Timeout: no response from Connector within the time window
>100 ODBC database connection error codes
40002 General error in SQL query; request string is invalid

Switch to SQL4automation Now.

Connect industrial controllers directly with SQL databases. Field-proven since 2007 for maximum performance and security, completely without middleware.

B&R
by Industry.