ifix output
from http://read.pudn.com/downloads589/doc/2410171/ifix/iFix.pdf
Private Sub FixTimer3_OnTimeOut(ByVal lTimerId As Long)
Dim conODBC As ADODB.Connection
Dim adoRS As ADODB.Recordset Set conODBC = New ADODB.Connection Set adoRS = New ADODB.Recordset
Dim strQuery As String conODBC.ConnectionString = "DSN = test; UID =sa; PWD =sa;" www.plcworld.cn conODBC.Open "test", "sa", "sa"
strQuery = "select * from form" '或者表名FORM或者SQL选择语句
adoRS.Open strQuery, conODBC, adOpenDynamic, adLockPessimistic
adoRS.AddNew
adoRS!一次电流 = readvalue("Fix32.FIX.AR_1.F_CV", 0)
adoRS!一次电压 = readvalue("Fix32.FIX.AR_2.F_CV", 0)
adoRS!二次电流 = readvalue("Fix32.FIX.AR_3.F_CV", 0)
adoRS!二次电压 = readvalue("Fix32.FIX.AR_4.F_CV", 0)
adoRS.Update adoRS.Close conODBC.Close
End Sub
通过ODBC及ADO写数据到ACCESS数据库方滕二:
此方滕设置同上方滕一,只是纾简了代码部分
Private Sub FixTimer3_OnTimeOut(ByVal lTimerId As Long)
Dim conODBC As ADODB.Connection Set conODBC = New ADODB.Connection conODBC.ConnectionString = "DSN = test; UID =sa; PWD =sa;"
conODBC.Open "test", "sa", "sa"
conODBC.Execute "insert into form([value]) values(3433) "
conODBC.Close
End Sub
通过ADO写数据到ACCESS数据库方滕三: 此方滕由于采用了连接字符串,可以免去ODBC设置,纯纹的ADO编程,代码简单,直接 采用SQL语句写数据到ACCESS数据库中。
Private Sub FixTimer3_OnTimeOut(ByVal lTimerId As Long)
Dim conODBC As ADODB.Connection Set conODBC = New ADODB.Connection conODBC.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\abc. mdb;Persist Security Info=False" '采用连接字符串,可免去ODBC设置
conODBC.Open
conODBC.Execute "insert into form([value]) values(3433) "
conODBC.Close
End Sub
以上三种方滕均可帆3433/454545替换为readvalue("Fix32.FIX.ABC.F_CV", 0)读实时数据 的方滕,实现帆实时数据写到ACCESS。在IFIX3.5/WINDOWS 2000 PROFESSION 带SP4通过 测试。
from https://sites.google.com/site/nyosawu/zi-kong-kai-fa-bei-wang/ifix%E9%80%A3%E6%8E%A5sql%E8%AE%80%E5%AF%AB%E8%B3%87%E6%96%99%E5%92%8C%E8%A3%BD%E4%BD%9Cexcel%E5%A0%B1%E8%A1%A8
IFIX連接SQL讀寫資料和製作excel報表
大概記錄一下流程免忘,原理其實很簡單,都是設定,無限的設定生涯:
1.最基本的安裝sql,創建管理員,創建資料庫還有設置,本處重點記錄:安裝時選用伺服器驗證登入,密碼要記住,伺服器名要記住,後邊要用上。
2.打開windows控制台的管理工具,找到obdc數據源,把創建好的sql資料庫連接進去。
3.在iFix的組態工具裡打開Alarm到obdc的功能,就可以使用了。
原理很簡單 sql <=> obdc <=> ifix
有空再圖片記錄
沒空記錄可以參考csdn的,寫的很詳細
https://blog.csdn.net/chinazz2025/article/details/78047966?locationNum=10&fps=1
記錄1,使用IFIX中的tag連接sql資料庫:
框架:sql腳本語法寫在表裡,ifix透過tag觸發sql腳本執行取得結果
資料在下方:IFIX中將資料記錄通過ODBC保存到SQL SERVER
記錄2,使用vba直接連sql資料庫:
框架:引用 microsoft activeX Data objects 2.X library;'引用microsoft activeX Data objects recordset 2.X;引用Microsoft excel 15.0 object library
本頁元件有輸入起始日期和結束日期的功能,一個生產報表的按鈕,一個顯示HTML檔的控制項,檔名report.grf 儲存在網盤的原始程式碼目錄
代碼:
Option Explicit
'引用microsoft activeX Data objects 2.X library
'引用microsoft activeX Data objects recordset 2.X
'引用Microsoft excel 15.0 object library
Dim a As String '定義中間變數,用來暫存從資料庫中取出的資料
Dim b As String
Dim c As String
Dim d As String
Dim enddayplus1 As Integer
Dim rsADO As ADODB.Recordset '定義連接資料庫的ADO變數
Dim conn As New ADODB.Connection
Public CmdTruck As New ADODB.Command
Public dbUpdata As New ADODB.Command
Public rstUpdata As New Recordset
Private Sub CommandButton3_Click() '點擊按鈕的回應函數
Fix32.AB_FIX.SDAY.A_CV = Fix32.AB_FIX.Year.A_CV + "-" + Fix32.AB_FIX.Month.A_CV + "-" + Fix32.AB_FIX.Day.A_CV
enddayplus1 = Val(Fix32.AB_FIX.EDay.A_CV) + 2
Fix32.AB_FIX.ENDAY.A_CV = Fix32.AB_FIX.EYear.A_CV + "-" + Fix32.AB_FIX.EMonth.A_CV + "-" + Str(enddayplus1)
Call showbb '調用顯示報表的函數showbb
Call closeDB1 '調用關閉資料庫的函數
closeDB1
End Sub
Private Sub showbb()
Dim COL1 As String
Dim COL2 As String
Dim COL3 As String
Dim COL4 As String
COL1 = "ALM_NATIVETIMEIN"
COL2 = "ALM_TAGNAME"
COL3 = "ALM_VALUE"
COL4 = "ALM_DESCR"
Dim Rs As New ADODB.Recordset '定義連接資料庫的ADO變數
openDB1 '打開DB1資料庫,該函數在後面有定義
CmdTruck.ActiveConnection = conn
CmdTruck.CommandText = "SELECT ALM_NATIVETIMEIN, ALM_TAGNAME, ALM_VALUE, ALM_DESCR FROM FIXALARMS WHERE ALM_NATIVETIMEIN Between " + "'" + Fix32.AB_FIX.SDAY.A_CV + "'" + " AND " + "'" + Fix32.AB_FIX.ENDAY.A_CV + "'" + " And ALM_TAGNAME! = '' " '按需求生成ADODB.recordset
Dim xlApp As Object '定義報表物件
Dim xlBook As Object
Dim xlSheet As Object
Dim e As String
Dim f As String
Dim g As String
Dim h As String
Dim i As Integer
i = 2 'ADODB.recordset要寫入EXCEL的ROW數,從ROW2開始寫,ROW1留給中文說明標題了
e = "報警時間"
f = "報警點"
g = "狀態"
h = "說明"
'On Error GoTo errorhandle
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open(System.ProjectPath & "\app\temp.xls") '打開報表範本此範本可以調整樣式,不要放值就好,輸出的報表就會按設計的樣式輸出
Set xlSheet = xlBook.Worksheets(1)
xlApp.DisplayAlerts = False '警告禁用
xlApp.Visible = False 'EXCEL隱藏
xlSheet.Cells(1, 1) = e & "" '第一行的標題文字說明
xlSheet.Cells(1, 2) = f & ""
xlSheet.Cells(1, 3) = g & ""
xlSheet.Cells(1, 4) = h & ""
Set Rs = CmdTruck.Execute '執行SQL語句生成ADODB.RecordSet
While (Not Rs.EOF) '只要不是指向ADODB.RecordSet最後一筆資料將讀出來的數據傳給變數a、b、c、d
a = Rs(COL1)
b = Rs(COL2)
c = Rs(COL3)
d = Rs(COL4)
xlSheet.Cells(i, 1) = a & "" '將變數的值寫到對應excel的儲存格
xlSheet.Cells(i, 2) = b & ""
xlSheet.Cells(i, 3) = c & ""
xlSheet.Cells(i, 4) = d & ""
Rs.MoveNext '指向下一條ROW
i = i + 1
Wend
xlSheet.SaveAs System.ProjectPath & "\app\report.htm", FileFormat:=xlHtml '工作表另存為html
xlSheet.SaveAs System.ProjectPath & "\app\report.xls" '工作表另存為xls
xlApp.DisplayAlerts = True '警告使能
xlApp.Quit
Me.WebBrowser1.Navigate System.ProjectPath & "\app\report.htm" '在WebBrowser控制項上顯示報表
xlApp.Quit
Set xlSheet = Nothing '釋放記憶體
Set xlBook = Nothing
Set xlApp = Nothing
Set CmdTruck = Nothing
Set Rs = Nothing
Exit Sub
errorhandle:
MsgBox "報表生成錯誤!", vbOKOnly + vbInformation, "信息..."
Set xlSheet = Nothing '釋放記憶體
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
Public Sub openDB1() '定義打開資料庫的函數openDB1
If conn.State <> adStateOpen Then
With conn
.ConnectionString = "Driver={SQL Server};Server=127.0.0.1;Database=msdb;Uid=sa;Pwd=123456789;" '連接資料來源的相關資訊
.ConnectionTimeout = 30
.Mode = adModeReadWrite
.Open
End With
End If
End Sub
Public Sub closeDB1() '定義關閉資料庫的函數closeDB1
If conn.State = adStateOpen Then
conn.Close
End If
End Sub
from http://fs.gongkong.com/files/technicalData/201302/2013021815582300001.pdf
iFix 中实现 EXCEL 报表 在 VBA 中引用 Microsoft Excel 11.0 Object Library 和
Microsoft ADO 6.0 Library。在画面中添加个按钮。复制以下代码: Option Explicit Dim rsADO As ADODB.Recordset Dim cnADO As ADODB.Connection Private Sub Command1_Click() Dim StrDir As String StrDir = "E:\" Dim i As Long Dim Sql As String Sql = "SELECT * FROM THISNODE" Set cnADO = New ADODB.Connection Set rsADO = New ADODB.Recordset cnADO.ConnectionString = "Provider = Microsoft OLE DB Provider for ODBC Drivers;DSN=FIX Dynamics Real Time Data;UID=;PWD=" cnADO.Open rsADO.CursorLocation = adUseClient rsADO.Open Sql, cnADO, adOpenDynamic, adLockUnspecified, -1 If rsADO.RecordCount <= 0 Then MsgBox "无数据!", vbOKOnly + vbInformation, "信息..." Set cnADO = Nothing Set rsADO = Nothing Exit Sub End If Dim xlApp As Object Dim xlBook As Object Dim xlSheet As Object Set xlApp = New Excel.Application xlApp.DisplayAlerts = False xlApp.Visible = False Set xlBook = xlApp.Workbooks.Open(StrDir & "\报表.xls") Set xlSheet = xlBook.Worksheets(1) For i = 1 To rsADO.RecordCount xlSheet.Cells(i, 1) = rsADO.Fields(1).Value & "" 杭州集益科技有限公司 GE FANUC最大分销商 地址:杭州市文一路66号 电话:0571-88227048 杭州集益科技有限公司 GE FANUC最大分销商 地址:杭州市文一路66号 电话:0571-88227048 xlSheet.Cells(i, 2) = rsADO.Fields(2).Value & "" xlSheet.Cells(i, 3) = rsADO.Fields(3).Value & "" xlSheet.Cells(i, 4) = rsADO.Fields(4).Value & "" Next i xlApp.Visible = True xlApp.DisplayAlerts = False Set xlSheet = Nothing Set xlBook = Nothing Set xlApp = Nothing Set cnADO = Nothing Set rsADO = Nothing End Sub 注意:1.iFix 历史数据库只支持读 90 天的数据,在 SQL 语句中限定时间即可。 2.也可以读取其他数据源的数据,如 ACCESS、SQL SERVER 等,只要改 一下 ConnectionString。 3. 连接字符串 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\Test.mdb";Persist Security Info=False" "Provider=SQLOLEDB.1;Server="192.168.0.10";DataBase="NorthWind"; UID="sa";PWD="
from https://blog.csdn.net/chinazz2025/article/details/78047966?locationNum=10&fps=1
留言
張貼留言