wincc连接mysql数据库说明_wincc 数据库的连接方法
WinCC中如何與本地數據庫(如SQL
SERVER、ORACLE)進行數據交換?以下的測試將說明如連接遠程的數據庫:
Topic One: ODBC
Testing environment:
Primary PC with a WinCC, This PC, we named is
Server.
Secondary PC with a Access DB, This PC, we named is
Client.
Server PC and Client PC is connected by Ethernet.
Test step:
1. The Server PC and the Client PC must config the DB server
option. This is a very
important ODBC configuration step.
Control Panel -> SIMATIC Workstation -> Workstation
Configuration -> TCP/IP
Configuration for Multiple Node Systems -> select the DB server
option.
2. At the server PC node, active the WinCC project but do not
running this project(This action
is only for the first time ODBC configuration at the client PC) .
WinCC will build two ODBC
driver connections automatically, one is for RT Database and the
other is for RC Database.
For example:
"CC_u1_01-04-12_15:36:08R","CC_u1_01-04-12_15:36:08".
All of the jobs is over at the server PC node.
3. At the client PC node, open the contol panel folder and select
the "Sybase SQL
Anywhere5.0" driver for configuration ODBC Driver.
Data Source Name:CC_u1_01-04-12_15:36:08R (be named at the server
PC node.)
User ID: DBA
Password: SQL
Server Name: BJADLIJS_N (Server PC Node computer
name)
Database Name: CC_u1_01-04-12_15:36:08R (the same as Data Source
Name)
Database File://Bjadlijs/WinCC50_Project_u1/u1RT.db(the
"WinCC50_Project_u1" is a
share directory by WinCC automatically and the "u1RT.db" is the
WinCC RT database name.
you'd better search the "u1RT.db" file via the Browse
button.)
At this time, we completed the ODBC configuration.
4. At the server PC node, Running the WinCC project( Don't forget
to select the Tag Logging
option in the start up page, at the same time you could creat a
form by user archive only for
test.)
5. At the client PC node, you could open an Access and import or
link forms via an ODBC
driver that is builded at the step three.
?
如何正確使用第三方軟件(如VB)對WinCC的SYBASE數據庫進行操作,應注意什么細節?
通過ODBC,可以使用第三方軟件對數據庫進行操作(VB,VC,DELPHI).下面是分別使用
DAO,RDO和ADO方法對WinCC的RT數據庫訪問的簡單例程,開發環境為VB6.0:
Public wsODBC As Workspace
Public cnODBC As Connection
Public rsODBC As Recordset
‘DAO method
Public Sub LoadODBCData()
Set wsODBC = DBEngine.CreateWorkspace("ODBC_ws", "Admin", "",
dbUseODBC)
Set cnODBC = wsODBC.OpenConnection("Connection1", , ,
_
"ODBC;UID=DBA;PWD=SQL;DSN=CC_416_01-04-17_00:54:00R")
Set rsODBC =
cnODBC.OpenRecordset("PDE#HD#TankValue_Arc#TankLevel2")
‘PDE#HD#TankValue_Arc#TankLevel2 is RT database sample
table
'DBGrid1.Text = rsODBC
T1.Text = rsODBC.Fields("T")
T2.Text = rsODBC.Fields("V")
rsODBC.Close
cnODBC.Close
wsODBC.Close
End Sub
’RDO method
Public Sub RDOData()
Dim rs As rdoResultset
Dim cn As New rdoConnection
Dim SQL As String
Set cn = New rdoConnection
With cn
.Connect = "uid=DBA;pwd=SQL;DSN=demo1;"
‘demo1 is a manully created ODBC DSN of Sybase
database
.EstablishConnection rdDriverNoPrompt, False
End With
SQL = "select * from contact"
Set rs = cn.OpenResultset(SQL, rdOpenKeyset, _
rdConcurReadOnly, rdAsyncEnable + rdExecDirect)
T3.Text = rs!city
T4.Text = rs!id
End Sub
‘ADO method
Public Sub AdoData()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "select * from contact order by id", _
"uid=DBA;pwd=SQL;DSN=demo1;"
T5.Text = rs!id
T6.Text = rs!city
End Sub
值得注意的是
1.在OFFICE套件中,不能使用RDO訪問ODBC數據庫,因為MICROSOFT沒有對VBA提供
RDO的庫函數.
2.ODBC的USER DSN 是在工程啟動的過程中自動生成的,無需用戶干預
3.有兩個數據庫,一個是CONFIG 數據庫,里面存放的是組態信息,另一個是實時(RT)數據庫,
里面存放的是過程的數據,包括歷史和報警等信息,用戶更多的將是對RT庫的操作;如果不清
除數據庫的具體結構,可以使用WINCC安裝目錄 ( 例如
c:/siemens/common/sqlany/scview.exe )
下的scview.exe查看具體的TABLE及字段,還可以
用其目錄下的isql.exe工具用SQL語句查詢具體的記錄
?
WinCC怎樣作為數據提供者向外提供數據(怎么開放其內部數據)?
主要有以下幾種方法:
1。.通過ODBC進行local/remote方式的數據庫的連接(上面已經敘述);
2。.通過OPC進行local/remote方式的過程數據的連接,包括WINCC之間的連接和與
WINAC之間的OPC通訊,以及其他支持OPC的第三方軟件和用戶自行開放的OPC
SERVER/CLIENT軟件通訊;
3。 通過DDE與本機交換過程數據,通過NETDDE向遠方PC提供數據;
4。.通過OLE與EXCEL通訊,在EXCEL中使用VBA,創建WINCC對象,使用其
GetValue和SetValue方法可以與WINCC交換數據。(具體見WINCC電子文檔
CONFIG2_C.PDF文件)。下面是EXCEL中的VBA例程:
Private Sub CommandButton1_Click()
Dim mcp As Object
Dim var As String
Dim value As Variant
Dim cell As Variant
Dim i As Integer
Set mcp = CreateObject("WinCC-Runtime-Project")
cell = "C3"
i = 1
Do While Not Range(cell) = ""
var = Range(cell)
value = mcp.GetValue(var)
Range("D" & 2 + i).value = value
cell = "c" & i + 3
i = i + 1
Loop
End Sub
Private Sub CommandButton2_Click()
Dim mcp As Object
Dim var As String
Dim value As Variant
Dim cell As Variant
Dim i As Integer
Dim bRet As Integer
Set mcp = CreateObject("WinCC-Runtime-Project")
cell = "c3"
i = 1
Do While Not Range(cell) = ""
var = Range(cell)
value = Range("E" & 2 + i).value
bRet = mcp.SetValue(var, value)
cell = "c" & i + 3
i = i + 1
Loop
End Sub
5。可以使用 WINCC提供的SIMATIC DMC ActiveX控件存取
WINCC過程數據,簡單例程如下:
Dim tagVal as Variant
Dim myState as Long
Dim myDmc as Object
' Write the WinCC tag value named "NewTag"
'tagVal is the value which will be written in
WinCC
Private Sub Command1_Click()
Dmc1.Connect myDmc
Dmc1.Write "NewTag",100,tagVal
Dmc1.Disconnect
End Sub
' Read the WinCC tag value named "NewTag"
' tagVal will get the tag value from WinCC
Private Sub Command1_Click()
Dmc1.Connect myDmc
Dmc1.Read "NewTag",100,tagVal,myState
Dmc1.Disconnect
End Sub
總結
以上是生活随笔為你收集整理的wincc连接mysql数据库说明_wincc 数据库的连接方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 常见浏览器兼容性问题与解决方案?
- 下一篇: 【原】unity shader(3)反射