S7 Data logging

JohnW

Member
Join Date
Mar 2004
Location
Cornwall
Posts
487
I want to log with a time stamp the last 30 values. I was thinking of using a data block and with incrementing pointers to enter the records. The value is a real number and the time stamp is a DT type. I add 4 to the pointer for the next real value and 8 for the next time stamp. So I have a block of 30 real numbers followed by a block of 30 date time values.

p1 = value pointer

p2 = DT pointer

for each record p1 = p1+4 p2 = p2+8

So the data block address looks like DBx.DBD[p1] for the real values. Is the address for the DT value P#DBx.DBX[p2].0 ?

will this work and is there a better way to do this?
 
Can you clarify the functionality. Initially the log is empty. Event occurs and you put in and entry. Then another, until you count 30 entries. Do you then stop logging, or do the entries shift down so the log contains the last 30 entries ?
 
I guess I'd put the value and the DT in together so that I've only got one set of entries to shift down each time rather than shifting down the values and the DT entries separately.
 
Important note: If you use the DT type in a DB, you cannot monitor it.

Here's an implementation if it's of any use. Call FC1 when you want to add an entry to the log. I've used DB9 for the log store and a structure for the date and time so you can view the logged time when monitoring the DB.

Code:
DATA_BLOCK DB 9
TITLE =
VERSION : 0.1

  STRUCT  
   Data : ARRAY  [1 .. 30 ] OF STRUCT  
	rValue : REAL ; 
	When : STRUCT  
	 byYearBCD : BYTE ; 
	 byMonthBCD : BYTE ; 
	 byDayBCD : BYTE ; 
	 byHourBCD : BYTE ; 
	 byMinuteBCD : BYTE ; 
	 bySecondBCD : BYTE ; 
	 byMillisecond1BCD : BYTE ; 
	 byMillisecond2BCD : BYTE ; 
	END_STRUCT ; 
   END_STRUCT ; 
  END_STRUCT ; 
Begin
END_DATA_BLOCK

FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  rValue : REAL ; 
END_VAR
VAR_TEMP
  when : DATE_AND_TIME ; 
  iSFC1Ret : INT ; 
  iSFC20Ret : INT ; 
  iLoopCount : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =shuffle down entries
	  OPN   DB	 9; 
	  LAR1  P#DBX 336.0; //this is the 29th entry
	  L	 29; 
Loop: T	 #iLoopCount; 
	  L	 D [AR1,P#0.0]; 
	  T	 D [AR1,P#12.0]; 
	  L	 D [AR1,P#4.0]; 
	  T	 D [AR1,P#16.0]; 
	  L	 D [AR1,P#8.0]; 
	  T	 D [AR1,P#20.0]; 
	  L	 P#12.0; 
	  NEGD  ; 
	  +AR1  ; 
	  L	 #iLoopCount; 
	  LOOP  Loop; 
NETWORK
TITLE =get time
	  CALL SFC	1 (
		   RET_VAL				  := #iSFC1Ret,
		   CDT					  := #when);
	  NOP   0; 
NETWORK
TITLE =Add new entry for time
	  CALL SFC   20 (
		   SRCBLK				   := #when,
		   RET_VAL				  := #iSFC20Ret,
		   DSTBLK				   := DB9.Data[1].When);
	  NOP   0; 
NETWORK
TITLE =add new entry for value
	  L	 #rValue; 
	  T	 DB9.DBD	0; 
	  NOP   0; 
END_FUNCTION
 
Last edited:
Thanks for that, I will give it a go. I am not that experienced with this level of programming so it may take me a while to get my head round it.
 

Similar Topics

Hi, Wy we log data in PLC using DLG instruction, when we have option to log data in HMI
Replies
1
Views
63
Hi everyone id like to start by saying im not a PLC programmer so my technical terminology is limited. i would like advice on what software is...
Replies
4
Views
289
Hi All, I am looking for recommendations for a data logging software package that can be used for a simple 1 PLC installation. The installation...
Replies
13
Views
1,358
Hello all, I am working on a DA70A flex edge data logger. I am it communicating with a computer on the network. I can ping it and everything looks...
Replies
1
Views
384
Hi colleagues.We do data logging system.We want to record three temperatures under a certain condition. We prepared the project as follows. We do...
Replies
1
Views
746
Back
Top Bottom