Zum Hauptinhalt springen

FANUC / SQL4FANUC

Requirements

The following software options must be enabled on the controller:

  • R632 KAREL

  • R648 User Socket Msg

Setup interface (Client-Tag)

  • Menu – Setup – Host Comm
Menu – Setup – Host Comm
  • [F4] Show – Clients
[F4] Show – Clients
  • Find free client – [F3] Detail
Find free client – [F3] Detail Find free client – [F3] Detail
  • Comment – Name Client
Comment – Name Client
  • Protocol – [F4] Choice – SM
Protocol – [F4] Choice – SM
  • Startup State – [F4] Choice – Define
Startup State – [F4] Choice – Define
  • Enter Server IP/Hostname
Enter Server IP/Hostname
  • [F2] Action – Define
[F2] Action – Define [F2] Action – Define
  • Menu – Next – System – Variables
Menu – Next – System – Variables
  • Find $HOSTC_CFG – Detail
Find $HOSTC_CFG – Detail
  • Choose Tag-Index (Tag C1 -> [1]) – Detail
Choose Tag-Index (Tag C1 -> [1]) – Detail Choose Tag-Index (Tag C1 -> [1]) – Detail
  • Find $SERVER_PORT and enter port number
Find $SERVER_PORT and enter port number

Inserting KAREL files into the project

  • SQL4Fanuc.kl Example program for a database request

  • S4ARoutine.kl contains all routines for a database request

S4ARoutine.kl contains all routines for a database request
  • Open SQL4Fanuc build it
Open SQL4Fanuc build it
  • SQL4Fanuc.pc was created
SQL4Fanuc.pc was created

Call SQL4FANUC in TP-Program

  • Create new TP-Program and insert call INST – CALL – CALL program - KAREL
INST – CALL – CALL program - KAREL Enter Parameter – Choice – Constant
  • Enter Parameter – Choice – Constant
Enter Parameter – Choice – Constant
  • The parameter passed is read out in the Karel program (selector) and

calls the desired SQL query

The parameter passed is read out in the Karel program (selector) and In debug mode, information about the SQL query is displayed on the user page
  • In debug mode, information about the SQL query is displayed on the user page.
In debug mode, information about the SQL query is displayed on the user page

Insert database query in Karel program

Constants and variables are prepared in the Karel program. They should not be changed, because they are also used in the S4ARoutines.

  • The constants contain settings for the protocol
The constants contain settings for the protocol
  • More variables can be added to the project as needed.

  • After the variables, the SQL4Fanuc target library (S4ARoutine) is inserted.

After the variables, the SQL4Fanuc target library (S4ARoutine) is inserted

SQL Request

Structure

  • An SQL query is entered in the string array request
The array size can be adjusted as needed

The array size can be adjusted as needed

  • The array helps among other things to build queries that are larger than 254 characters..
The array helps among other things to build queries that are larger than 254 characters

Execution

  • A database query is executed with the SqlRequest() function
When calling the function 2 parameters follow

When calling the function 2 parameters follow:

  • ClientTag e.g. 'C1:' corresponds to the configured client tag 1

  • Debug When True: Information is displayed on the user page

The function returns a return value:

  • 0 Query was executed successfully

  • -1 Timeout during the request

  • -2 UMS-File could not be created (Fanuc-Error)

  • -3 No connection to the connector could be established

  • >0 Error message from the connector

Evaluation

  • At Return 0 the data of the query are stored in the table DataTable[Rows][Columns] as string values
With the help functions from the S4ARoutine (see below) the data from the table are copied into variables

With the help functions from the S4ARoutine (see below) the data from the table are copied into variables.

In this example, the values of the parameters Speed and WaitTime are queried from the table tParameter and then entered into the numeric registers 1 and 2.

In this example, the values of the parameters Speed and WaitTime are queried from the table tParameter and then entered… S4ARoutine

S4ARoutine

The S4ARoutine contains beside the actual SqlRequest function for queries of the database also a number of auxiliary functions.

FunctionParameterDatatypeDescription
SqlRequetsClientTagStringClient tag of the configured connection
DebugBooleanTRUE: Information is displayed on the user page
ReturnInteger

0 Query was executed successfully

-1 Timeout during the request

-2 UMS-File could not be created (Fanuc-Error)

-3 No connection to the connector could be established

>0 Error message from the connector

Convert boolean variable into string

FunctionParameterDatatypeDescription
Bool2StringValueBooleanValue of boolean variable
StateInteger

Status of function

0 Success

ReturnStringValue as string

Convert string variable to boolean variable

FunctionParameterDatatypeDescription
String2BoolValueStringValue of string variable
StateInteger

Status of function

0 Success

-1 String can’t be converted

ReturnBooleanValue as boolean (False on error)

Convert integer variable to string

FunctionParameterDatatypeDescription
Int2StringValueIntegerValue of integer value
StateInteger

Status of function

0 Success

ReturnStringValue as string

Convert string variable to integer

FunctionParameterDatatypeDescription
String2IntValueStringValue of string variable
StateInteger

Status of function

0 Success

-1 String can’t be converted

ReturnIntegerValue as integer (0 on error)

Convert integer variable to BCD-string

FunctionParameterDatatypeDescription
Int2StrBCDValueIntegerValue of integer variable
StateInteger

Status of function

0 Success

ReturnStringValue as string in BCD-Format (10101010)

Convert BCD-string variable to integer

FunctionParameterDatatypeDescription
StrBCD2IntValueStringValue of string variable in BCD-Format (01010101)
StateInteger

Status of function

0 Success

ReturnIntegerValue as integer

Convert integer variable to HEX-String

FunctionParameterDatatypeDescription
Int2StrHEXValueIntegerValue of integer variable
StateInteger

Status of function

0 Success

ReturnStringValue as string in HEX-Format (0x00FF00FF)

Convert real variable to string

FunctionParameterDatatypeDescription
Real2StringValueRealValue of real variable
StateInteger

Status of function

0 Success

ReturnStringValue as string

Convert string variable to real

FunctionParameterDatatypeDescription
String2RealValueStringValue of string variable
StateInteger

Status of function

0 Success

-1 String can’t be converted

ReturnRealValue as real (0.0 on error)

Get TP-CALL parameter as integer

FunctionParameterDatatypeDescription
GetTpParIntParNbIntegerParameter number
StateInteger

Status of function

0 Success

-1 Type is Integer

-2 Type is Real

-3 Type is String

-4 Type is unknown

-5 Error in function

ReturnIntegerParameter value as integer (0 on error)

Read TP-CALL parameter as real

FunctionParameterDatatypeDescription
GetTpParRealParNbIntegerParameter number
StateInteger

Status of function

0 Success

-1 Type is Integer

-2 Type is Real

-3 Type is String

-4 Type is unknown

-5 Error in function

ReturnRealParameter-Value as real (0.0 on error)

Read date and time

FunctionParameterDatatypeDescription
GetTimeStrFormatInteger

Status of function

0 Date and time (31.12.2020 23:59:59)

1 only date (31.12.2020)

2 only time (23:59:59)

3 File (20201231_235959)

ReturnStringValue as real (0.0 on error)