Come trasferire i dati tramite SQL Gateway tra EcoStruxure Machine Expert e qualsiasi database

 

Come funziona?

Requisiti di sistema

Sono necessari i seguenti requisiti di sistema:

oServer (ad esempio MySQL, non fornito da Schneider Electric)

oSQL Client (ad esempio MySQL Workbench, non fornito da Schneider Electric)

oDatabase, creato con SQL Client (ad esempio MySQL Workbench)

oSQL Gateway (è un'installazione separata sul DVD EcoStruxure Machine Expert)

oLibreria SqlRemoteAccess (parte dell'installazione EcoStruxure Machine Expert)

Come trasferire i dati tramite SQL Gateway tra EcoStruxure Machine Expert e qualsiasi database

Per poter trasferire i dati, è necessario dapprima stabilire la connessione SQL con il SQL Gateway. Per informazioni dettagliate, vedere il documento SQL Gateway - Guida utente.

Per poter interfacciare con il SQL Gateway, possono essere necessarie le informazioni su SQL Gateway e sul database dall'amministratore dell'ambiente SQL. Sono necessari l'indirizzo IP del SQL Gateway, il nome della connessione configurato nel SQL Gateway e il nome del database.

NOTA: La sintassi SQL negli esempi di codice in questa descrizione dipende da un server MySQL; se si usa un altro server SQL, i comandi possono essere diversi.

Scrittura dei dati da EcoStruxure Machine Expert al database

Dichiarazione:

PROGRAM WriteData
VAR
     fbWrite           : SE_SQL.FB_SqlDbWrite;
     stConnSettings    : SE_SQL.ST_ConnectionSettings;
     refRequestWstring : SE_SQL.RequestWstring;
END_VAR

Implementazione:

stConnSettings.wsDbConnectionName    := "ConnectionCountry";
stConnSettings.wGwPort               := 3457;
stConnSettings.wsGwIpAddress         := "10.128.154.47";
stConnSettings.timSqlTimeout         := T#20S;
//SQL Command to insert a new Country - MySQL-Syntax: INSERT INTO <database name>.<table name> (column1...columnN) values (value1...valueN)
//SQLite-Syntax: without "<database name>.")
refRequestWstring[1]                 := "INSERT INTO world.countries (Country, CapitalCity, Language)";
refRequestWstring[2]                 := "values ('Germany', 'Berlin', 'german')";

fbWrite(    i_xExecute             := TRUE,
iq_stConnSettings                  := stConnSettings,
i_refRequestWstring                := refRequestWstring,
i_uiNumOfWstrings                  := 2
);

Passo

Azione

1

In ST_ConnectionSettings, impostare l'indirizzo IP (wsGwIpAddress) del PC sul quale è in esecuzione il gateway, ad esempio 10.128.154.47.

2

In ST_ConnectionSettings, impostare la porta (wGwPort) del gateway (impostazione predefinita: 3457).

3

In ST_ConnectionSettings, impostare il nome della connessione (wsDbConnectionName) configurato nel SQL Gateway, ad esempio ConnectionCountry.

4

In ST_ConnectionSettings, impostare il time-out (timSqlTimeout) ad esempio, T#20S.

5

Scrivere la richiesta di scrittura in refRequestWstring, ad esempio INSERT INTO world.countries (Country) values ('France').

6

In i_uiNumOfWstrings, impostare le righe in refRequestWstring, ad esempio, 2.

7

Chiamare FB_SqlDbWrite con le impostazioni, i parametri o le variabili indicati sopra.

NOTA: È possibile utilizzare soltanto una richiesta per chiamata del blocco funzione.

Lettura dei dati da EcoStruxure Machine Expert al database

Dichiarazione:

PROGRAM ReadData
VAR
        fbRead            : SE_SQL.FB_SqlDbRead;
        stConnSettings    : SE_SQL.ST_ConnectionSettings;
        refRequestWstring : SE_SQL.RequestWstring;
        refUserData       : SE_SQL.UserData;
END_VAR

Implementazione:

stConnSettings.wsDbConnectionName  := "ConnectionCountry";
stConnSettings.wGwPort             := 3457;
stConnSettings.wsGwIpAddress       := "10.128.154.47";
stConnSettings.timSqlTimeout       := T#1 M;

//SQL Command to read all Countries in the database - MySQL-Syntax: SELECT (column1...columnN) FROM <database name>.<table name> [where <column>=<value>]
//SQLite-Syntax: without "<database name>."
refRequestWstring[1]               := "SELECT * FROM world.countries";

fbRead  (      i_xExecute            := TRUE,
               iq_stConnSettings     := stConnSettings,
               i_refRequestWstring   := refRequestWstring,
               i_uiNumOfWstrings     := 1,
               i_refUserData         := refUserData
);

Passo

Azione

1

In ST_ConnectionSettings, impostare l'indirizzo IP (wsGwIpAddress) del PC sul quale è in esecuzione SQL Gateway, ad esempio 10.128.154.47.

2

In ST_ConnectionSettings, impostare la porta (wGwPort) del gateway (impostazione predefinita: 3457).

3

In the ST_ConnectionSettings, impostare il nome della connessione (wsDbConnectionName) configurato in SQL Gateway, ad es. ConnectionCountry.

4

In ST_ConnectionSettings, impostare il time-out (timSqlTimeout) ad esempio, T#20S.

5

Scrivere la richiesta di lettura in refRequestWstring, ad esempio SELECT * FROM world.countries.

6

In i_uiNumOfWstrings, impostare le righe in refRequestWstring, ad esempio, 1.

7

In i_refUserData impostare l'array UserData.

8

Chiamare FB_SqlDbRead con le impostazioni, i parametri o le variabili indicati sopra.

Impostazioni avanzate per il buffer dati / Richiesta con i parametri globali

NOTA: Le impostazioni avanzate possono essere sovrascritte specificamente per il progetto nel Gestore libreria.

Passo

Azione

1

In Gc_uiMaxRows impostare il numero max. di righe per l'ARRAY of UserData (necessario solo per FB_SqlDbRead), ad esempio 20.

Risultato: è possibile leggere 20 righe dal database configurato.

2

In Gc_uiMaxColumns impostare il numero max. di colonne per l'ARRAY of UserData (necessario solo per FB_SqlDbRead), ad esempio 10.

Risultato: è possibile leggere 10 colonne dal database configurato.

3

In Gc_uiTableWstringLength impostare il numero max. di caratteri dell'ARRAY of UserData bidimensionale (necessario solo per FB_SqlDbRead), ad esempio 200.

Risultato: è possibile leggere un campo con 200 caratteri dal database configurato.

4

In Gc_uiMaxRequest impostare il numero di righe max. di ARRAY of RequestWstring, ad esempio 20.

Risultato: la richiesta può essere suddivisa in 20 righe di WSTRINGs.

5

In Gc_uiRequestWstringLength impostare il numero max. di caratteri in ARRAY of RequestWstring, ad esempio 200.

Risultato: una riga di richiesta può includere 200 caratteri.