Opcclient: Difference between revisions

From Eigenvector Research Documentation Wiki
Jump to navigation Jump to search
imported>Donal
(Created page with "===Purpose=== Creates an opcclient object which allows access to OPC servers. ===Synopsis=== :code here ===Description=== The opcclient object allows the Matlab user to c...")
 
imported>Donal
 
(10 intermediate revisions by the same user not shown)
Line 5: Line 5:
===Synopsis===
===Synopsis===


:code here
:client = opcclient(1);  % create OPC client, with client id=1.


===Description===
===Description===
Line 11: Line 11:
The opcclient object allows the Matlab user to connect to an OPC DA server and read item values from or write item values to the server. Opcclient is available in PLS_Toolbox Version 7.3 and later and provides access to OPC servers supporting OPC Data Access standard v2.05a.
The opcclient object allows the Matlab user to connect to an OPC DA server and read item values from or write item values to the server. Opcclient is available in PLS_Toolbox Version 7.3 and later and provides access to OPC servers supporting OPC Data Access standard v2.05a.


Simple example of accessing item values on an OPC server on the same machine as the opcclient
The code example below shows how to interact with an OPC server running on the local computer. There are some prerequisite steps to take before running the example code:
System Set-up
System Set-up
1. Start an OPC server on your computer. Free demo OPC servers are available from Matrikon or Graybox, and others..
1. Start an OPC server on the local computer. Free demo OPC servers are available from Matrikon or Graybox, and others..
2. Ensure computer is configured for DCOM communication. See, for example, http://www.opssys.com/InstantKB/article.aspx?id=10834, or http://cache.automation.siemens.com/dnl/zY/zYwMjc3AAAA_31198863_FAQ/OPC_via_DCOM_e.pdf
3. Create a user with admin privileges, for example, "testuser", with example password "test", or use any user with admin privileges and with an account password.
It may be necessary to cycle the Windows firewall off and back on after performing steps 2 and 3.
4. Find your computer's IP address. Get it from the "IPv4 address" entry in the results from the "ipconfig" command.


