Sign in to follow this  
Followers 0
freewayc

Obtaining wallclocktime into one single tag. (Cntrlogix)

21 posts in this topic

I need to obtain the time once every minute for a project and condense it into one easy to read user friendly format. Example: 12:02 AM. Any ideas or code examples? I know you access the PLC time via GSV and store it in a DINT(7). I just need to put it together in one tag and prefferably not in military time.

Share this post


Link to post
Share on other sites
Here attached is an example Hope this helps.... - fuzzy logic Clock.zip Edited by fuzzy logic

Share this post


Link to post
Share on other sites
Are you wanting to display this time in an HMI? For that you just display hour hours, and if greater than 12, subtract 12 and change text display to PM. minutes should be straight forward. If you do it Fuzzy's way, in the PLC, just do your compare and subtract 12 before your concatenate. Edited by IamJon

Share this post


Link to post
Share on other sites
Thanks fellas!! This helped immenseley. I don't program every day and I've never even heard of concatenate. It is going to be used in conjunction with a program called XLReporter in which the tag will be used to display the time and temperature every minute of a furnace. Thanks again

Share this post


Link to post
Share on other sites
The actual algorithm would be: If hours > 11 then AM/PM = PM else AM/PM = AM If hours > 12 then hours = hours - 12 If hours = 0 then hours = 12 In case anyone cares the conversion in the opposite direction is: If (AM/PM = AM) AND (Hours = 12) then Hours = 0 if (AM/PM = PM) AND Hours < 12 then Hours = Hours + 12 Edited by b_carlton

Share this post


Link to post
Share on other sites
I just spent the whole day trying to get the colon character in between the hours, minutes and seconds. I tried converting 58 (ascii for :) into a string to no avail. I know this is probably pretty fundamental, but can anyone give me a hand? Thanks

Share this post


Link to post
Share on other sites
Have you looked at fuzzy logic's example.."Clock.zip" it has a "String Concatenate" function used to add in the Colon....? Edited by TechJunki

Share this post


Link to post
Share on other sites
IMHO, the U.S. (entire world, for that matter) should do away with AM and PM and use 24-hour time (some mistakenly refer to this as Military Time (it is not, but the military does use it)). It sure makes manipulating and displaying time easier by a couple orders of magnitude. Add to that the complete elimination of confusion; when somebody refers to 0900, there is no doubt whether they mean morning or evening. Just my 2¢ worth. Bill

Share this post


Link to post
Share on other sites
To be more specific: In the example (clock) from fuzzy, how do I get the tag ora1[2] to contain the colon ":" symbol.

Share this post


Link to post
Share on other sites
Assuming the array of strings (ora1(x)) is in 'Controller Tags', open 'Controller Tags'. Make sure the 'Monitor Tags' tab is chosen. Expand ora1 so that ora1[2] is shown. In the 'Value' column click then click on the ellipsis ('...'). In the window that opens type a single colon then click 'OK'

Share this post


Link to post
Share on other sites
Just type it into the word as you would any variable

Share this post


Link to post
Share on other sites
Thanks alot fellas. As you might have guessed, I am pretty new to programming and I assumed that you must change variables in edit, not monitor. I spent a whole day trying to figure that out. Just think of the lost productivity!

Share this post


Link to post
Share on other sites
If you couldn't tell, I'm pretty new to PLC programming. I ran into another problem. I am adding logic for a 12 hour clock which was pretty simple until I got to AM/PM. In fuzzy's example above, I want to concatenate "AM" or "PM" to the time. I added a string array giving two of the strings values of "AM" and "PM" and tried to use a MOV command to move them, depending on the time of day, and then concatenate them onto the rest of the time. Problem is, I can't MOV the string. How would I go about doing this?

Share this post


Link to post
Share on other sites
There may be a better way.... but quickly combining fuzzy logic's code and b_calton's "rules" it would look something like this. Edited by TechJunki

Share this post


Link to post
Share on other sites
Awesome Techjunki, now, how would I go about saving "Timestrings[4]" into another string array since you cant use MOV? I need to save the time (Timestrings[4] is perfect) into another string array for a furnace in which I need to store the temperature and time each minute. I already have all of the logic in place but I can't move the time into the time string array. Thanks for the AM/PM solution.

Share this post


Link to post
Share on other sites
I would either use structured text (this is a whole other story), or you can just use the CONCAT function and make Source A the string you want to move, Source B would just be an empty string, and the destination is where you want to move the Source to.

Share this post


Link to post
Share on other sites
I understand. I will give it a shot and let you know how it works out!! Thanks alot!!

Share this post


Link to post
Share on other sites
Try using the COP instruction to move strings.

Share this post


Link to post
Share on other sites
Thanks BobLfoot for catching that, I put it together pretty quick. I see the COP does in fact support String datatypes, I figured there was a better way to move strings.

Share this post


Link to post
Share on other sites
No problem - Editing or reviewing is easy, coming up with the algorithm is the tuff part and you nailed it well.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0