Programming - First steps
P.
68 of 349
Binary telegrams
Different
definition of telegrams
The functions
sendudp
and
readudp
can also be used to process binary data. In this case,
telegrams, the structure and data layout of which are specified, but which are not character strings,
are evaluated.
Therefore, we set ourselves the following problem, at which it must be taken into account that the
Enertex
®
EibPC itself receives only from its port 4806, and that its transmitting port is always 4807.
The Enertex
®
EibPC receives from port 4806 (port of the sender 5220, sender 192.168.22.22)
telegrams of the form:
Type1: Command 1000 until 1200: Arrangement of data in the telegram
Command (32 bit)
Number1 (Sign, 32 bit)
Floatingpoint number (32 bit)
Number1 (No sign 8 bit)
Type2: Command 2000 until 2200 : Arrangement of data in the telegram
Command (32 bit)
Floatingpoint number (32 bit)
Number1 (No sign 8 bit)
–
If command has a value of 1000, the result of the sum of the two numbers shall be
sent on the same communication channel. The reply message has the same structure, and the
result shall be sent at the position of the of number1. Command of the response amounts to
1100.
–
If command has a value of 1001, the difference of the two numbers shall be sent on
the same communication channel as a floating point number. The reply message has the
same structure, and the result shall be sent at the position of the of floating point number.
Command of the response amounts to 1101.
–
If command has a value of 2000, the root of floating point numbers shall be
calculated and sent back with command 2001. If the floating-point number is less than zero,
the integer of the telegram will be set to 1, otherwise to 0 .
Now, the program is written simply: You will notice that here the nesting of if statements is also
avoided (see page 51).
The two variables Command1 and Command2 realize the definition of the reading functions by
readudp
(processing of arguments of Type1 and Type2).
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - mail@enertex.de