2. Ensure computer is configured for DCOM communication. See, for example, [http://www.opssys.com/InstantKB/article.aspx?id=10834], or [http://cache.automation.siemens.com/dnl/zY/zYwMjc3AAAA_31198863_FAQ/OPC_via_DCOM_e.pdf].


3. Create a user with admin privileges, for example, "testuser", with example password "test", or use any user with admin privileges and with an account password. It may be necessary to cycle the Windows firewall off and back on after performing steps 2 and 3.


Notes:
4. Find the computer's IP address. This can be obtained from the "IPv4 address" entry in the results from the "ipconfig" command.
1. You need to know the Program ID of the OPC server you want to connect with. The Program ID is a human readable form of the server's COM
unique identification, its Globally Unique Identifier (GUID). Graybox's progID is 'Graybox.Simulator'.
2. You will need to know the names of any items you want to access on the server.
Item names (or tags) are usually in a hierarchical namespace specific to a server. Matrikon example: Bucket Brigade.ArrayOfReal8, Graybox example: numeric.saw.float.


Details:
=====Notes=====
Opcclient is implemented using the Java-based openscada.org Utgard package. OPC DA communication is based on the Windows COM protocol.
1. It is necessary to know the Program ID of the OPC server you want to connect with. The Program ID is a human readable form of the server's COM unique identification, its "Globally Unique Identifier" (GUID). Graybox's progID is 'Graybox.Simulator'.


Simplifications
2. The names of any items to be accessed on the server must be known. Item names (or tags) are usually in a hierarchical namespace specific to a server. Matrikon example: Bucket Brigade.ArrayOfReal8, Graybox example: numeric.saw.float.
1. Uses default group only.
2. Item types on Matlab side are simply doubles, rather than mapping to int8, int32, float32, double
3. Only tested on local computer which is protected by firewall. Security issues would exist if the OPC server
is on a remote computer because of sending user login and password info to the OPC server computer


3. Opcclient is implemented using the Java-based openscada.org Utgard package. OPC DA communication is based on the Windows COM protocol.


====Inputs====
=====Simplifications=====
* '''first''' = first input is this.
Some simplifications have been made to the full OPC DA communication. Opcclient makes the following simplifications to user access:
 
1. Uses a default group only. The user cannot specify groups.


====Optional Inputs====
2. Items read from the OPC server into Matlab are of type double, rather than mapped to specific types for int8, int32, float32, double.
* '''second''' = optional second input is this.


====Outputs====
3. Opcclient has only been tested communicating with an OPC server located on the local computer which is protected by firewall. Security issues arise if the OPC server is on a remote computer because of sending user login and password info to the OPC server computer.
* '''firstout''' = first output is this.


===Options===
4. A more complete package supporting OPC communications is available from the Mathworks in their OPC Toolbox ([http://www.mathworks.com/products/opc/index.html]).


options = a structure array with the following fields:
====Inputs====
* '''id''' = Integer ID for this client.


* '''plots''': [ {'none'} | 'final' ] governs plotting of results, and
====Outputs====
* '''order''': positive integer for polynomial order {default = 1}.
* '''client''' = opcclient object.


===Example===
===Example===


<pre>
<pre>
Line 65: Line 56:


% Reading a single item
% Reading a single item
%Read the specified OPC item. The function returns a (value, quality, timestamp) tuple. If the call fails, the quality will be set to 'Error'.
% Read the specified OPC item. The function returns a structure with fields: value, quality, timestamp and errorcode.
% If the call fails, the quality will be set to a value other than 192 (Good).
itemname  = 'Bucket Brigade.Int4';        % This server item tag, is read/write
itemname  = 'Bucket Brigade.Int4';        % This server item tag, is read/write
[value timestamp quality] = client.read(itemname);
iteminfo  = client.read(itemname);
value      = iteminfo.itemvalue;
timestamp  = iteminfo.itemtimestamp;
quality    = iteminfo.itemquality;
errorcode  = iteminfo.itemerrorcode;


% Writing a single item
% Writing a single item
Line 74: Line 70:


% And read its value back
% And read its value back
[value timestamp quality] = client.read(itemname);
iteminfo  = client.read(itemname);
value      = iteminfo.itemvalue;
timestamp  = iteminfo.itemtimestamp;
quality    = iteminfo.itemquality;
errorcode  = iteminfo.itemerrorcode;


% Writing an array item
% Writing an array item
itemname = 'Random.ArrayOfReal8';
itemname = 'Bucket Brigade.ArrayOfReal8';
newvalue = rand(6,1)*10;
newvalue = rand(6,1)*10;
res = client.write(itemname, newvalue);
res = client.write(itemname, newvalue);


% And read its value back
% And read its value back
[value timestamp quality] = client.read(itemname);
iteminfo  = client.read(itemname);
value      = iteminfo.itemvalue;
timestamp  = iteminfo.itemtimestamp;
quality    = iteminfo.itemquality;
errorcode  = iteminfo.itemerrorcode;
 
% Close connection
client.disconnect;
</pre>
</pre>


===See Also===
===See Also===
[[baselinew]], [[deresolv]]

Latest revision as of 16:31, 7 August 2013

Purpose

Creates an opcclient object which allows access to OPC servers.

Synopsis

client = opcclient(1);  % create OPC client, with client id=1.

Description

The opcclient object allows the Matlab user to connect to an OPC DA server and read item values from or write item values to the server. Opcclient is available in PLS_Toolbox Version 7.3 and later and provides access to OPC servers supporting OPC Data Access standard v2.05a.

The code example below shows how to interact with an OPC server running on the local computer. There are some prerequisite steps to take before running the example code: System Set-up 1. Start an OPC server on the local computer. Free demo OPC servers are available from Matrikon or Graybox, and others..

2. Ensure computer is configured for DCOM communication. See, for example, [1], or [2].

3. Create a user with admin privileges, for example, "testuser", with example password "test", or use any user with admin privileges and with an account password. It may be necessary to cycle the Windows firewall off and back on after performing steps 2 and 3.

4. Find the computer's IP address. This can be obtained from the "IPv4 address" entry in the results from the "ipconfig" command.

Notes

1. It is necessary to know the Program ID of the OPC server you want to connect with. The Program ID is a human readable form of the server's COM unique identification, its "Globally Unique Identifier" (GUID). Graybox's progID is 'Graybox.Simulator'.

2. The names of any items to be accessed on the server must be known. Item names (or tags) are usually in a hierarchical namespace specific to a server. Matrikon example: Bucket Brigade.ArrayOfReal8, Graybox example: numeric.saw.float.

3. Opcclient is implemented using the Java-based openscada.org Utgard package. OPC DA communication is based on the Windows COM protocol.

Simplifications

Some simplifications have been made to the full OPC DA communication. Opcclient makes the following simplifications to user access:

1. Uses a default group only. The user cannot specify groups.

2. Items read from the OPC server into Matlab are of type double, rather than mapped to specific types for int8, int32, float32, double.

3. Opcclient has only been tested communicating with an OPC server located on the local computer which is protected by firewall. Security issues arise if the OPC server is on a remote computer because of sending user login and password info to the OPC server computer.

4. A more complete package supporting OPC communications is available from the Mathworks in their OPC Toolbox ([3]).

Inputs

  • id = Integer ID for this client.

Outputs

  • client = opcclient object.

Example

% Create client instance
client = opcclient(1);

% Connect to OPC Server
% client.connect(IPaddress, domain, username, password, OPC_server_progID);
client.connect('10.0.2.15', 'localhost', 'testuser', 'test', 'Matrikon.OPC.Simulation');

% Reading a single item
% Read the specified OPC item. The function returns a structure with fields: value, quality, timestamp and errorcode.
% If the call fails, the quality will be set to a value other than 192 (Good).
itemname   = 'Bucket Brigade.Int4';         % This server item tag, is read/write
iteminfo   = client.read(itemname);
value      = iteminfo.itemvalue;
timestamp  = iteminfo.itemtimestamp;
quality    = iteminfo.itemquality;
errorcode  = iteminfo.itemerrorcode;

% Writing a single item
newvalue = 23;
res = client.write(itemname, newvalue);

% And read its value back
iteminfo   = client.read(itemname);
value      = iteminfo.itemvalue;
timestamp  = iteminfo.itemtimestamp;
quality    = iteminfo.itemquality;
errorcode  = iteminfo.itemerrorcode;

% Writing an array item
itemname = 'Bucket Brigade.ArrayOfReal8';
newvalue = rand(6,1)*10;
res = client.write(itemname, newvalue);

% And read its value back
iteminfo   = client.read(itemname);
value      = iteminfo.itemvalue;
timestamp  = iteminfo.itemtimestamp;
quality    = iteminfo.itemquality;
errorcode  = iteminfo.itemerrorcode;

% Close connection
client.disconnect;

See Also