Indexed Access To Datablocks in SCL

Globe

Member
Join Date
Oct 2004
Posts
24
Hi,
I want to read out the cpu time and put the the time in arrays in different datablocks. I have wrote the code in SCL but when I compilate the code it generates error. My code looks like this:

IF READ_TIME THEN;
SFC_ERROR := READ_CLK(CDT := WORD_TO_BLOCK_DB(DB_NR_I).LOGTIME[LOGTIME_I]);
READ_TIME := FALSE;
END_IF;

DB_NR_I = Index for datablock, could be 101, 102, 103
LOGTIME = Is an array in datablock with the datatype DATE_AND_TIME
LOGTIME_I = Is index for array, 1-6

Can anyone se where the problem is or can I do this in some smarter way??

/Globe
 
Here's my implementation. I think the easiest method is to copy the time and date information into a temp area before copying it to the required data block. My code assumes the array of time and dates is at the start of the DB. The problem with your code is that the output parameter for the READ_CLK sfc is not valid.

Code:
FUNCTION_BLOCK FB333
VAR_INPUT
DB_NR_I:INT;
LOGTIME_I:INT;
	
END_VAR 
VAR_IN_OUT
READ_TIME:BOOL;	
END_VAR
VAR_TEMP
  // Temporary Variables
LOGTIME:DATE_AND_TIME;
LOGTIME_DW:DWORD;
LOGTIME_DI:DINT;
SFC_ERROR:INT;
Area:ANY;
View AT Area:STRUCT
	ID:BYTE;
	TYP:BYTE;
	NUM:INT;
	DBN:INT;
	PTR:DWORD;
	END_STRUCT;

END_VAR
VAR
  // Static Variables
END_VAR
IF READ_TIME THEN
SFC_ERROR := READ_CLK(CDT := LOGTIME);
//Copy data from local array to DB
View.ID:=16#10;
View.TYP:=16#02;
View.NUM:=8;
View.DBN:=DB_NR_I;
LOGTIME_DW:=16#84000000;
LOGTIME_DI:=DWORD_TO_DINT(LOGTIME_DW);
LOGTIME_DI:= LOGTIME_DI + (8 * 8 * (LOGTIME_I-1));
LOGTIME_DW:= DINT_TO_DWORD(LOGTIME_DI);
View.PTR:=LOGTIME_DW;
SFC_ERROR:= BLKMOV(SRCBLK := LOGTIME,
				   DSTBLK := Area);
  
READ_TIME := FALSE;
END_IF;

END_FUNCTION_BLOCK
 
I find what cause my error in one of Hans Bergers excellent books.
If the datablock is adressed indirectly, the data adress can not be adressed symbolically.
 

Similar Topics

I have upgraded an old RS500 project to Studio 5000, it has thrown multiple errors which I am currently working through. I have looked through...
Replies
8
Views
1,720
Hello guys, I use Tia Portal V16. What is the best way to change the indexed HMI tags when I change the format of an Udt in my plc program...
Replies
0
Views
1,303
Hello, I am doing a PLC5 to 1756 L81 conversion. I have an issue with what looks like an indexed array bit in the PLC 5 that I am unsure of how...
Replies
1
Views
1,272
As per manual i was tested with PLC on below program. But not any changes using swap instruction. plz help
Replies
3
Views
1,992
Hello, I'm running into an issue with how to resolve an indexed data array ADD in a SLC 5/5 to a Compactlogix 1769 L33ER conversion process. I...
Replies
8
Views
3,062
Back
Top Bottom