wincc连接mysql数据库说明_wincc 数据库的连接方法
发布日期:2021-06-24 13:33:20 浏览次数:2 分类:技术文章

本文共 5167 字,大约阅读时间需要 17 分钟。

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

转载地址:https://blog.csdn.net/weixin_33212263/article/details/113549923 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:matlab std函数 omitnan_MATLAB之使用GUI处理语音信号(三)时域分析及卷积运算
下一篇:python循环 文件名_Python 与 Stata 配合批量转换数据

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月07日 14时11分28秒