Interpret S7 Diagnostic Buffer

This:

Code:
t_idatafirstbyte := (WORD_TO_[B]INT[/B](t_pdata.ByteAddressLSB) / 8);

to:


Code:
t_idatafirstbyte := (WORD_TO_[B]DINT[/B](t_pdata.ByteAddressLSB) / 8);
 
Thanks Mate,

I need to add yet another conversion because my assigned variable is an integer.

Code:
    t_idatafirstbyte := DINT_TO_INT((WORD_TO_DINT(t_pdata.ByteAddressLSB) / 8));  //Correct conversion    
    t_iasciifirstbyte := DINT_TO_INT((WORD_TO_DINT(t_pascii.ByteAddressLSB) / 8)); //Correct Conversion

Thanks
JD

SCL_Double_Division.jpg
 
You could also do mask & shr on dword containing base pointer. This is straight from head, but im sure u get the picture:

Code:
t_iasciifirstbyte := DWORD_TO_INT(SHR(IN:=(t_pascii.BasePointer AND DW#16#00FFFFFF), N:=3));
SHR is shift bits right. If shifted 3 bits right, then its same as division by 8 but is more effective instruction and there is no room for overflow. If you change :

Code:
    t_pascii AT t_aascii: STRUCT
         type1: BYTE;  //0x10
         type2: BYTE;  //0s00..0x1D: NIL, BOOL, .. TIMER
         count: INT;   //number of elements
         dbno:  WORD;   //DB number
         [COLOR=Red]BasePointer : DWORD;[/COLOR]
END_STRUCT;


Then you can remove memory area with mask.

Code:
t_pascii.BasePointer [COLOR=Red]AND DW#16#00FFFFFF[/COLOR]
In the end, do what ever works for you.
 
Last edited:
Here's the SCL source I used:

Code:
FUNCTION FC71:void
VAR_IN_OUT
    LOG_ENTRY : ANY;
    ASCII_DATA : ANY;
END_VAR
 
VAR_TEMP
    t_adata : ANY;        
    t_pdata AT t_adata: STRUCT
         type1: BYTE;  //0x10
         type2: BYTE;  //0s00..0x1D: NIL, BOOL, .. TIMER
         count: INT;   //number of elements
         dbno:  WORD;   //DB number
         MemoryArea     : BYTE;         // Specified memory area = 0x84 = data block   
         ByteAddressMSB : BYTE;         // Byte address most significant bits   
         ByteAddressLSB : WORD;         // Byte address least significant bits   
         END_STRUCT;
    t_aascii : ANY;        
    t_pascii AT t_aascii: STRUCT
         type1: BYTE;  //0x10
         type2: BYTE;  //0s00..0x1D: NIL, BOOL, .. TIMER
         count: INT;   //number of elements
         dbno:  WORD;   //DB number
         MemoryArea     : BYTE;         // Specified memory area = 0x84 = data block   
         ByteAddressMSB : BYTE;         // Byte address most significant bits   
         ByteAddressLSB : WORD;         // Byte address least significant bits   
         END_STRUCT;
     t_pLDascii AT t_aascii: STRUCT
         type1: BYTE;  //0x10
         type2: BYTE;  //0s00..0x1D: NIL, BOOL, .. TIMER
         count: INT;   //number of elements
         dbno:  WORD;   //DB number
         dwAreaPointer     : DWORD;         // Specified memory area = 0x84 = data block     
         END_STRUCT;

    t_ientry_LEN    :   INT;
    t_ientry_type : INT;
    t_idx : INT;
    t_idatabyte : INT;
    t_iasciibyte : INT;

    t_sascii: STRUCT
        t_Padding:INT;
        t_iasciifirstbyte:INT;
        END_STRUCT;    
    t_dwasciiAddress AT t_sascii: DWORD;
    t_idatafirstbyte : INT;
    t_idatalastbyte : INT;
    t_iasciilastbyte : INT;
    t_bdata : BYTE;
    t_bchar : BYTE;
    t_itmp          :   INT;
    t_ivalue        :   INT;


END_VAR  
 
BEGIN
    t_adata := LOG_ENTRY;
    t_aascii := ASCII_DATA;
    t_dwasciiAddress:= 
    SHR(IN:=(t_pLDascii.dwAreaPointer AND dw#16#007ffff),
        N:=3); 
//Test assignment for byte address
    t_itmp:= t_sascii.t_iasciifirstbyte;

end_function
 
It was unclear why you used dw#16#007ffff instead of dw#16#00fffff. Then I found the ANY definition (below) but both would work because of the 5th bit of the 7th byte is a zero in a ANY.

ANY_Data_Type.jpg
 

Similar Topics

Hi all, Trying to remotely diagnose a machine with a 1769-L16ER-BB1B Compact Logix. When I connected I found it had a major fault, power up...
Replies
4
Views
3,591
I'm looking for a way to use the Audit Value for the controller to detect changes made programmatically. This link lays it out pretty cleary (page...
Replies
7
Views
2,712
Kind of a newbie to factorytalk view, and recently have been trial and error converting an old RSView 32 project into Factorytalk view SE. I have...
Replies
0
Views
3,559
How do you track Interpret Area Errors? More than a few people working on the app and I can't find what is filling the log over and over many...
Replies
17
Views
10,674
Hi, All. Could you please explain what is gonna happen in following STL Programming? A #FEHLER R #FEHLER L #Adresse...
Replies
6
Views
1,973
Back
Top Bottom