Jak udostępnić dane z tabeli bazy SQL do serwera OPC? samouczek ANT How to share data from SQL database table to the OPC Server? ANT tutorial
Krok 1: Uruchom ANT Studio i dodaj do drzewka konfiguracyjnego moduł OPC Server Step 1: Run ANT Studio and add to the configuration tree module "OPC Server" Krok 2: Włącz moduł OPC Server Step 2: Switch on module "OPC Server"
Krok 3: Dodaj do drzewka konfiguracyjnego moduł ODBC Step 3: Add to the configuration tree module "ODBC" Krok 4: Włącz moduł ODBC Step 4: Switch on module "ODBC"
Krok 5: Wyszukaj źródła ODBC wybierając polecenie Explore ODBC Step 5: Scan for ODBC data sources, select Explore ODBC Krok 6: Wybierz źródło ODBC, poleceniem Connect Step 6: Choose ODBC source pressing Connect
Krok 6: Dodaj moduł skryptu TCL wybierz ScriptTemplate Step 6: Add scripted module (TCL), choose ScriptTemplate Krok 7: Dodaj do modułu skryptowego kanał wejściowy SQL result Step 7: Add to the scripted module input channel of type SQL result
Krok 8: Połącz moduł skryptowy ze źródłem ODBC przeciągając kanał result z ODBC do sql_result0_in w module ScriptedTemplate0 Step 8: Connect scripted module with ODBC source by dragging channel result from ODBC to sql_result0_in in ScriptedTemplate0 module. Krok 9: Skopiuj wzorzec skryptu template.tcl w katalogu ANTStudio\ScriptedModules i zmień jego nazwę na SQL2OPC.tcl Step 9: Copy script template.tcl and replace its name to SQL2OPC.tcl in ANT Studio\ScriptedModules.
Krok 10: Wybierz SQL2OPC.tcl w module ANT Studio ModuleScript SourcePath Step 10: Choose SQL2OPC.tcl in module ANT Studio ModuleScript SourcePath Krok 11: Dodaj kanał wyjściowy typu double w module skryptowym lub dodaj więcej kanałów które chcesz udostępnić Step 11: Add output channel type "double" in the script module or add more channels you want to share
Krok 12: Połącz kanał wyjściowy modułu skryptowego z modułem OPCServer Przeciągnij double0_out do InputChannels w module OPCServer Step 12: Connect the output channel module with a module script OPCServer Drag double0_out to InputChannels module OPCServer
Krok 13: Napisz program TCL odczytujący dane z bazy i udostępniający je, jako kanały ANT Studio. Poniżej treść przykładowego programu. Step 13: Write TCL program reading data from database and providing them as channels ANT Studio. The following sample program content. package require antutility proc startup { { # Startup is called once at the beginning. Here initialize Your variables and set input channels policy # save_and_notify - notifydata is called and value is available when input channel value changes foreach {i [antgetinputchannels] { antsetchannelcontrol $i save_and_notify # Install hooks, Available hooks: 1/100s 1/10s 1s 2s 5s 10s 30s 1m #more than one hook can be installed antinstallhook "1 s" proc shutdown { { # Shutdown is called at the end. Uninitialize variables here proc notifydata { channel_name { # NotifyData is called when input channel value changes # Remember to clean input channel buffer antclearchannelvalues $channel_name proc timerhook { hook_name { #called every installed hook 1s antsqlquery sql_result0_in answer "SELECT * FROM example_table limit 1" antsqlcheck answer result antlog "SQLResult $answer(column_count) columns & $answer(row_count) rows" for { set i 0 { $i < $answer(column_count) { incr i { antlog "Column $i: name \"$answer(column_$i\_name)\", table name \"$answer(column_$i\_table_name) \",type \"$answer(column_$i\_type)\"" for { set i 0 { $i < $answer(row_count) { incr i { antlog "Row $i: \"$answer(row$i)\"" antsetchannelvalues double0_out [lindex $answer(row$i) 2] [lindex $answer(row$i) 1] 1
Krok 14: Włącz moduł skryptowy. Step 14: Switch on scripted module. Krok 15: Ustaw tryb ukryty wstawania aplikacji po jej starcie Minimalized to try. Step 15: Set starup mode as Minimalized to tray.
Krok 16: Zapisz konfigurację jako. Step 16: Save configuration as. Krok 17: Zarejestruj serwer OPC. (Musisz posiadać prawa administratora). Step 17: Register OPC server. You have to have administrator right.
Krok 18: Widok działającej aplikacji. Step 18: View of a running application. Konfiguracja SQL. SQL Configuration. CREATE TABLE "example_table" ( point character varying(100), "time" timestamp without time zone, value double precision ) insert into example_table values('double0_out','2012-09-13 17:25:00',100);