Hướng dẫn lưu giá trị trên wincc vào csdl

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Hng dn lu gi tr trn wincc vo csdl

B1: m Sql 2005 ln

Sau khi m ln chn connect


B2: tao CSDL
Vo mc database chn csdl m bn mun lu d liu vo. To table lu d liu

To ct dng lu d liu vo bao gm tn ct v loi d liu cn lu

Sau khi to xong lu li vi tn bn mun

Vy l xong bc to csdl. By gi bn vo Wincc to 1 event dung lu d liu theo thi


gian.

Bn c th dung C hoc VB. Mnh th dung VB

To Trigger

Mnh to trigger 10s. vy c 10s event ny s chy 1 ln v ly gi tr a vo csdl cho ban

Code trong Event


Option Explicit
Function action
Dim objConnection
Dim strConnectionString
Dim strSQL
Dim objCommand

Dim mday
Dim NewTag_1
Dim NewTag
Dim Timer

Set Timer = HMIRuntime.Tags("timer")

mday =FormatDateTime(Now(),0)

Timer.Write mday

strConnectionString ="Driver={SQL Native


Client};Server=tiendung\wincc;Database=CC_fffff_11_07_22_12_18_23R;Trusted_Connection=
yes;"

NewTag_1 = HMIRuntime.Tags("NewTag_1").Read
NewTag = HMIRuntime.Tags("NewTag").Read

strSQL = "INSERT INTO dbo.test (Date,Values1,Values2) VALUES ('"& mday & "' ,'"& NewTag &
"' ,'" & NewTag_1 & "');"

Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

With objCommand

Thnh qu

Mun c d liu ny ln bn c th dung VBS Or VB.


Finish.

tiendungkct@yahoo.com

You might also like