Danderson

Time display formatting question

11 posts in this topic

I am trying to display the time from an Accumulation timer. Using a data display object I am able to see the time in the following format 00:00:00.0000000. Is there a way to format the time without the decimal seconds I just want to see 00:00:00 (hours:minutes:seconds)

Share this post


Link to post
Share on other sites

Not that I am aware of.

Share this post


Link to post
Share on other sites

It is a bit convoluted, but you can do this:

DTStruct.thumb.jpg.509b68f5dd901ae18b284

Ultimately, you want to have the time in a DT Struct variable and then you can used ElapsedDTStruct.Hour,  ElapsedDTStruct.Min and  ElapsedDTStruct.Sec as 3 individual displays on your screen.  The code above does what you need.  Of course you need to ignore the Year, Month, Day fields.

 

Share this post


Link to post
Share on other sites

Temp := TimeToSec(yourTimerVariable);

Hour := Temp / 3600;

Min := (Temp MOD 3600) / 60;

Sec := (Temp MOD 60);

After that you can convert this 3 integer to  string. Then concat with ":"

Share this post


Link to post
Share on other sites

Posted (edited)

I use something similar to show times of a machine running or not running. Unfortunately, I use multiple data displays on the HMI to represent N, NMInutes, NHours, an NDays. Like Michael said though. its gets to be convoluted.

 

Edit: It is really easy to get away from the multiple data displays with using a single text data display with an Expression that would look like:

NHours & ":" & NMinutes &  ":" Nsecs & "." &NTenthSecs

 

 

 

Capture.PNG

Edited by Nate Hammersmith

Share this post


Link to post
Share on other sites

I have never used these but in the CJ2M there is ANDW function which can be used as a mask and is really good. Is there nothing like this in the NA?

Share this post


Link to post
Share on other sites
8 hours ago, BobB said:

I have never used these but in the CJ2M there is ANDW function which can be used as a mask and is really good. Is there nothing like this in the NA?

Keep in mind the NJ/NX series is much different animal than the CJ and previous PLCs.

You don't see the physical memory locations. You can do logical operations like AND, OR, XOR, etc... but they must be performed on Data Types like BOOL arrays, BYTE, WORD, DWORD, etc...

For time, you must use the Data Types TIME and DT (Date & Time). They have special instructions like the ones that Michael has shown. The TIME Data Type contains all the fields contiguously, which was the original poster's issue. The AND or ANDW function will not work with them. Michael has converted it to DT where each element can be accessed as Dot Fields (".").

Bob, I know your are well experienced with PLCs and you are used to manipulating memory however you wish. With the new platform you (kind of) loose that freedom. Conversions will be necessary where you used to be able to just 'take a portion'.

Share this post


Link to post
Share on other sites

Thanks for the reply. I will probabaly eventually have to tackle 'the dark side' and just trying to get my head around it a bit. The Schneider M580 is a very different beast to the predecessors as well - still have not got my head around that properly after doing a large job with the redundant processor one. It is all changing I guess.

Share this post


Link to post
Share on other sites

Here's a FB in ST that outputs a string in HH:MM:SS format.

Format_Time_FB.thumb.png.056f6599f8d4315

Sample_Output.png.2badd0b8a682b193960095

Share this post


Link to post
Share on other sites

The solution I actually used was to feed the accumulation timer into the TruncTime function and using _eSUBSEC#_SEC for the accuracy. I then use a numeric Data Display to show it.

TruncateTime.png

 

Edited by Danderson

Share this post


Link to post
Share on other sites

The Data Display object must adjust its format automatically if the milliseconds are all zero's, The output of TruncTime is still a Time Variable (time in nanoseconds).

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