wincc 数据库的连接方法

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
通过ODBC,可以使用第三方软件对数据库进行操作(VB,VC,DELPHI).下面是分别使用
DAO,RDO和ADO方法对WinCC的RT数据库访问的简单例程,开发环境为VB6.0:
Public wsODBC As Workspace
Public cnODBC As Connection
Public rsODBC As Recordset
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
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
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)
.EstablishConnection rdDriverNoPrompt, False
End With
SQL = "select * from contact"
Set rs = cn.OpenResultset(SQL, rdOpenKeyset, _
rdConcurReadOnly, rdAsyncEnable + rdExecDirect)
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
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;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
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
WINAC之间的OPC通讯,以及其他支持OPC的第三方软件和用户自行开放的OPC
SERVER/CLIENT软件通讯;
3。 通过DDE与本机交换过程数据,通过NETDDE向远方PC提供数据;
4。.通过OLE与EXCEL通讯,在EXCEL中使用VBA,创建WINCC对象,使用其
GetValue和SetValue方法可以与WINCC交换数据。(具体见WINCC电子文档
Private Sub Command1_Click()
Dmc1.Connect myDmc
Dmc1.Write "NewTag",100,tagVal
Dmc1.Disconnect
End Sub
' Read the WinCC tag value named "NewTag"
? WinCC 中如何与本地数据库(如SQL SERVER、ORACLE)进行数据交换?
以下的测试将说明如连接远程的数据库:
Topic One: ODBC
Testing environment:
Primary PC with a WinCC, This PC, we named is Server.
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
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
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过程数据,简单例程如下:
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
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.
用其目录下的isql.exe工具用SQL语句查询具体的记录
? WinCC怎样作为数据提供者向外提供数据(怎么开放其内部数据)?
主要有以下几种方法:
1。.通过ODBC进行local/remote方式的数据库的连接(上面已经叙述);
2。.通过OPC进行local/remote方式的过程数据的连接,包括WINCC之间的连接和与
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".
'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()
2. At the server PC node, aing this project(This action
is only for the first time ODBC configuration at the client PC) . WinCC will build two ODBC
‘DAO method
Public Sub LoadODBCData()
Set wsODBC = DBEngine.CreateWorkspace("ODBC_ws", "Admin", "", dbUseODBC)
Set cnODBC = wsODBC.OpenConnection("Connection1", , , _
important ODBC configuration step.
Control Panel -> SIMATIC Workstation -> Workstation Configuration -> TCP/IP
Configuration for Multiple Node Systems -> select the DB server option.
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
3.有两个数据库,一个是CONFIG 数据库,里面存放的是组态信息,另一个是实时(RT)数据库,
里面存放的是过程的数据,包括历史和报警等信息,用户更多的将是对RT库的操作;如果不清
除数据库的具体结构,可以使用WINCC安装目录 ( 例如
c:\siemens\common\sqlany\scview.exe ) 下的scview.exe查看具体的TABLE及字段,还可以
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 是在工程启动的过程中自动生成的,无需用户干预
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.)
相关文档
最新文档