Canonical Data Types For OPC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Technical Note

Canonical Data Types for OPC


1. What are the Canonical Data Types
In the world of OPC, the client application can be created in on one of many diverse
programming languages. These programming languages can each refer to data types in
different ways. Many of the data types used in OPC may even be incorporated into only
one or two variable data types in the client. To resolve potential issues all OPC data
types are assigned a specific Canonical Data Type. When a client application adds an
OPC Item to an OPC Group it can use the default data type for the item or it can request
the item with a specific canonical data type.

2. When to Use Canonical Data Types


Typically you would only have to worry about this if you were creating your own OPC
client from VB for example. When adding OPC Items to our server you have the option
of using Static or Dynamic tags. Static tags are created in the server and would be
referenced using the Add Item function. Dynamic Tags are created by referencing valid
device address in the Add Item function. If you add theses Dynamic tags and you do not
specify a data type then KEPServerEX® will use the default data type for that address.
This is fine if you only need the default data type.
Note: Most Microsoft .Net Stacks/API’s use System Data Types for items rather
than requiring.

3. How to Use a Canonical Data Type in VB


If you are using the legacy OPC DA 2.0 Automation Wrapper in Visual Basic there are
two ways to add OPC items to a group.
 The AddItem() method – for adding one item at a time with its default data type.
 The AddItems() method – for adding one or more items at a time. The requested
data type is optional.
The following is a code snippet of the AddItems method:

ItemCollection.AddItems NumItems As Long, ItemIDs() As String, ClientHandles()


As Long, ServerHandles() As Long, Errors() As Long, [RequestedDataTypes() as
Integer], [AccessPaths() as String]

See Also: OPC Data Access Specification for details on these methods.

www.kepware.com 1 ©2004-2018 PTC, Inc. All Rights Reserved.


4. OPC Server Data Types and Canonical Type Code
The following table shows the Supported Data Types in KEPServerEX, the Canonical Data
Type associated with that data type, its size, and the data range for that data type.

Data Type Canonical Size Data Range


Type
Boolean 11 1 Bit True or False
Boolean Array 8203 1 Bit times Array Size True or False
Byte 17 1 Byte 0-255
Byte Array∗ 8209 1 Byte times Array Size 0-255
Short 2 2 bytes -32768 – 32767
Short Array∗ 8194 2 bytes times Array Size -32768 – 32767
BCD 18+ 2 bytes 0 - 9999
BCD Array∗ 8210 2 bytes times Array Size 0 - 9999
Word 18 2 bytes 0 – 65535
Word Array∗ 8210 2 bytes times Array Size 0 – 65535
Long 3 4 bytes -2,147,483,648 to 2,147,483,647
Long Array∗ 8195 4 bytes times Array Size -2,147,483,648 to 2,147,483,647
LBCD 19+ 4 bytes 0 - 99999999
LBCD Array∗ 8211 4 bytes times Array Size 0 - 99999999
DWord 19 4 bytes 0 – 4,294,967,295
DWord Array∗ 8211 4 bytes times Array Size 0 – 4,294,967,295
Float 4 4 bytes -(3.40 E38 – 1.40 E-45) to
(1.40 E-45 – 3.40 E38)
Float Array∗ 8196 4 bytes times Array Size -(3.40 E38 – 1.40 E-45) to
(1.40 E-45 – 3.40 E38)
Double 5 8 bytes -(1.798 E308 – 4.941 E-324) to
4.941 E-324 – 1.798 E308)
Double Array∗ 8197 8 bytes times Array Size -(1.798 E308 – 4.941 E-324) to
4.941 E-324 – 1.798 E308)
LLong 20 8 bytes -(2 E63) to (2 E63) -1
LLong Array 8212 8 bytes times Array Size -(2 E63) to (2 E63) -1
Qword 21 8 bytes 0 to (2 E64) -1
Qword Array 8213 8 bytes times Array Size 0 to (2 E64) -1
Char 16 1 Byte All Characters supported in the
standard ASCII table
String 8 1 – n Bytes All Characters supported in the
standard ASCII table

Note: Each driver supports different addresses and data types. Please check the
individual driver help file for the supported addresses and data types. All
help files will display the default address data type in bold letters.
∗ In KEPServerEX, the maximum size of an array is determined by the block size in the driver. So if the block
size is 100 bytes, a byte array can only have 100 bytes, a Word array of 50 words, and so on.

+ Because BCD and LBCD data types are not standard variable data types they are assigned the same
canonical data type as a Word or Long item, respectively. To have the server dynamically create an item
with this data type, append the data type to the end of the address. In the SimDemo project provided by
Kepware asking for an R register on Channel_1 and Device_1, device address R30; the item id would be
Channel_1.Device_1.R30@BCD. See the KEPServerEX help file for details.

www.kepware.com 2 ©2004-2018 PTC, Inc. All Rights Reserved.

You might also like