wincc怎么做数据库_wincc 数据库的连接方法

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:14   2260   0

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的第三方软件和用户自行开放的OPCSERVER/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 ObjectDim var As StringDim value As VariantDim cell As VariantDim i As IntegerSet mcp = CreateObject("WinCC-Runtime-Project")cell = "C3"i = 1Do While Not Range(cell) = ""var = Range(cell)value = mcp.GetValue(var)Range("D" & 2 + i).value = valuecell = "c" & i + 3i = i + 1LoopEnd SubPrivate Sub CommandButton2_Click()Dim mcp As ObjectDim var As StringDim value As VariantDim cell As VariantDim i As IntegerDim bRet As IntegerSet mcp = CreateObject("WinCC-Runtime-Project")cell = "c3"i = 1Do While Not Range(cell) = ""var = Range(cell)value = Range("E" & 2 + i).valuebRet = mcp.SetValue(var, value)cell = "c" & i + 3i = i + 1LoopEnd Sub5。可以使用 WINCC提供的SIMATIC DMC ActiveX控件存取WINCC过程数据,简单例程如下:Dim tagVal as VariantDim myState as LongDim myDmc as Object' Write the WinCC tag value named "NewTag"'tagVal is the value which will be written in WinCCPrivate Sub Command1_Click()Dmc1.Connect myDmcDmc1.Write "NewTag",100,tagValDmc1.DisconnectEnd Sub' Read the WinCC tag value named "NewTag"' tagVal will get the tag value from WinCCPrivate Sub Command1_Click()Dmc1.Connect myDmcDmc1.Read "NewTag",100,tagVal,myStateDmc1.DisconnectEnd Sub

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP