Posted 26 Feb 2020 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
Posted 26 Feb 2020 It is a bit convoluted, but you can do this: 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
Posted 27 Feb 2020 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 6 May 2020 (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 Edited 6 May 2020 by Nate Hammersmith Share this post Link to post Share on other sites
Posted 7 May 2020 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
Posted 7 May 2020 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
Posted 7 May 2020 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
Posted 7 May 2020 Here's a FB in ST that outputs a string in HH:MM:SS format. Share this post Link to post Share on other sites
Posted 22 May 2020 (edited) 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. Edited 22 May 2020 by Danderson Share this post Link to post Share on other sites
Posted 23 May 2020 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
Posted 27 January I know this question is a little old but wanted to post snips of code that might help someone out in the future. Test_Time is a TIME DataType variable Time_String is a STRING[] DataType variable To get a string with HH:MM:SS format for dispaly from a TIME DataType you can use the below code: (* Convert Time to String HH:MM:SS format for Display *)Time_String := LEFT(TodToString(SecToTod(TimeToSec(Test_Time))),UINT#8); If you want to display with miliseconds in the format (HH:MM:SS.SSS) then you need to do two TIME conversions to strip the lower decimals from the nanosecond conversion and CONCAT the two strings with a decimal in between. (* Convert Time to String HH:MM:SS.SSS format for Display *)Time_String := CONCAT(LEFT(TodToString(SecToTod(TimeToSec(Test_Time))),UINT#8),'.',LEFT(RIGHT(LINT_TO_STRING(TimeToNanoSec(Test_Time)), UINT#9),UINT#3)); 1 person likes this Share this post Link to post Share on other sites