Home | Products | Tutorials | Download | Contact us

 

COPC32 Member

 

V 1.6 (Jan 16, 2006)

* You can create SCADA within unlimited instance of COPC32. For examples, you can create 600 tags SCADA system with 10 COPC32 instances. You can use unlimited instances of COPC32 control.

Updated Properties

Name

Type

Description

Itm0 – Itm59

String

Name of OPC tag like to accessed by COPC

vl0 – vl59 Variant Value of OPC tags connected by COPC

 

V 1.5

* You can create SCADA within unlimited instance of COPC32. For examples, you can create 600 tags SCADA system with 30 COPC32 instances. You can use unlimited instances of COPC32 control.

Properties

Name

Type

Description

IsConnect

Boolean

Return True if COPC already connect to OPC server

Itm0 – Itm19

String

Name of OPC tag like to accessed by COPC

name

String

Name of COPC control

nodname

String

Computer name or IP Address of Remote OPC Server like to connected by COPC

svrname

String

Name of OPC Server like to connected by COPC

UpdateRate

Variant (Number in mSec)

Update or refresh rate of OPC data detections (msec).

vl0 – vl19

Variant

Value of OPC tags connected by COPC

 

 

 

 

Functions & Methods

Name

Type

Description

cnnect

Boolean (Function)

Connect to OPC Server

discnn

Boolean (Function)

Disconnect from OPC Server

GetItmName(i as Integer)

 

Getting name of OPC tag index i

GetQuality(i as Integer)

 

Getting quality of OPC tag index i

GetTimeStamp(I as Integer)

 

Getting time stamp of OPC tag index i

GetVl(i)

 

Getting value of OPC tag index i

opcWrt(i As Integer, vl)

 

Write value vl to OPC tag index i

SetItmName(i As Integer, name As String)

 

Setting name of OPC tags index i

loadCSV(startRow As Integer, columnIndex As Integer, rowCount As Integer, delimitWord As String, sourceFile As String)
  Load OPC tags name from CSV file. You can specify start row to read, column, delimited character and CSV file name you would like to load.

 

Example

This example show how to connect to OPC server when form is loaded and disconnect from OPC Server when form is terminated.

 

[VB, VB.NET]

Private Sub Form_Load()

Dim b As Boolean
b = copc1.cnnec

End Sub

 

Private Sub Form_Terminate()

Dim b As Boolean
b = copc1.discnn

End Sub

 

 

