OMRON

For Omron NX/NJ PLCs programmed in Sysmac Studio, SQL4automation provides the SQL4Omron library (Sql4OmronLib.slr). The library requires CPU version 1.18 or newer and uses standard Omron socket functions (SktTCPConnect, SktClose, SktGetTCPStatus, SktClearBuf). The library was developed and tested with an NX1P2.

Connecting Omron PLC to SQL Databases, MES, ERP

SQL4Omron enables Omron NX/NJ PLCs to connect directly to SQL databases via TCP socket communication. The library is referenced as Sql4OmronLib.slr in an existing Sysmac Studio project. Communication uses standard Omron TCP socket functions. Note: the sample project cannot be tested in simulation mode as simulation does not support communication functions.

Integration of the Sql4Omron Library

The Sql4OmronLib.slr library is referenced in the Sysmac Studio project. The fbSql4Omron function block is instantiated and called cyclically in a separate task. SQL commands are assembled as STRING variables. INTEGER and REAL variables are converted to STRING using Omron conversion functions (INT_TO_STRING, DINT_TO_STRING, RealToFormatString) before inclusion in the SQL command.

The Sql4Omron library receives parameters such as the IP address and port of the Connector as well as the SQL string. The return values of the SQL query are written to the stResult structure.

SQL4automation Link Settings

The SQL4automation Connector is operated with the target setting "Standard" for Omron Sysmac Studio controllers. The configuration is completed in just a few clicks.

FAQs

Frequently Asked Questions to Omron

Which Omron Sysmac Studio controllers are compatible with SQL4automation?

SQL4Omron requires Omron NX/NJ series controllers with CPU version 1.18 or newer. The library was developed and tested on an NX1P2 (9024DT1 v1.60). The sample project can be easily adapted to other Omron NX/NJ controller types by changing the controller in Sysmac Studio. Simulation mode is not supported; a physical controller is required for testing.

Can the SQL4Omron sample project be tested in Sysmac Studio simulation mode?

No. The sample project cannot be tested in simulation mode because Sysmac Studio simulation does not support communication functions (SktTCPConnect, SktClose, etc.). A physical Omron NX/NJ controller connected to the network is required to test the SQL4Omron integration.

How is an SQL command assembled in the Omron Sysmac Studio program?

SQL commands are assembled as STRING variables in the Sysmac Studio program. A step chain is programmed in the respective subroutine where the SQL command is built and passed to fbSql4Omron as a STRING. To include INTEGER or REAL values in the SQL command, use Omron conversion functions: INT_TO_STRING, DINT_TO_STRING, or RealToFormatString.

How are query results accessed after a successful SQL query in Sysmac Studio?

Results are available via the stResult output structure and the stSql4OmronInterface interface struct. diResultRows and diResultColumns report the dimensions. diResultState contains the status code (0 = success). The diResultReturnParams output gives the number of return parameters received from stored procedures.

Which SQL databases can an Omron NX/NJ PLC connect to via SQL4automation?

All ODBC-compatible databases are supported, including Microsoft SQL Server, MySQL, MariaDB, PostgreSQL, Oracle, and SQLite. For stored procedure testing, an MS SQL Server is required. The database is configured in the SQL4automation Connector on the Windows PC.

Which Omron controllers has SQL4automation been tested on?

SQL4automation has been developed and tested specifically on the Omron NX1P2 (9024DT1, firmware v1.60) running in Sysmac Studio. The library requires CPU version 1.18 or newer. The sample project (Sql4OmronExampleProject.smc2) can be adapted to other Omron NX/NJ series controllers by changing the controller type in Sysmac Studio. Note: simulation mode is not supported; a physical controller is required.

Technical Data

REQUIREMENTS & VERSION INFO
CPU version 1.18 or newer
Library file Sql4OmronLib.slr (referenced in Sysmac Studio project)
Socket functions SktTCPConnect, SktClose, SktGetTCPStatus, SktClearBuf must be available
Simulation Sample project cannot be tested in simulation mode; physical hardware required
Sample project Sql4OmronExampleProject.smc2 (developed and tested for NX1P2 9024DT1 v1.60)
FUNCTION BLOCK PARAMETERS
Parameter Type Description
sIPAddress STRING[50] IP address of the SQL4automation Connector
iPort UINT Port number of the SQL4automation Connector
tTimeout TIME Communication timeout
stSql4OmronInterface Sql4OmronInterfaceType Interface structure (In/Out)
xExecute BOOL Triggers the database query
xHoldConnection BOOL Keeps the socket connection open after a database query
uiRequestBufferSize UINT Size of the request data buffer (input)
dwResponseBufferSize UINT Size of the response data buffer (input)
diResponseMaxReturnParams UINT Maximum number of return parameters (Connector >= V4.0, otherwise 0)
diResponseMaxRows UINT Maximum number of rows in the DB query response
diResponseMaxColumns UINT Maximum number of columns in the DB query response
diResponseMaxStringLen UINT Maximum string length of the DB query response
diResponseCutStringLen UINT Strings longer than this are truncated (0 = inactive)
xReady BOOL Output: ready for a new database query
xBusy BOOL Output: database query running
xDone BOOL Output: database query completed
xError BOOL Output: database query ended with an error
stResult stParseResponseResultType Output: result interface struct
diResultState DINT Output: status / error code (0 = no error)
diResultReturnParams DINT Output: number of return and output parameters received
diResultRows DINT Output: number of rows received from the DB query
diResultColumns DINT Output: number of columns received from the DB query
ERROR CODES (diResultState)
Error Code Description
1 Unknown SQL command
2 Query returns more records than diResponseMaxRows. Adjust query or increase diResponseMaxRows.
3 Query returns more columns than diResponseMaxColumns. Adjust query or increase diResponseMaxColumns.
5 Query returns at least one value larger than diResponseMaxStringLen. Adjust query or increase diResponseMaxStringLen.
10 Internal Connector error
11 Internal Connector error; database cannot be opened
21 No IP address defined (sIPAddress = '')
22 No port number defined (iPort = 0)
23 Request string is empty
24 MaxRows not defined (diResponseMaxRows = 0)
25 MaxColumns not defined (diResponseMaxColumns = 0)
41 No connection to SQL4automation Connector. Check firewall.
51 Request string larger than send buffer
95 Error receiving data
99 Timeout: no response from Connector within the time window
>100 ODBC database connection error codes

Switch to SQL4automation Now.

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

OMRON
by Industry.