Jump to content

Recommended Posts

Posted

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)


Posted

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.

 

Posted

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 ":"

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
Posted

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?

Posted
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'.

Posted

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.

Posted (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.

TruncateTime.png

 

Edited by Danderson
Posted

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).

Posted

 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));

 

  • Like 1
Posted
On 1/28/2023 at 5:43 AM, Str8jCkt said:

 I know this question is a little old but wanted to post snips of code that might help someone out in the future.

Likewise. I know this question is old, but found something today that might be of use to others later on. I was trying to get a data display to show text and timespan using the custom formatting option, but it was only displaying the timespan data (ie. no text). I will caveat this by saying I haven't tested this on an HMI yet, but it does work in the simulator. Omron doesn't document this anywhere I could find, so it was simply trial and error.

VBA has custom formatting options for timespan variables (see here: https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-timespan-format-strings ), and as it turns out, these can be applied to data display objects using the numeric custom value format. For example:

  • Set the DataType of the Data Display to "Numeric"
  • Value Format = Custom
  • CustomDisplayFormat: My Time Label: {0:hh\:mm\:ss\.ff}
    • Details on what the characters and formatting do are documented in the above Microsoft link.

The above results in a data display that displays "My Time Label: 12:15:30.25" (minus the double quotes).

So not only can we include text in the data displays for Timespan variables, we can also control the resolution displayed simply by using the HMI formatting.

Posted

You can use that custom format for about anything.  I've used it before to include text like 'mm' or 'Degrees F' as part of a numeric display.

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
×
×
  • Create New...