[C#)]

 

private void Form1_Load( object sender, EventArgs e)

{

bool b;

b=axcopc1.cnnec();

}

 

private void Form1_FormClosing( object sender, FormClosingEventArgs e)

{

bool b;

b = axcopc1.discnn();

}

 

Example

 

This example show how to connect to OPC server when form is loaded then display value of OPC tags on label control. And disconnect from OPC Server when form is terminated.

 

[VB, VB.NET]

 

Private Sub Form_Load()

Dim b As Boolean

b = copc1.cnnec

Label1.Caption = copc1.GetVl(0)

Label2.Caption = copc1.GetVl(1)

End Sub

 

Private Sub Form_Terminate()

Dim b As Boolean

b = copc1.discnn

End Sub

 

‘Display OPC values when OPC data changed

Private Sub copc1_datChange()

Label1.Caption = copc1.GetVl(0)

Label2.Caption = copc1.GetVl(1)

End Sub

 

[C#)]

 

private void Form1_Load( object sender, EventArgs e)

{

bool b;

b = axcopc1.cnnec();

//call sub ‘shw' to display OPC values

shw();

}

 

private void Form1_FormClosing( object sender, FormClosingEventArgs e)

{

bool b;

b = axcopc1.discnn();

}

 

private void axcopc1_datChange( object sender, EventArgs e)

{

shw();

}

 

private void shw()

{

short i;

i = 0;

//Check if null first. Then display OPC values on Label control

label1.Text = axcopc1.GetVl( ref i)== null ? "Null" : axcopc1.GetVl( ref i).ToString();

i = 1;

label2.Text = axcopc1.GetVl( ref i)== null ? "Null" : axcopc1.GetVl( ref i).ToString();

}

 

Example

This example shows how to write value to OPC tag.

Write value 23.67 to OPC tag index 1 when user click on command button.

 

[VB, VB.NET]

 

Private Sub Command1_Click()

If copc1.IsConnect Then 'Check if OPC Server is connected

copc1.opcWrt 1, 23.67

End If

End Sub

 

 

[C#]

 

private void button1_Click( object sender, EventArgs e)

{

if (axcopc1.IsConnect) //Check if OPC Server is connected

{

short i;

object val= new object ();

i = 1;

val = 23.67 ;

axcopc1.opcWrt( ref i, ref val);

}

}

 

If you have any questions, please contact projects@scadathai.com

We answer rapidly.

 

Example

This example show how to load the list of OPC tag names from CSV file. First, you need to export OPC tag names from OPC Server. Then save it in your desired directory. In this example, we suppose that you have export OPC tag names into "C:\tagName.csv". Youcan use property page of COPC32 to load CSV file as show in figure1

Figure 1

You can browse to your CSV file by click 'Browse' and then click 'Start Load' to load it.

 

Or use the following code to load CSV file

 

[VB, VB.NET]

Private Sub Form_Load()
copc1.loadCSV 1, 0, 5, ",", "C:\tagName.csv"
End Sub

Above code used to load tag name from 'tagName.csv' file located on "C:\tagName.csv". Start at row 1, column 0, get 5 rows from started row, use "," as delimited character. The content of 'tagName.csv' show below.

 

Item ID,Access Path,Data Type,Active
Channel_0_User_Defined.Ramp.RampXL3,"",Long,TRUE
Channel_0_User_Defined.Ramp.RampXL2,"",Long,TRUE
Channel_0_User_Defined.Ramp.RampXL1,"",Long,TRUE
Channel_0_User_Defined.Ramp.Ramp4,"",Long,TRUE
Channel_0_User_Defined.Ramp.Ramp3,"",Long,TRUE
Channel_0_User_Defined.Ramp.Ramp2,"",Long,TRUE
Channel_0_User_Defined.Ramp.Ramp1,"",Long,TRUE
Channel_0_User_Defined.Ramp.Ramp_Float,"",Float,TRUE

We export above tag name list from KEPware OPC Server using it's tool called 'OPC Quick Client'.
Then we get tag name from row 1 'Channel_0_User_Defined.Ramp.RampXL3' to row 5 'Channel_0_User_Defined.Ramp.Ramp3'.

 

[C#]

Following code example show you how to load OPC tag from CSV file, connect to OPC server and show OPC tag values in ListBox control. We don't forget to disconnect from OPC Server when user close form.

private void Form1_Load(object sender, EventArgs e)
{


short rwIndex, clIndex, rwCount;
string delimitChar, srcFile;
rwIndex = 1;
clIndex = 0;
rwCount = 5;
delimitChar = ",";
srcFile = @"C:\tagName.csv";
axcopc1.svrname = "KEPware.KEPServerEx.V4";
axcopc1.loadCSV(ref rwIndex, ref clIndex, ref rwCount, ref delimitChar, ref srcFile);

bool b = axcopc1.cnnec();

short i;

listBox1.Items.Clear();

try
{

for (i = 0; i < 4; i++)
{
string tmp = axcopc1.GetVl(ref i).ToString();
listBox1.Items.Add(tmp);
}


}
catch { }


}

 

private void axcopc1_datChange(object sender, EventArgs e)
{


listBox1.Items.Clear();

for (short i = 0; i < 4; i++)
{
string tmp = axcopc1.GetVl(ref i).ToString();
listBox1.Items.Add(tmp);
}


}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{


try
{
bool b = axcopc1.discnn();
}
catch { }


}