scl fc and db with array of udt

Werner

Member
Join Date
Apr 2005
Location
IJsselstein
Posts
336
I'm trying to get started with SCL.

qOut1:=WORD_TO_INT(DB50.DW0);
qOut2:=WORD_TO_INT("DB Cascade order".DW0);
qOut3:=WORD_TO_INT("DB Cascade order".DW[iIndex]);

The first to outputs are working. The third does not work. What am I missing here?

I have several list in several db's. I need to perform calculations in these lists. For instance:

Motorspeed(1)=Motorspeed(2)+Delta(1)

Motorspeed is a db with an array of reals. And Delta is als a db with an array of reals.

I need to loop through this calculation in steps. So on cycle calculate motor 1 to 10, next cycle calculate motor 11 to 20. etc...

Can you guys give me some tips?
 
Is iIndex initialised ?

If so, then I am not sure what goes wrong, but I strongly advice you to program everything symbolically.

For example:
qOut3:=WORD_TO_INT("DB Cascade order".WordArray[iIndex]);
WordArray is then defined in the UDT.
 
Here's a quick example (just for syntax) showing an array of udts being accessed:

Code:
TYPE UDT111
  STRUCT
  ispeed:INT;
  iDelat:INT;
  END_STRUCT
END_TYPE
DATA_BLOCK DB111
  STRUCT
  Motor:ARRAY[1..10] OF udt111;
  END_STRUCT
BEGIN
END_DATA_BLOCK
FUNCTION FC111: INT
VAR_TEMP
  iMotorIndex:INT;
  iData:INT;
END_VAR
  FOR iMotorIndex:=1 TO 10 DO
	iData:=db111.Motor[iMotorIndex].ispeed;
  END_FOR;
FC111:=0;
END_FUNCTION
 
iIndex is defined as an input of the FC and is of the type INT.

My UDT has a structure like this:

Struct
Follows_item_nr INT
end struct

The DB is:

Item Array[1..50]
of udt53

So I have symbolic names like:

DB Cascade order.Item[3].follows_item_nr
 
Werner said:
Thanx L D[AR2,p#0.0]

I'll give it a try. It compiles ok, so I just need to modify it to use the symbolic names.

Its working now. I also created an FB in this way. Thank you for the information. What I am missing is how to add comments to the inputs / outputs of an FC or FB. Do you know how to do that?
 
If you mean the hint text that appears when you hover over the parameter name when you call the block, then the following works:

Code:
FUNCTION FC111: INT
VAR_INPUT
bInput1:BOOL; //Comment for input 1	
END_VAR
VAR_TEMP
  iMotorIndex:INT;
  iData:INT;
END_VAR
  FOR iMotorIndex:=1 TO 10 DO
	iData:=db111.Motor[iMotorIndex].ispeed;
  END_FOR;
FC111:=0;
END_FUNCTION
 
Great!! I can't believe that I could have worked without scl for so long. This will save a lot of time!

One other question: Debugging. I have inserted some break points, I set the operation mode to test operation. I have compiled the block again and downloaded it to the plc simulator. When I hit the monitor button I get the message: Cannot test block. Debug info was not generated. What does this mean and how can I solve this problem?
 

Similar Topics

Hello I wanna know if are some function to check what is the max value from an array or if I have to loop the array to compare all numbers to get...
Replies
4
Views
1,883
Hello, When you want compare values of an array to a range of numbers is it a right way to do that? FUNCTION ADD VAR_IN_OUT A:ARRAY[1..50]...
Replies
5
Views
2,063
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...
Replies
18
Views
5,835
Hi, I just can't wrap my head around this one so all ideas and comments are more than welcome. My SCL programming skills are beginner level. What...
Replies
3
Views
1,931
Hello I am writing a small code, I have two problems populating the arrays? I am getting an error Non-existing identifier. I also need help to...
Replies
12
Views
5,909
Back
Top Bottom