Re: Problems with data exchange beatween forms
Quote:
Originally Posted by
chris128
...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
...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.
Re: Problems with data exchange beatween forms
Quote:
Originally Posted by
Fact
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:
Me.CheckForIllegalCrossThreadCalls = False
Re: Problems with data exchange beatween forms
Quote:
Originally Posted by
Dave Sell
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 :)
Re: Problems with data exchange beatween forms
Quote:
Originally Posted by
chris128
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.
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?
Re: Problems with data exchange beatween forms
Quote:
Originally Posted by
chris128
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.
Re: Problems with data exchange beatween forms
Quote:
Originally Posted by
Dave Sell
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:
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
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 :)
Re: Problems with data exchange beatween forms
Quote:
Originally Posted by
Fact
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?
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:
Imports OPC_Process
Public Class frmMain
'
Private WithEvents m_OPC_Process As OPC_Process.cls_OPC_Group
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'
' This allows me to update my Form's GUI Objects
Me.CheckForIllegalCrossThreadCalls = False
'
m_OPC_Process = New OPC_Process.cls_OPC_Group
'
' I can listen to "any" OPC Server installed on the same OS as the app is running on
' (not all servers in the world tested...)
m_OPC_Process.Initialize_OPC(Me.txt_OPCServer.Text, Me.txt_Context.Text, "10")
'
End Sub
Private Sub AddOPC_Item()
m_OPC_Process.AddListener(Me.txt_Context.Text, "Location/goes/here/" & "TagName")
End Sub
Private Sub WriteOPC_Item()
m_OPC_Process.WriteToTag(Me.txt_Context.Text, "Location/goes/here/" & "TagName", "Value!")
End Sub
Private Sub m_OPC_Process_DataChanged(ByRef Context As String, ByRef TagName As String, ByRef TagValue As String) Handles m_OPC_Process.DataChanged
'
' Any change to any OPCItem that occurs on the device will trigger this Event
' Do anything you want with TagName/TagValues here...
'
End Sub
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.
Re: Problems with data exchange beatween forms
Quote:
Originally Posted by
Dave Sell
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.
1 Attachment(s)
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.