Herunterladen Inhalt Inhalt Diese Seite drucken

IFTOOLS MSB-RS485-PLUS Handbuch Seite 136

Inhaltsverzeichnis

Werbung

KAPITEL 13. DER PROTOKOLLMONITOR
Sie können die einzelnen Bytes eines Lua Srings mit string:byte(index)
erfragen. Diese Funktion arbeitet ähnlich der telegram:data(index) und
liefert das Byte an der angegebenen String Position. Eine Anzeige von Adres-
se und Funktion ist damit einfach zu realisieren:
1
box . t e x t { c a p t i o n =" Address " , t e x t = b i n d a t a : b y t e ( 1 ) , f g = f c , bg=bc }
2
box . t e x t { c a p t i o n =" Function " , t e x t = b i n d a t a : b y t e ( 2 ) , f g = f c , bg=bc }
Die Prüfsumme ist das letzte Byte in der Binärsequenz und es wäre schön die-
se in hexadezimaler Notation zu sehen. Dazu übergeben wir das Checksum
Byte der string format Funktion:
box . t e x t { c a p t i o n ="Chksum " ,
t e x t = s t r i n g . f o r m a t ("%02X " , b i n d a t a : b y t e ( 1) ) , f g = f c , bg=bc }
Wie bereits erwähnt unterscheidet unser Protokoll zwischen Anfragen (Re-
quests) und Antworten (Responses). Nur die Antwort Telegramme enthalten
ein zusätzliches Datenfeld mit einem 4-Byte umfassenden Fliesskommawert.
Antwort-Telegramme sind durch ihre Länge von 17 Byte (Originaltelegramm
in Base16 Kodierung) bzw. durch eine Binärsequenz von 7 Bytes (Adresse=1
Byte, Funktion=1 Byte, Daten=4 Bytes, Checksum=1 Byte) gekennzeichnet.
Um sie von einer Anfrage zu unterscheiden reicht eine Prüfung der Telegramm-
oder bindata Länge aus.
1
i f t g : s i z e ( ) == 17 then . . . end
2
i f # b i n d a t a == 7 then . . . end
Es macht keinen Unterschied welche davon Sie wählen. Da wir aber im weite-
ren Verlauf auf die bindata Sequenz zugreifen wählen wir die zweite Variante.
1
function o u t ( )
2
t e l e g r a m c o l o r s
3
l o c a l t e x t c o l o r s = { 0xFF0000 , 0x0000FF }
l o c a l b a c k c o l o r s = { 0xFFEEDD, 0xDDEEFF }
4
5
6
access t h e c u r r e n t t e l e g r a m
l o c a l t g = t e l e g r a m s . t h i s ( )
7
l o c a l b i n d a t a = base16 . decode ( t g : s t r i n g ( ) : sub ( 2 ,
8
9
10
s e l e c t t h e t e x t and background c o l o r depending on t h e data
source
11
l o c a l f c = t e x t c o l o r s [ t g : d i r ( ) ]
12
l o c a l bc = b a c k c o l o r s [ t g : d i r ( ) ]
13
14
d i s p l a y t i m e
15
box . t e x t { c a p t i o n =" Time " , t e x t = t g : t i m e ( ) , f g = f c , bg=bc }
16
17
s t a r t c o l o n
18
box . t e x t { c a p t i o n ="SOF" , t e x t = s t r i n g . char ( t g : data ( 1 ) ) , bg= f c ,
f g =bc }
19
20
t h e address f i e l d
21
box . t e x t { c a p t i o n =" Address " , t e x t = b i n d a t a : b y t e ( 1 ) , f g = f c , bg=bc }
22
23
t h e f u n c t i o n number f i e l d
24
box . t e x t { c a p t i o n =" Function " , t e x t = b i n d a t a : b y t e ( 2 ) , f g = f c , bg=bc }
25
26
i s i t a response?
27
i f # b i n d a t a >= 7 then
124
3 ) )

Werbung

Inhaltsverzeichnis
loading

Inhaltsverzeichnis