Preface
IEC61499 is a functional block standard for distributed control systems. Information is exchanged between multiple devices and other external devices. This information exchange is realized through communication function blocks. The communication function block includes:
One-way communication function block: Publish/Subscribe
Two-way communication function block: Client/Server
The message between the devices is the data of the function block ( IEC61499-FBDATA ), which is composed of type and value. The communication function block may involve the input and output of multiple data. Each input and output data can be a simple single-valued data type or an array type (Constructed). So they have to exchange multiple data. The information abstract identification of multiple data uses the ASN.1 encoding and decoding method.
ASN.1
Abstract Syntax Notation ASN.1 (Abstract Syntax Notation One) is an international standard the I SO 8825-1. Use a compact way to abstractly identify data inside the computer, such as integer numbers, Boolean numbers, floating point numbers, and so on. It is precisely because ASN.1 is a universal language that the description syntax is adopted. It feels very complicated at first. In the IEC61499 standard, only the basic coding rules in ISO8825-1 are adopted. And further specifications and descriptions are made in Appendix E Information Exchange of IEC61499-1. It is clearer to combine learning.
ASN.1 basic encoding rules
The encoding of a data value consists of four parts
Identify octets (identifier octets)
Length octets
Content octets
End of content octets
The end-of-content octet can be defaulted. So in most cases, it is a three-segment logo
| identifier octets | length octets | contents octets |
Sometimes called TLV triples <Type, Length, Value>
Definition of identifier
The eighth and seventh place represents the class of tag
In Appendix E of IEC61499-1, the ASN.1 encoding rules of FBDATA are further standardized
The class of -tag is Application. All 8, 7 are 0, 1
-Tag number of basic data types
BOOL0 0
BOOL1 1
SAINT 2
INT 3
DINT 4
LINT 5
UINT 6
USINT 7
UDINT 8
ULINT 9
REAL 10
LREAL 11
TIME 12
DATE 13
TIME_OF_DAY 14
DATE_AND_TIME 15
STRING 16
BYTE 17
WORD 18
DWORD 19
LWORD 20
WSTRING 21
Array
ArrayVariable 22
ASN.1 encoding of IEC61499 FBDATA
(IEC61499-1 Appendix E) says there can be two types:
-Basic (BASIC) coding
Comply with the basic coding rules of ISO/IEC 8825-1
-Compact ( COMPACT ) coding
ComPACT encoding is used in 4DIAC.
For the above data types, length (length octets) is omitted, and the length of different data types is the default.
Simple type data encoding
Using compact coding, multiple data are arranged consecutively.
For example 4 INT
tag=01000011=0x43 where class=01, P/Construct=0, tag number=3=00011
Final code
0x43 0x00,0x00, 0x43 0x00,0x00, 0x43 0x00,0x00, 0x43 0x00,0x00
Array type encoding
-tag No. 6 is 1 Constructed
-length is encoded as UINT, a 16-bit unsigned number
-The first element of the array has a tag (COMPACT Encoding), and the following elements default to the tag
For example, the encoding of LREAL[2] is
tag = 0x76=011 10110 where
class=01,P/Constructed =1 ,tag number=22=10110
length=x0002
contents=8 octetX2
The tag of the first element (LREAL) is
tag=01001011=0x4b where class =01 /Construct=0,tag number=11=0x0b=01011
0x4b is the LREAL type. Two LREALs follow, each with 64 bits and 8 bytes).
The final code is
0x76,0x00,0x02,0x4b,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00
Program example
Using this simple software, you can display the ASN.1 coded FBDATA sent by the Client function block
package main
import (
"fmt"
"net"
"os"
)
func main() {
arguments := os.Args
if len(arguments) == 1 {
fmt.Println("Please provide a port number!")
return
}
PORT := ":" + arguments[1]
s, err := net.ResolveUDPAddr("udp4", PORT)
if err != nil {
fmt.Println(err)
return
}
connection, err := net.ListenUDP("udp4", s)
if err != nil {
fmt.Println(err)
return
}
defer connection.Close()
buffer := make([]byte, 1024)
serveraddr, _ := net.ResolveUDPAddr("udp", "192.168.31.108:8881")
client, _ := net.DialUDP("udp4", nil, serveraddr)
for {
// n, addr, err := connection.ReadFromUDP(buffer)
n, _, _ := connection.ReadFromUDP(buffer)
txbuf := make([]byte, n)
for i:=0;i<n;i++ {
fmt.Printf("0x%02x ",buffer[i])
txbuf[i]=buffer[i]
}
fmt.Printf("length=%d\n",n)
_, err := client.Write(txbuf)
if err != nil {
fmt.Println(err)
return
}
}
}
Believe that I explained clearly the FBDATA ASN.1 codec of IEC61499 standard. Did not introduce the abstract concept of ASN.1 in a big way. Of course, in order to write these clearly, I also made a small amount of money and downloaded the ISO8825-1 2008 version of the standard.
It’s very important to write a blog in depth.