Zum Hauptinhalt springen

B&R / SQL4BR

Requirements

  • B&R Automation Studio V3.0.80.25 or higher

  • Automation Runtime V3.00 or higher

Implementing the Library into the B&R Automation Studio

To implement the library into the B6R Automation Studio, it must be copied into the Library directory of Automation Studio. Per default, this directory is located under: C:\Programme\BrAutomation\AS\Library

Integrating the SQL4BR Library into the Application Program

After a new project has been created, the SQL4BR library must be added to the project. The libraries AsTCP, asstring and standard are automatically integrated.

Global Variables

VAR CONSTANT

diUBoundRequestArray : DINT := 5; (* UpperBoundary Request-String-Array, must be attributed the same value as diUBoundRequestArray of the Library*)

diRequestStringLength : DINT := 256; (* String-Length Request-String-Array, must be attributed the same value as diRequestStringLength of the Library *)

END_VAR

VAR

saRequest : ARRAY[1..diUBoundRequestArray] OF STRING[diRequestStringLength]; (* Request String Array *)

END_VAR

Instance / Interface

The following Variables can be configured in the file SQL4BR.var: VAR CONSTANT

diMaxRows : DINT := 50; (* max Number Datasets, from Table-Array ) diMaxColumns : DINT := 15; ( max Number Columns, from Table-Array ) diStringLength : DINT := 256; ( String-Length in the Table-Array ) diUBoundRequestArray : DINT := 5; ( UpperBoundary Request-String-Array ) diRequestStringLength : DINT := 256; ( String-Length Request-String-Array ) diReadDataBuffer : DINT := 1024; ( Databuffer for Reading the Data ) diWriteDataBuffer : DINT := 1024; ( Databuffer for Writing the Data *)

END_VAR

The SQL4BR contains the following input and output variables:

VAR_INPUT

xExecute : BOOL; (* Executing the SQL Request ) xAbort : BOOL; ( Reset ) sIPAddressPLC : STRING[15]; ( IP address of the PLC ) sIPAddressCon : STRING[15]; ( IP address of the Connector ) iPort : INT; ( Port Number of the SQL4automation-Connectors ) xHoldConnection :BOOL; ( Hold connection to the Connector ) timTimeOut :TIME; ( Timeout in Seconds, Default 30s ) saRequest : ARRAY[1..diUBoundRequestArray] OF STRING[diRequestStringLength]; ( SQL Request String-Array *)

END_VAR

VAR_OUTPUT

xReady : BOOL; (* Ready for SQL Request ) xBusy : BOOL; ( SQL Request in process ) xDone : BOOL; ( SQL Request completed ) xError : BOOL; ( SQL Request resulted in an Error ) diResultState : DINT; ( Status of result / Error number ) diResultRows : DINT; ( Number Result-Datasets ) diResultColumns :DINT; ( Number Result-Columns ) saColumnsName : ARRAY[1..diMaxColumns] OF STRING[diStringLength]; ( Column names*) saTableValues : ARRAY[1..diMaxRows,1..diMaxColumns] OF STRING[diStringLength]; (* Data-Array*) diCycle : DINT; (* Cycle-Time *)

END_VAR

Creating an Instance

Creating an instance of the SQL4BR library and local variables.

VAR

SQL4automation : SQL4BR; xExecute: BOOL; xAbort: BOOL; sIPAddressPLC: STRING[15]:='127.0.0.1'; sIPAddressCON: STRING[15]:='127.0.0.1'; iPort: INT := 11001; xHoldConnection: BOOL := FALSE; timTimeOut: TIME := T#30s; xReady: BOOL; xBusy: BOOL; xDone: BOOL; xError: BOOL; diResultState: DINT; diResultRows: DINT; diResultColumns: DINT; diCycle : DINT; sAnswerSample : STRING[diRequestStringLength];

END_VAR

Error Codes Return-Value

The variable “diResultState” describes the error.

Error NumberError Description
1Unknown SQL Command
2Request returns more datasets than defined by MaxRows, modify request or increase MaxRows
3Request returns more columns than defined by MaxColumns, modify request or increase MaxColumns
5Request returns minimal one value that is bigger than defined by MaxStringLength, modify request or increase MaxStringLength
10Internal Connector error
11Internal Connector error, cannot open database
21No IP address PLC and/oder Connector defined
22No port number defined
23Request string is empty
24Number MaxRows not defined
25Number MaxColumns not defined
26Size MaxStringLength not defined
27Number MaxBytes not defined
28Too much data was written to the send data buffer
41Error during opening the Control system port
42No connection to SQL4automation-Connector established. Turn off Firewall.
51Error during sending of request
71Connection to the SQL4automation-Connector cannot be closed
99Timeout
>100Error numbers of the ODBC database connection (some known error numbers are attached)
40002General error during SQL request, request string is invalid

Sample Project SQL4BRSample

The SQL4BR Library has already been integrated into the sample project SQL4BRSample. The project can be tested on the Soft PLC AR000 which is contained in B&R Automation Studio. The connector must be started, and the connection to the sample library “S4A_Test_DB.mdb” must be configured.

The configuration of the connection to the database is described in chapter 4.1.2 Setting up the connection to the test database.

By forcing xExecute, the program can be tested. In the case of an error, the connection can be reset by forcing xAbort.

By forcing xExecute, the program can be tested. In the case of an error, the connection can be reset by forcing xAbort