OPC and Ms Access

johanime
2011-09-04
2011-09-10
  • johanime - 2011-09-04

    Hi
    I am new to OPC and need some advice. I got the OPC running and when i check the tags with Matrikon Explorer all seems fine no bad connections . The problem is the next step How do I get the info from OPC to Ms Access and back. Don't have a lot of knowledge about OPC . Is there a tutorial or guide available .Or if possible can I go direct from Ms access to codesys.

    Thanks

     
  • TimvH

    TimvH - 2011-09-06

    It is possible in MS Access to add vbscript code. This script can call e.g. a dll or .ocx.
    There is a freeware OPC client component available on the internet called "opc_da20_components.exe".
    When you install this you can call it from e.g. an Access Form with the following code:

    (PS, you can also use the SQL4Automation libraries to connect your PLC to any database supporting ODBC).


    Option Compare Database

    Option Explicit

    'Declare all the variables
    Dim groups As Variant
    Dim group As Variant
    Dim Items As Variant
    Dim Item1 As Variant
    Dim opcauto As Variant

    Private Sub Form_Load()

    Me.TimerInterval = 1000

    'Get OPC Automation Reference
    Set opcauto = CreateObject("OPC.Automation.1")

    'Connect to the server
    opcauto.Connect ("YourOPCServername.xxx")

    'Plays with groups and items
    Set groups = opcauto.OPCGroups
    Set group = groups.Add("Device1.Group")
    group.IsActive = True
    Set Items = group.OPCItems
    Set Item1 = Items.AddItem("Device1.Group1.Tag1", 1)

    End Sub

    Private Sub Form_Timer()

    'Read Item1 and display in Label
    Item1.Read (1)
    Label0_v.Caption = Item1.value
    Label0_q.Caption = Item1.Quality
    Label0_t.Caption = Item1.TimeStamp

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    opcauto.Disconnect

    End Sub

     
  • johanime - 2011-09-10

    Thank you will give a go

     

Log in to post a comment.