Page 2 of 2 FirstFirst 12
Results 41 to 51 of 51

Thread: Problems with data exchange beatween forms

  1. #41
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Problems with data exchange beatween forms

    Quote Originally Posted by chris128 View Post
    ...I mean is there any way I could test it in the same way you are testing it? Does it require any special equipment or anything like that?
    You can get an OPC-DA DLL from OPC Foundation, Kepware, or RSLinx. The file you need on your system is something like OPCDAAuto.DLL, kepopcdaauto.dll, or RSopcdaauto.dll.

    Once installed on your system, you can instantiate the appropriate objects with which you can examine actual OPC-DA Servers, if you have any installed on your system.

    Iconics has a free OPC Simulator and TopServer has a free OPC Simulator.

    Quote Originally Posted by chris128 View Post
    ...What exactly does this OPC server thing do?
    Think of an OPC-DA server like a printer driver, only an industry standard printer driver. In fact, it is exactly an industry standard device driver. If you make a hardware device, you can also make a software OPC-DA driver to go along with it.

    It is widely adopted because many vendors make useful OPC-DA clients, which all know how to talk to any OPC-DA server.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  2. #42
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Problems with data exchange beatween forms

    Quote Originally Posted by Fact View Post
    Hello all,

    I am trying to make an application, that gets data from OPC server to form1 and displays some pieces in form2. The app works that way: on start - form1 starts. Form2 must be started manually after form form1 is statrted (i mad a buttton for that). If some values in OPC server changes i need to see some of them in form2. Here is a sub which shows how do i get data from OPC server.
    Code:
    Public mObject As List (Of Object)
        Overridable Sub OnDataChange( _
        ByVal dwTransid As Integer, _
        ByVal hGroup As Integer, _
        ByVal hrMasterquality As Integer, _
        ByVal hrMastererror As Integer, _
        ByVal dwCount As Integer, _
        ByVal phClientItems() As Integer, _
        ByVal pvValues() As Object, _
        ByVal pwQualities() As Short, _
        ByVal pftTimeStamps() As OpcRcw.Da.FILETIME, _
        ByVal pErrors() As Integer) Implements IOPCDataCallback.OnDataChange
    
            Dim i As Integer = 0
            Dim j As Integer = 1
            Dim k As Integer = 0
    
            If dwCount > 0 Then
    
                mObject = New List(Of Object)
                For i = 0 To jk - 1
                    For j = 1 To jk
                        If phClientItems(i) = j Then
                            mObject.Add(pvValues(k))
                            k += 1
                        End If
                    Next j
                Next i
            End If
            dwCount = 0
        End Sub
    I have tried to write line before sub end
    Code:
    Dim c As Integer
    For c=0 To mObject.Count - 1
    Form2.mObject.Add(Object(c))
    Next c
    but nothing happened when i opened form2, nor on change of data in OPC server (i wrote the code that on form2 load all values are shown in msgbox, message box did not show up).

    dwCounts - how many values were changed in PLC.
    phClientItems - variable index.
    pvValues - variable value.

    All the ideas are wellcome.

    Thank you in advance.

    I did not study your entire thread, and did not really see if this problem is solved, but a workaround I have used is to place this in the Form2_Load Event:

    VB Code:
    1. Me.CheckForIllegalCrossThreadCalls = False
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  3. #43
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Problems with data exchange beatween forms

    Quote Originally Posted by Dave Sell View Post
    Iconics has a free OPC Simulator and TopServer has a free OPC Simulator.
    Ok cool thanks for the information, I'm downloading that Iconics OPC Simulator now
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #44
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Problems with data exchange beatween forms

    Quote Originally Posted by chris128 View Post
    Ok cool thanks for the information, I'm downloading that Iconics OPC Simulator now
    You should start by examining the OPC Simulator using an OPC Browser.

    Iconics has one for free I think, called OPC Data Spy. Use the OPC Data Spy to examine and set values in your OPC Simulator.

    Then you can attempt to graduate to doing this in code.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  5. #45
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Problems with data exchange beatween forms

    Well at the moment I am just wanting to run the code that the original creator of this thread is using and see what happens. The trouble is at the moment when I test it I do not actually have an OPC server so all I can do is manually call the OnDataChanged sub that he is having problems with, which does not produce the same problems he is having.

    EDIT: OK I've got it installed (and it came with that OPC Spy thing) so now how do I go about sending some data to my project or do I not have to do anything like that?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #46
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Problems with data exchange beatween forms

    Quote Originally Posted by chris128 View Post
    Well at the moment I am just wanting to run the code that the original creator of this thread is using and see what happens. The trouble is at the moment when I test it I do not actually have an OPC server so all I can do is manually call the OnDataChanged sub that he is having problems with, which does not produce the same problems he is having.

    EDIT: OK I've got it installed (and it came with that OPC Spy thing) so now how do I go about sending some data to my project or do I not have to do anything like that?
    The only way to properly execute his code will be to configure the OPC Simulator to be exactly the OPC Topic and exactly the OPC Tags in their exact heirarchical arrangement. The original poster is the only one who knows this.

    As far as the DataChanged event, once you are truly "listening" to an OPC Item in code, then go to the OPC Data Spy, and do a SyncWrite, which allows you to "Set" the value, thus triggering the event.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  7. #47

    Thread Starter
    Member
    Join Date
    Sep 2009
    Posts
    32

    Re: Problems with data exchange beatween forms

    Quote Originally Posted by Dave Sell View Post
    I did not study your entire thread, and did not really see if this problem is solved, but a workaround I have used is to place this in the Form2_Load Event:

    VB Code:
    1. Me.CheckForIllegalCrossThreadCalls = False
    Hey Dave, thanks for the solution, unfortunately it did not make my form 2 to work

    Quote Originally Posted by Dave Sell View Post
    You can get an OPC-DA DLL from OPC Foundation, Kepware, or RSLinx. The file you need on your system is something like OPCDAAuto.DLL, kepopcdaauto.dll, or RSopcdaauto.dll.
    Both dll's - opcrcw.da.dll and opcrcw.comn.dll are in bin\Release directory.

    For testing purpose i am using: Simatic Step7 to load the project to the station, SimaticNET for OPC server, CP5512 with HW adapter to communicate with PLC and S7-300 PLC CPU 315-2DP

  8. #48
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Problems with data exchange beatween forms

    Quote Originally Posted by Fact View Post
    Hey Dave, thanks for the solution, unfortunately it did not make my form 2 to work



    Both dll's - opcrcw.da.dll and opcrcw.comn.dll are in bin\Release directory.

    For testing purpose i am using: Simatic Step7 to load the project to the station, SimaticNET for OPC server, CP5512 with HW adapter to communicate with PLC and S7-300 PLC CPU 315-2DP
    Have you tried that code in the Form1_Load Event?

    Can you email me those DLLs?
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  9. #49
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Problems with data exchange beatween forms

    I made an ActiveX wrapper which I use to easily communicate with OPC Servers from VS2005/2008. It is compiled as a binary package which needs to be installed. Once installed, any VS2005/2008 app (VB+C#) can add a reference to the library.

    On the coding side, the number of lines to code is very minimal:

    VB Code:
    1. Imports OPC_Process
    2.  
    3. Public Class frmMain
    4.     '
    5.     Private WithEvents m_OPC_Process As OPC_Process.cls_OPC_Group
    6.  
    7.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    8.         '
    9.         ' This allows me to update my Form's GUI Objects
    10.         Me.CheckForIllegalCrossThreadCalls = False
    11.         '
    12.         m_OPC_Process = New OPC_Process.cls_OPC_Group
    13.         '
    14.         ' I can listen to "any" OPC Server installed on the same OS as the app is running on
    15.         ' (not all servers in the world tested...)
    16.         m_OPC_Process.Initialize_OPC(Me.txt_OPCServer.Text, Me.txt_Context.Text, "10")
    17.         '
    18.     End Sub
    19.  
    20.     Private Sub AddOPC_Item()
    21.         m_OPC_Process.AddListener(Me.txt_Context.Text, "Location/goes/here/" & "TagName")
    22.     End Sub
    23.  
    24.     Private Sub WriteOPC_Item()
    25.         m_OPC_Process.WriteToTag(Me.txt_Context.Text, "Location/goes/here/" & "TagName", "Value!")
    26.     End Sub
    27.  
    28.     Private Sub m_OPC_Process_DataChanged(ByRef Context As String, ByRef TagName As String, ByRef TagValue As String) Handles m_OPC_Process.DataChanged
    29.         '
    30.         ' Any change to any OPCItem that occurs on the device will trigger this Event
    31.         ' Do anything you want with TagName/TagValues here...
    32.         '
    33.     End Sub
    34.  
    35. End Class

    This is not an official product of our company, but let me know if you'd like to try it, I will see how I can start distributing this.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  10. #50
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Problems with data exchange beatween forms

    Quote Originally Posted by Dave Sell View Post
    Can you email me those DLLs?
    If you go back to the first page of this thread you will see near the end of the page the OP attached his entire project file to a post so you can just get them out of there.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #51

    Thread Starter
    Member
    Join Date
    Sep 2009
    Posts
    32

    Re: Problems with data exchange beatween forms

    Well, i do not have problems with connection to OPC server and all data changes are displayed correct, but only in form where the main code is. The connection to OPC server, creation of group, filling of it with variables is made in form1 load event. What i am after is to be able to view some data in form 1 some data in form2 some data in form 3 and so on. I believe if i put that main code in all forms i will see the result i am seeking, but then the program will be something like 3x, 4x bigger, because i will repeat same code in all forms.

    Those dll's are Runtime Callable Wraper components.

    I have attached a pure code, with some explanations how it works.
    Attached Files Attached Files

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width