Step 7 STL Array Loop

preacher.ca

Lifetime Supporting Member
Join Date
Jan 2014
Location
Regina
Posts
22
Good day.

I have a device on profibus that I am reading data from using SFC14. This data is written into an array within a DB. The array is 128 bytes in size. The formatting of each byte is not useful to me on its own as it is in hexadecimal. I have to do a bitwise swap to each byte and move it to another array formatted as INTs. I show both arrays in a VAT, one display format as "character" and the other as "DEC". Yes, the device sends alphanumeric values, but I only care for the numeric part of the data sent.

Example 1:
Device sends a byte as hex "32". PLC reads "32". In the VAT for array 1 shows "2". Array 2 will show "2".

Example 2:
Device sends a byte as hex "41". PLC reads "41". In the VAT for array 1 shows "A". Array 2 will show "2".

Good so far?

My question is more so for efficiency. Instead of copy and pasting 128 bitwise swaps, how can a loop be created to go through the array? I have google'd numerous combinations of Step 7 array loops to either say use "SCL" (which I have not used or am familiar with) or the examples did not seem to relate to what I am doing.

In my head I would think something similar to a do-while. While array does not equal 128, do bitwise swap for array1[0] and write to array2[0] and then increment the counter.

Any ways, if any one has a thought, I would appreciate the schooling. Or if you have a better way, feel free to throw that at me as well. The logic I have does work... it is just tedious to set up or modify...🤾

Additional info:
-Siemens S7-417.
-Step 7 v5.5 + SP4 + HF11.
-Device is Anybus Profibus M30.
 
Good day.

Step 7 array loops to either say use "SCL" (which I have not used or am familiar with) or the examples did not seem to relate to what I am doing.


But do you have it? It will be easier to learn this if you have it - if not then you have no choice.
 
Good day.

I have a device on profibus that I am reading data from using SFC14. This data is written into an array within a DB. The array is 128 bytes in size. The formatting of each byte is not useful to me on its own as it is in hexadecimal. I have to do a bitwise swap to each byte and move it to another array formatted as INTs. I show both arrays in a VAT, one display format as "character" and the other as "DEC". Yes, the device sends alphanumeric values, but I only care for the numeric part of the data sent.

Example 1:
Device sends a byte as hex "32". PLC reads "32". In the VAT for array 1 shows "2". Array 2 will show "2".

Example 2:
Device sends a byte as hex "41". PLC reads "41". In the VAT for array 1 shows "A". Array 2 will show "2".

Good so far?


No. How do you get a numeric 2 from both hex 32 and hex 41?
Post your processing for one element of the arrays.
 
Here's some SCL code to do the loop. I would put the processing for converting the byte to int in a separate function. Using this method will make the STL implementation much easier to understand.



Code:
FUNCTION FC88 : VOID
VAR_TEMP
i:INT;
END_VAR
FOR i:=1 TO 128 DO
 db3_IntArray.aiData[i]:=fc77_BitSwap(byData:=db2_ByteArray.abyData[i]);    
END_FOR;
END_FUNCTION
 
Here's the STL version.


Code:
FUNCTION "fc66_STLLoop" : VOID
TITLE =
VERSION : 0.1


VAR_TEMP
  iX : INT ;    
  iByteArrayStart : INT ;    
  dwByteStartPtr : DWORD ;    
  iIntArrayStart : INT ;    
  dwIntStartPtr : DWORD ;    
  byCurrentByte : BYTE ;    
  iCurrentInt : INT ;    
END_VAR
BEGIN
NETWORK
TITLE =

//stl  implementation of the following SCL code
//FUNCTION FC88 : VOID
//VAR_TEMP
//i:INT;
//END_VAR
//FOR i:=1 TO 128 DO
// db3_IntArray.aiData[i]:=fc77_BitSwap(byData:=db2_ByteArray.abyData[i]);    
//END_FOR;
//END_FUNCTION

//start byte for array of bytes
      L     20; 
      T     #iByteArrayStart; 
      SLD   3; 
      T     #dwByteStartPtr; 

//start byte for array of ints
      L     100; 
      T     #iIntArrayStart; 
      SLD   3; 
      T     #dwIntStartPtr; 

//for loop (done in reverse order)

      L     128; 
for:  T     #iX; 
      +     -1; //array is 1 based
      OPN   "db2_ByteArray"; 
      SLD   3; //convert to pointer format
      L     #dwByteStartPtr; 
      +D    ; 
      LAR1  ; 
      L     DBB [AR1,P#0.0]; 
      T     #byCurrentByte; 
      CALL "fc77_BitSwap" (
           byData                   := #byCurrentByte,
           RET_VAL                  := #iCurrentInt);

      OPN   "db3_IntArray"; 
      L     #iX; 
      +     -1; //array is one based
      SLD   4; //convert to pointer format
      L     #dwIntStartPtr; 
      +D    ; 
      LAR1  ; 
      L     #iCurrentInt; 
      T     DBW [AR1,P#0.0]; 
      L     #iX; 
      LOOP  for; 



END_FUNCTION
 
Replies in order:
L D[AR2,P#0.0]:
But do you have it?
I went to Help-->About--> display installed software and I see "S7-SCL Professional 2010 SR4", so I guess I do have it. As I mentioned, I have never used it so a good day to learn.

L D[AR2,P#0.0]:
Post your processing for one element of the arrays.
Ah yes, I apologize. I did not mean bitwise swap. I meant I do an "And Word" comparison so that I only keep the right four bits.

So when "41" is sent as a byte, in binary it is "0100 0001". Then I "AW" to 2#1111 and I am left with "0000 0001" or "1" (not 2, another typing error). But as I mentioned, I am not interested in the alphabet values.

L #inputByte
L 2#1111
AW
T #outputValue

L D[AR2,P#0.0]:
Here's some SCL code to do the loop
Thank you. Obviously I will need to adjust this for an And comparison, not a bitwise swap.

Here's the STL version
Yes, I see what you mean using SCL vs STL. I will give it a go on the test bench and let you know how it worked out.

Geoff White:
Can't you configure the Anybus to byte swap the data?
This was my fault in wording. I did not mean bitwise swap. Also, the AnyBus M30 module comes from a vendor with their own "GSD" file attached. I have asked the vendor for example logic, but at this time they have not replied.


Much appreciated for the assistance. To provide some further information regarding this, the device that was provided to us will send me temperature. Initially I was expecting a single int value for temperature. Instead, it will send me 6 bytes. Each byte represents a single value of the whole temperature. ABCD.Y or byte 1 = A, byte 2 = B, byte 3 = C, byte 4 = D, byte 5 = . and byte 6 = Y. So after I convert each byte to an int, because I know A is in the thousands, I multiply it by 1000. I move on to byte 2 and multiply by 100 and then add it to the first int. I do this for each value until I am left with a single dint, which then I can use for further processing.
 

Similar Topics

Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
660
I really struggle with STL in Siemens Step 7 Classic. I'll learn chunks, but then I don't use it enough to retain and build on the knowledge. When...
Replies
17
Views
3,207
Hi all, I have been asked to make some modifications to a Siemens S7-300 which is programmed entirely in STL and commented entirely in Italian...
Replies
10
Views
3,616
Hello everyone! I've just stared with programming on STL and I have problem which I can't understand. I'm writing programs on Step 7 and I'm...
Replies
2
Views
2,174
Hello everyone! I've just stared with programming on STL and I have problem which I can't understand. I have this piece of code:
Replies
1
Views
1,936
Back
Top Bottom