S7-1500 SCL - Move Individual REAL values into an Array

b16mcc

Member
Join Date
Jul 2006
Location
North West
Posts
20
Hi guys. I have a challenge that I'm struggling with and I can't help thinking there's a really easy solution.

I want to move a series of individual REAL values from existing DB locations into an array to be passed to a Modbus client. I don't need to get into modbus , I've got that covered.

I simply want to collate the data. I was thinking my best bet would be SCL. So that's where I started.

I have this very simple code, but of course it's not correct and this is where I'm hung up.

Code:
FOR #Counter := 1 TO 32 DO
#Input := CONCAT(IN1 := 'SourceData', IN2 := INT_TO_STRING(#Counter));
#Reg4000[#Counter] := #Input;
END_FOR;

So, you can see I tried making a temp string to address my inputs. My inputs are :-

SourceData1, SourceData 2 , etc etc , up to 32.

So you can see that on each pass of the loop the string #Input becomes 'SourceData1' , then 'SourceData2' and so on.

The output from the block is an array of REAL called Reg4000.

I have some VB coding experience , now this may be clouding my judgement somewhat here, but what I'm trying to achieve is what would be in VB ,

Code:
Reg4000[#counter]=#Input.value

Of course maybe my approach is flawed from the outset.

So my problem is simply, How can I loop through my inputs without them being an array.



Thanks for looking..

Martin.
 
Create a user datatype with an array of reals. In your tag table map call the user datatype with the correct start address of the inputs then you can access the inputs as an array and loop them


real.jpg


Another way is to use the PEEK instruction.
 
Something like this might also work. Could be a good alternative if you need to byteswap

Code:
#tAddress := 10; // Start at input 10

FOR #Counter := 1 TO 10 DO
    
    // No byteswap
    #Reg4000[#Counter] := DWORD_TO_REAL(PEEK_DWORD(area := 16#1, dbNumber := 0, byteOffset := #tAddress));
    
    // Byteswap
    //   #Reg4000[#Counter] :=  DWORD_TO_REAL(SWAP(PEEK_DWORD(area := 16#81, dbNumber := 0, byteOffset := #tAddress)));
    
    // 4 byte offset between each real
    #tAddress += 4;
END_FOR;
 
S7-1500 scl

Thanks for your suggestions. The problem is , the inputs are not consecutive, they may not even be in the same datablock.
 
Something like this might also work. Could be a good alternative if you need to byteswap

Code:
#tAddress := 10; // Start at input 10

FOR #Counter := 1 TO 10 DO
    
    // No byteswap
    #Reg4000[#Counter] := DWORD_TO_REAL(PEEK_DWORD(area := 16#1, dbNumber := 0, byteOffset := #tAddress));
    
    // Byteswap
    //   #Reg4000[#Counter] :=  DWORD_TO_REAL(SWAP(PEEK_DWORD(area := 16#81, dbNumber := 0, byteOffset := #tAddress)));
    
    // 4 byte offset between each real
    #tAddress += 4;
END_FOR;


This looks interesting, thanks. Can you explain what the area :- 16#81' is referring to please ?
 
Thanks for the info. I understand the theory now, but it's still not relevant as this assumes my data sources are concurrent addresses.
My data source addresses must be passed to the block as individuals and then packaged as an array, so the block call would look like this.

Capture.JPG
 
Thanks for the info. I understand the theory now, but it's still not relevant as this assumes my data sources are concurrent addresses.
My data source addresses must be passed to the block as individuals and then packaged as an array, so the block call would look like this.




Is there possible to make 32 inputs to 1 FC / FB block.


Inside block you need to copy individual inputs first to array, then you can use blk_move for copying.


You maybe also need variant data type, if you se fc inside fc block.


https://support.industry.siemens.co...d-data-in-step-7-(tia-portal)-?dti=0&lc=en-WW


https://cache.industry.siemens.com/...1318674_Programming_guideline_DOCU_v14_en.pdf
(page25)


https://support.industry.siemens.co...ssing-for-the-s7-1200-s7-1500-?dti=0&lc=en-WW



Anyway, on result you have same than easier with 32 seperate move blocks.

you can animate move blocks on networks, but for output array you need animation table)


