- Beiträge
- 8.300
- Reaktionspunkte
- 1.888
-> Hier kostenlos registrieren
Jetzt glaube ich das ich habe es verstanden.
Es gibt viele Wege nach Rom. Hier ist ein Beispiel mit ein Global-DB:
(warnung: nicht getestet)
Es gibt viele Wege nach Rom. Hier ist ein Beispiel mit ein Global-DB:
(warnung: nicht getestet)
Code:
TYPE UDT_dataset_pro_byte
STRUCT
bi0, bi1, bi2, bi3, b4, b5, bi6, b7 : BOOL ;
by0, by2 : BYTE ; // warum 2 bytes ?
in0 : INT ; // byte-wert interpretiert als INT ?
END_STRUCT
END_TYPE
DATA_BLOCK PLC_data
STRUCT
vals : ARRAY[0..99] OF UDT_dataset_pro_byte ; // es soll einfach gross genug sein !
END_STRUCT
BEGIN
END_DATA_BLOCK
FUNCTION Copy_via_db : VOID
VAR_input
structStartAddress : INT ;
iInputStartByte : INT ;
iOutputStartByte : INT ;
iNoOfBytes : INT ;
END_VAR
VAR_TEMP
structCurrentAddress : INT ;
iInputCurrentByte : INT ;
iOutputCurrentByte : INT ;
iCurrentByteNo : INT ;
tempBYTE : BYTE ;
tempINT : INT ;
END_VAR
FOR iCurrentByteNo := 1 TO iNoOfBytes BY 1 DO
iInputCurrentByte := iInputStartByte + iCurrentByteNo - 1 ;
iOutputCurrentByte := iOutputStartByte + iCurrentByteNo - 1 ;
structCurrentAddress := structStartAddress + iCurrentByteNo - 1 ; // Zufällig zählt Struct nummer und E/A Bytenummer gleich.
tempBYTE := IB[iInputCurrentByte] ;
PLC_data.vals[structCurrentAddress].by0 := tempBYTE ; // tu etwas mit der DB abhängig von die Eingänge
tempINT := BYTE_TO_INT(tempBYTE) ;
PLC_data.vals[structCurrentAddress].in0 := tempINT ; // tu etwas mehr
IF tempInt > 0 THEN // tu etwas mit die Ausgänge abhängig von der DB wert.
QB[iOutputCurrentByte] := PLC_data.vals[structCurrentAddress].by0 ;
END_IF ;
END_FOR ;
END_FUNCTION
FUNCTION Sample_Call : VOID
Copy_via_db(structStartAddress := 0
,iInputStartByte := 2
,iOutputStartByte := 2
,iNoOfBytes := 6
);
Copy_via_db(structStartAddress := 10
,iInputStartByte := 12
,iOutputStartByte := 14
,iNoOfBytes := 4
);
END_FUNCTION