Use COPC32 on Visual Basic.NET

This tutorial will certainly assist you how to use COPC32 on Aesthetic Basic.NET. You need to set up COPC32 on your system prior to develop SCADA with Visual.NET and also COPC32 ActiveX control. As well as we intend that you have OPC Web server on your local system currently.

We will develop the straightforward form to read and also write to OPC web server on local systems. But you would, like to attach to remote OPC server. Please configure DCOM on both web server and customer side by refer to tutorial of KEPWare at http://www.kepware.com/Support_Center/Viewlets/XP_sp2_viewlet_swf.html

The form we will certainly produce is received Figure 1.

Number 1

When customer insert numerical worth in textbox and click switch ‘& lsquo; Write ‘, COPC32 will certainly contact OPC tag and reveal its value on ‘& lsquo

  1. ; Label1 ‘. Open Visual Studio.NET and crate brand-new task with VB.NET

Figure 2

Kind the name of this job as “& ldquo; TestCOPC32VBNET &

rdquo;. 2. Add COPC32 ActiveX control right into tool kit by choose food selection Tools > > Add/Remove Toolbox Things & hellip;

Figure 3

Then select COPC32 shown in Number 4.

Figure 4

Then click “& ldquo;

OK & rdquo; 3. Crate a switch, a textbox and also label on type like displayed in Number 1
At site COPC32 Download from Our Articles

. 4. Select in tool kit as well as drag on the kind.

5. Right click COPC32 control on the form as well as select ActiveX buildings.

Figure 5

Establish upgrade price to 100 msec. And also choose OPC Web server name to wanted OPC Server. You have to get in IP address or machine name in ‘& lsquo; nodname ‘ textbox if you want to link to remote OPC web server over the network.

Figure 6

6. Select OPC Tag you want to attach to.

Figure 7

Click OK.

This OPC Tag could be Readable as well as Writable. You can look at your OPC Web server like displayed in Figure 8.

Number 8 OPC Tag residential or commercial properties.

Figure 9 Configure OPC tag index number = 0

And click OK to leave residential or commercial property pages.

Note: You can configure linked OPC tags by import OPC tag listing from CSV documents which export from OPC Server. Please describe

http://www.scadathai.com/COPC/COPCEng/tutorials.htm

And also see “& ldquo; Exactly how to pack OPC tags from CSV file”&

rdquo;. 7. Dual click the form to get in to Form_Load event code view.

8. Produce the code to connect to OPC server and also get value of OPC tag index 0 to show on Label1.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Takes care of MyBase. Load

Axcopc1.cnnec()

Label1.Text = Convert.ToString(Axcopc1.GetVl( 0 ))

End Below

Keep in mind: If you have configure various other OPC tag such as OPC tag index number = 1. You can obtain its worth using ‘& lsquo

; GetVl( “1)’”. 9. Select & ldquo; Closing & rdquo;

event name from

dropdown. Number 10 As well as develop the code like following

Personal Below Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Manages MyBase. Closing

Application.DoEvents()

Axcopc1.discnn()

End Sub

Keep in mind: We utilize “& ldquo; Application.DoEvents()” & rdquo; to waiting various other task to end up before detach from OPC Server.

10. Back to develop sight. Double click on COPC32 control on the type to go into to “& ldquo; datChange & rdquo; occasion code view. After that produce the code to present OPC tag worth on Label1 when the vale of OPC tag we are attached has altered.

Personal Below Axcopc1_datChange(ByVal sender As Object, ByVal e As System.EventArgs) Deals with Axcopc1.datChange

Label1.Text = Convert.ToString(Axcopc1.GetVl( 0 ))

End Below

11. Back to develop design view. Dual click on button ‘& lsquo; Compose ‘. Then create code to compose vale to OPC tag which has index number = 0.

Private Below Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Takes care of Button1.Click

Axcopc1.opcWrt(0, Convert.ToDouble(TextBox1.Text))

End Sub

12. Test program by click F5. Put the number right into textbox and click ‘& lsquo; Write ‘. You can see the vale received label is equal to your get in number.

Figure 11

The complete related code is shown in Figure 12.