p.s


Or maybe variant type as output on FC block, then inside FC move array to output.

But variant type was maybe only input and in/out allowed?
 
Last edited:
A working solution but not happy.

Ok so I have a working solution , but it still seems the long way around the problem.

I created an FC with the interface as shown in the attached image.

attachment.php


The code in the FC is as follows :-

Code:
 #TempArray[1] := #SourceData1;
    #TempArray[2] := #SourceData2;
    #TempArray[3] := #SourceData3;
    #TempArray[4] := #SourceData4;
    #TempArray[5] := #SourceData5;
    #TempArray[6] := #SourceData6;
    #TempArray[7] := #SourceData7;
    #TempArray[8] := #SourceData8;
    #TempArray[9] := #SourceData9;
    #TempArray[10] := #SourceData10;
    #TempArray[11] := #SourceData11;
    #TempArray[12] := #SourceData12;
    #TempArray[13] := #SourceData13;
    #TempArray[14] := #SourceData14;
    #TempArray[15] := #SourceData15;
    #TempArray[16] := #SourceData16;
    #TempArray[17] := #SourceData17;
    #TempArray[18] := #SourceData18;
    #TempArray[19] := #SourceData19;
    #TempArray[20] := #SourceData20;
    #TempArray[21] := #SourceData21;
    #TempArray[22] := #SourceData22;
    #TempArray[23] := #SourceData23;
    #TempArray[24] := #SourceData24;
    #TempArray[25] := #SourceData25;
    #TempArray[26] := #SourceData26;
    #TempArray[27] := #SourceData27;
    #TempArray[28] := #SourceData28;
    #TempArray[29] := #SourceData29;
    #TempArray[30] := #SourceData30;
    #TempArray[31] := #SourceData31;
    #TempArray[32] := #SourceData32;
    
    #Reg4000 := #TempArray;

The interface looks like this when called. You can see that the source data is not consecutive, hence I can't use an array for the input.

attachment.php


So to get back to the original problem. I was trying to create this by using a For Next loop and therefore the code would be 2 or 3 lines rather than 30+. However I could not come up with a method of addressing the SourceData inputs to the block.

Obviously it's very simple to address the array elements within a For Next loop, but not the Source Data 1 to 32 references.

I wonder if by posting this second best solution it might help you guys better understand what I'm trying to achieve. Am I missing something very simple here or not ?

Thanks everyone.

Interface.JPG Capture.JPG
 
If you use an FB (non-optimised) instead of an FC then you can indirectly address the input parameters in an STL for loop, e.g.

m4000.jpg
 
Thanks for the info. I see what your doing there.

I guess this is a good as it gets ??
I find it disappointing or even hard to believe that there's no way in SCL of manipulating symbolic addressing to be used with variables.
Maybe SCL will catch up with VB one day.
 

Similar Topics

Hi guys! Is there a document somewhere that states the difference between SCL in TIA portal versus SCL in classic Step7? I want to reuse some...
Replies
8
Views
3,135
Can we use a Simotion D455 ethernet port x127 as a gate, to access S7-1500 plc Tia Portal program ? In the Simatic manager, we used Netpro to do...
Replies
2
Views
87
I have been working on this for a while now and I can't seem to get it. I was finally able to view the 1500 on the PanelView under the serial...
Replies
1
Views
85
Hello, I have a 1764 1500 LSP Series A that keeps failing with DTL_E_FAIL I/O error. Searching around it seems there's a weird issue specifically...
Replies
2
Views
106
Hi all Trying to remotely connect to a TIA Portal PLC. I can ping it without a problem but can't get my software to connect. I've opened port...
Replies
8
Views
334
Back
Top Bottom