Difference between revisions of "OPCServer:Variable Syntax"

From IBHsoftec Wiki English
Jump to: navigation, search
(No difference)

Revision as of 07:54, 25 June 2012

Variable Syntax

One of the special features of the IBH OPC Server is to allow direct use of the absolute PLC Variables without declaration. It is also possible to use symbolic addressing as defined in the PLC program (Symbolic Table). Even variables used in S7 Data Blocks can be accessed via the IBH OPC Server with their symbolic names. These features eliminate the need of double declarations.


To do so, the PLC program is assigned with the IBH OPCEditor to the PLCName and the required variables are selected within the user interface.


Addressing of variables with absolute addresses in the IBH OPC Server is done by using the Simatic® Step®7 or Simatic® Step®5 syntax. Please note that REAL values (Double Word Format ) in S7 must be declared symbolic in order to have the correct format information. If this is not the case, the SCADA application must do the conversion of the "Long variable in the REAL format" into the correct "REAL format".


The IBH OPC Server supports 3 notations for variables.

  • Symbolic from the PLC project (Variables are selected via the IBH OPCEditor)
  • SIMATIC® S7 notation
  • SIMATIC® S5 notation


When using absolute addresses from the OPC client, also a mixed S5/S7 notation is possible.


The syntax is always PLCName.VariableName respectively PLCName.DataBlockName.StructureElement.VariableName. A Variable must always begin with the PLCName. If the variables have been selected individually via the IBH OPCEditor, the variables can be conviniently browsed from the OPC client.


The configuration of the PLC itself must always be done via the IBH OPCEditor, regardless whether absolute or symbolic addressing is to be used. A shortcut to the IBH OPCEditor is installed on your PC.



Common Syntax for S5 and S7:

Operand Bereich Datentyp
En.n Inputbits (2) Bool (VT_BOOL)
EBn Inputbytes (1) Unsigned Byte (VT_UI1)
EWn Inputwords (1) Unsigned Word (VT_UI2)
EDn Inputdoublewords (1) Unsigned DWord (VT_UI4)
ETn[Stringlength] Text from the input area (3) Character Array (VT_BSTR)
An.n Outputbits (2) Bool (VT_BOOL)
ABn Outputbytes (1) Unsigned Byte (VT_UI1)
AWn Outputwords (1) Unsigned Word (VT_UI2)
ADn Outputdoublewords (1) Unsigned DWord (VT_UI4)
ATn[Stringlength] Text from the output area (3) Character Array (VT_BSTR)
Mn.n Flagbits (2) Bool (VT_BOOL)
MBn Flagbytes (1) Unsigned Byte (VT_UI1)
MWn Flagwords (1) Unsigned Word (VT_UI2)
MDn Flagdoublewords (1) Unsigned DWord (VT_UI4)
MTn[Stringlength] Text from the flag area (3) Character Array (VT_BSTR)

Syntax for S5:

Operand Bereich Datentyp
Dn.n,nr Databits, DB Bool (VT_BOOL)
DRn,nr Right Databyte, DB Unsigned Byte (VT_UI1)
DLn,nr Left Databyte, DB Unsigned Byte (VT_UI1)
DWn,nr Dataword, DB (1) Unsigned Word (VT_UI2)
DSn,nr Dataword, DB (1) Signed short Integer (VT_I2)
DDn,nr Datadoubleword, DB (1) Unsigned DWord (VT_UI4)
DVn,nr Datadoubleword, DB (1) Signed long integer (VT_I4)
DFn,nr Datadoubleword, DB (1) Float (VT_R4)
DTn,nr[Stringlength] Text from a datablock (3) Character Array (VT_BSTR)
DXn.n,nr Databits, DX Bool (VT_BOOL)
DXRn,nr Right Databyte, DX Unsigned Byte (VT_UI1)
DXLn,nr Left Databyte, DX Unsigned Byte (VT_UI1)
DXWn,nr Dataword, DX (1) Unsigned Word (VT_UI2)
DXSn,nr Dataword, DX (1) Signed short Integer (VT_I2)
DXDn,nr Datadoubleword, DX (1) Unsigned DWord (VT_UI4)
DXVn,nr Datadoubleword, DX (1) Signed long integer (VT_I4)
DXFn,nr Datadoubleword, DX (1) Float (VT_R4)
DXTn,nr[Stringlength] Text from a DX datablock (3) Character Array (VT_BSTR
Sn.n S-Flagbits (2) Bool (VT_BOOL)
SYn S-Flagbytes (1) Unsigned Byte (VT_UI1)
SWn S-Flagwords (1) Unsigned Word (VT_UI2)
SSn S-Flagwords (1) Signed short Integer (VT_I2)
SDn S-Flagdoublewords (1) Unsigned DWord (VT_UI4)
SVn S-Flagdoublewords (1) Signed long integer (VT_I4
SFn S-Flagdoublewords (1) Float (VT_R4)
STn[Stringlength] Text from the extended flag area (3) Character Array (VT_BSTR

Syntax for S7:

Operand Bereich Datentyp
DBn.DBXn.n DB, Databits (2) Bool (VT_BOOL)
DBn.DBBn DB, Databyte (1) Unsigned Byte (VT_UI1)
DBn.DBCn DB, Databyte (1) Signed Byte (VT_I1)
DBn.DBWn DB, Dataword (1) Unsigned Word (VT_UI2)
DBn.DBSn DB, Dataword (1) Signed Word (VT_I2)
DBn.DBDn DB, Datadoubleword (1) Unsigned DWord (VT_UI4)
DBn.DBVn DB, Datadoubleword (1) Signed DWord (VT_I4
DBn.DBRn DB, Real (1) Real (VT_R4)
DBn.DBLn DB, LongLong (64 Bit) (1) LONGLONG (VT_I8)
DBn.DBUn DB, ULongLong (64 Bit) (1) ULONGLONG (VT_UI8)
DBn.DBZn DB, S7 - DATE_AND_TIME (1) Date (VT_DATE)
DBn.DBTn[Stringlength] Text from a datablock (3) Character Array (VT_BSTR)


1) For these operands the suffix [Count] may be added to read/write arrays. Example: PLCName.DB10.DBB2[5] reads 5 bytes starting from DBB2. PLCName.MW4[7] reads 7 Words starting from the MW4.


2) For bit operands also the suffix [Count] may be added to read/write arrays. Arrays of boolean must always start with Bit 0 within the byte. Example: PLCName.DB10.DBX2.0[5] reads 5 Bits starting from DBX2.0. PLCName.M4.0[7] reads 7 Bits starting from M4.0. A variable like PLCName.M4.3[4] is not permitted. When writing boolean arrays, always the entire byte is written.


3) If strings are entered in absolute notation, there is no verification whether it is a declared string. In S7 PLCs, strings have 2 leading bytes with additional information regarding the string, the declared length and the current length. Since this information lacks in absolute notation, strings are treated as pure character arrays of the length entered in [Stringlength]. If in a write operation the text is shorter as the length enterd in [Stringlength], the rest is filled up with zeroes.


The 'signed' datatypes also exist for the S7. Normally, we assume that the type will be set via the configuration tool IBH OPCEditor.


Addressing the DB of a S7-200:

The syntax for the 200 equals the S7-300 syntax. To access a variable byte of the data block in S7-300 syntax you need to type: VB 2 (S7-200) = DB1.DBB2 (S7-300). The data block is always the DB1. A variable word VW 2 (S7-200) = DB1.DBW2 (S7-300). A variable doubleword VD 2 (S7-200) = DB1.DBD2 (S7-300).