Set Time in S7

snydl0ga

Member
Join Date
Apr 2005
Location
Tennessee
Posts
21
Anyone have simple code for setting the DateTime (SFC0) from data in DataBlocks?

S7 318-2 CPU

I can read the clock into data blocks but now I have to synchronize the D/T with our PCs so I need to set the D/T in the PLC.

Lance
 
No Info on Syncing time from a PC running VB? Or how to combine the yrs, days, month.....etc into a DT variable to send to Set_Clk ?
 
Or how to combine the yrs, days, month.....etc into a DT variable to send to Set_Clk

You're almost there. The single DATE_AND_TIME data type extends over several bytes. These hold the year, month, date, hour, minute etc Check the STEP7 online help for the order of these bytes. Search for DATE_AND_TIME.

Thereafter, if you've already got the individual values stored somewhere in a datablock, you can just use the standard Load and Transfer instructions to populate the DATE_AND_TIME bytes with the values you need. Let's just do the year, month & date as an example. Assume you've got 3 INTEGERS in MW0, MW2 and MW4 and your DATE_AND_TIME is in DB1 starting at DBB0

Code:
L MB1	 // You only want the LSB of the word
ITB		 // convert it to BCD/Hex coding
T DB1.DBB0 // Store in the first byte of the DATE_AND_TIME
 
L MB3	 // You only want the LSB of the word
ITB		 // convert it to BCD/Hex coding
T DB1.DBB1 // Store in the 2nd byte of the DATE_AND_TIME
 
L MB5	 // You only want the LSB of the word
ITB		 // convert it to BCD/Hex coding
T DB1.DBB2 // Store in the 3rd byte of the DATE_AND_TIME
 
.....

etc etc

Once you've filled the DATE_AND_TIME, just call the SFC and tell it the address to get the data. Give the DB1 a name, and you can use the whole structure symbolically like "TimeStore".Now where TimeStore is DB1 and Now is the name of DATE_AND_TIME variable.

Good luck

Ken.
 

Similar Topics

Hi need help why this “failure 5 emergency stop “ appears at every startup in the morning ? Have to shut off main switch at least 10 times on...
Replies
19
Views
281
Omron AD081-V1 Analog Input Card Offset & Gain Adjustment Entering Adjustment Mode 1. Set the input card in adjustment mode (Turn ON Dip SW No-1)...
Replies
0
Views
87
I was loading a program onto an XE1e2 PLC and it got stuck on these two windows and won't progress. It won't let me connect from the PC to reload...
Replies
0
Views
73
Hi all, i have recieved some 4RF Aprisa SR+ ethernet radios from a customer to configure. Issue is that they are used and have non-default...
Replies
0
Views
78
I want to set user security level based on the value of a tag in my PLC called "ActiveUser". That tag will contain the A-P code which we use for...
Replies
6
Views
211
Back
Top Bottom