You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old January 5th, 2018, 02:03 AM   #1
FCS_Chris
Member
Australia

FCS_Chris is offline
 
Join Date: Nov 2017
Location: Perth
Posts: 5
Logix Compare DateTime UDT?

Hi all,

Is there an efficient way to compare the UDT elements below in ladder logic, I need to know when they're not equal?

Compare PLC_DateTime_Set.Previous to PLC_DateTime_Set.Current

Code:
PLC_DateTime_Set				DateTime_Set
  PLC_DateTime_Set.Previous			DateTime
    PLC_DateTime_Set.Previous.Year		DINT
    PLC_DateTime_Set.Previous.Month		DINT
    PLC_DateTime_Set.Previous.Day		DINT
    PLC_DateTime_Set.Previous.Hour		DINT
    PLC_DateTime_Set.Previous.Minute		DINT
    PLC_DateTime_Set.Previous.Second		DINT
    PLC_DateTime_Set.Previous.uSec		DINT
  PLC_DateTime_Set.Current			DateTime
    PLC_DateTime_Set.Current.Year		DINT
    PLC_DateTime_Set.Current.Month		DINT
    PLC_DateTime_Set.Current.Day		DINT
    PLC_DateTime_Set.Current.Hour		DINT
    PLC_DateTime_Set.Current.Minute		DINT
    PLC_DateTime_Set.Current.Second		DINT
    PLC_DateTime_Set.Current.uSec		DINT
Cheers,
Chris.
  Reply With Quote
Old January 5th, 2018, 06:33 AM   #2
widelto
Member
Colombia

widelto is offline
 
widelto's Avatar
 
Join Date: Jul 2005
Location: barranquilla
Posts: 2,535
You can use an index on both arrays, then increment index and compare element by element until last element is achieved then repeat, this way is easier to handle.
Or you compare them individually using brute force.
__________________
My two cents.
  Reply With Quote
Old January 5th, 2018, 06:45 AM   #3
FCS_Chris
Member
Australia

FCS_Chris is offline
 
Join Date: Nov 2017
Location: Perth
Posts: 5
Thanks widelto,

I tried accessing the elements via an index but couldn't get it to work. Can anyone elaborate on the correct approach?

For now I've got a bunch of parallel NEQs which do the job rather untidily an inefficiently. Surely there's a better way?

Cheers,
Chris.
  Reply With Quote
Old January 5th, 2018, 06:47 AM   #4
jstolaruk
Member
United States

jstolaruk is offline
 
Join Date: Dec 2004
Location: Detroit, SE Michigan
Posts: 3,181
Seven NEQ instructions in a single rung is not a big deal, and its efficient. The next guy will know instantly what is happening.
__________________
"You can live to be a hundred if you give up all the things that make you want to live to be a hundred." Woody Allen
  Reply With Quote
Old January 5th, 2018, 06:50 AM   #5
FCS_Chris
Member
Australia

FCS_Chris is offline
 
Join Date: Nov 2017
Location: Perth
Posts: 5
Efficient to execute... but not to code. Especially if dealing with a bigger UDT.

Surely there's a better way?
  Reply With Quote
Old January 5th, 2018, 06:54 AM   #6
jstolaruk
Member
United States

jstolaruk is offline
 
Join Date: Dec 2004
Location: Detroit, SE Michigan
Posts: 3,181
Use structured text.
__________________
"You can live to be a hundred if you give up all the things that make you want to live to be a hundred." Woody Allen
  Reply With Quote
Old January 5th, 2018, 07:02 AM   #7
widelto
Member
Colombia

widelto is offline
 
widelto's Avatar
 
Join Date: Jul 2005
Location: barranquilla
Posts: 2,535
PLC_DateTime_Set.Previous DateTime = Array0
PLC_DateTime_Set.Previous.Year DINT =Array0[0]
PLC_DateTime_Set.Previous.Month DINT =Array0[1]
PLC_DateTime_Set.Previous.Day DINT
PLC_DateTime_Set.Previous.Hour DINT
PLC_DateTime_Set.Previous.Minute DINT
PLC_DateTime_Set.Previous.Second DINT
PLC_DateTime_Set.Previous.uSec DINT =Array0[7]
PLC_DateTime_Set.Current DateTime = Array1
PLC_DateTime_Set.Current.Year DINT =Array1[0]
PLC_DateTime_Set.Current.Month DINT =Array1[1]
PLC_DateTime_Set.Current.Day DINT
PLC_DateTime_Set.Current.Hour DINT
PLC_DateTime_Set.Current.Minute DINT
PLC_DateTime_Set.Current.Second DINT
PLC_DateTime_Set.Current.uSec DINT =Array1[7]

Index in this case is from 0 up to 7
compare array0[index] to array1[index]
the increment index and compares gain repeat until index = 7 then go back.
__________________
My two cents.
  Reply With Quote
Old January 5th, 2018, 07:02 AM   #8
FCS_Chris
Member
Australia

FCS_Chris is offline
 
Join Date: Nov 2017
Location: Perth
Posts: 5
Thanks jstolaruk, structured text would be a nice way to do it.

Unfortunately we're running Studio5000 mini/cheap, only $1377 +GST
  Reply With Quote
Old January 5th, 2018, 07:04 AM   #9
cwal61
Member
United States

cwal61 is offline
 
Join Date: Jan 2011
Location: NC
Posts: 944
Change them to Arrays and use the FSC instruction. Then FSC Expression would be:

PLC_DateTime_Set.Previous[FSC_Control.POS] <> PLC_DateTime_Set.Current[FSC_Control.POS]

PLC_DateTime_Set.Previous[7] DINT

PLC_DateTime_Set.Previous.[0] = Year
PLC_DateTime_Set.Previous.[1] = Month
PLC_DateTime_Set.Previous.[2] = Day
PLC_DateTime_Set.Previous.[3] = Hour
PLC_DateTime_Set.Previous.[4] = Minute
PLC_DateTime_Set.Previous.[5] = Second
PLC_DateTime_Set.Previous.[6] = uSec

PLC_DateTime_Set.Current[7] DINT

PLC_DateTime_Set.Current.[0] = Year
PLC_DateTime_Set.Current.[1] = Month
PLC_DateTime_Set.Current.[2] = Day
PLC_DateTime_Set.Current.[3] = Hour
PLC_DateTime_Set.Current.[4] = Minute
PLC_DateTime_Set.Current.[5] = Second
PLC_DateTime_Set.Current.[6] = uSec
  Reply With Quote
Old January 5th, 2018, 08:45 AM   #10
Mispeld
Member
United States

Mispeld is offline
 
Mispeld's Avatar
 
Join Date: Feb 2017
Location: VA
Posts: 281
This is not answering the OP's question about comparing the seven elements of the DateTime/LocalDateTime objects. Instead, consider using the CurrentValue of the WALLCLOCKTIME, which can be read into a two-element DINT array for a slightly faster comparison. This may not be appropriate if the DateTime elements are used for other purposes such as on HMI displays.

I am not seeing a way to get DateTime and CurrentValue simultaneously, which implies you may not be able to store both, and guarantee them to be consistent. There could be an AOI to convert CurrentValue to a DateTime object, in which case you could GSV and store the 64-bit CurrentValue, and then convert to DateTime elements as needed.
  Reply With Quote
Old January 5th, 2018, 09:32 AM   #11
Geospark
Lifetime Supporting Member
Ireland

Geospark is offline
 
Geospark's Avatar
 
Join Date: Feb 2012
Location: Kildare
Posts: 2,318
Hi and Welcome to the Forum!

Quote:
Originally Posted by FCS_Chris
...Is there an efficient way to compare the UDT elements below in ladder logic, I need to know when they're not equal?...
If you just need to know when the UDTs, as a whole, are not equal, then perhaps this simple method might suffice?...

45384 - Compare a whole UDT's data with another UDT
Access Level: Everyone

Regards,
George
__________________
"A little nonsense now and then is relished by the wisest men".
  Reply With Quote
Old January 8th, 2018, 12:32 AM   #12
FCS_Chris
Member
Australia

FCS_Chris is offline
 
Join Date: Nov 2017
Location: Perth
Posts: 5
Thanks everyone for your input!

To summarise, UDTs can be compared with:
- Parallel NEQ or other instructions.
- Instead of UDT use an array, elements can then be compared via their index using FSC or other instruction
- Structured text

There was a suggestion that elements of UDTs can be access via an index like an array. This would be nice but I haven't been able to get it to work. Is this really possible?

Cheers,
Chris.
  Reply With Quote
Old January 8th, 2018, 05:18 AM   #13
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,341
I would go "brute-force" on this, just for the sake of clarity...

A string of 7 EQU instructions in series on a rung would evaluate as true only if all elements were the same.

Obviously XIO "Same" would mean "Different"
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old January 8th, 2018, 08:08 AM   #14
Mispeld
Member
United States

Mispeld is offline
 
Mispeld's Avatar
 
Join Date: Feb 2017
Location: VA
Posts: 281
Quote:
Originally Posted by FCS_Chris View Post
There was a suggestion that elements of UDTs can be access via an index like an array. This would be nice but I haven't been able to get it to work. Is this really possible?
The literal answer to this question is, to my knowledge, no -- unless the UDT elements are defined as arrays to begin with.

What you can do, as pointed out by Geospark in post #11, is to effectively memory-copy UDT tags into a one-dimensional arrays. Then you can FSC or loop through those arrays for comparison with each other. This technique operates on copies of the UDT tags, and will not identify which UDT element(s) are different.

If it were possible to alias an array tag to a UDT tag, comparing the actual UDT contents would be possible. However, when defining an alias, Logix forces the data type of the alias to that of the base tag. I have not found a way around this behavior.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Studio 5000 Logix Emulate - Is this a free software with RS Logix 5000 or support ? Baker in Virginia LIVE PLC Questions And Answers 33 June 8th, 2017 01:58 PM
How to compare PART of a UDT Array TheWaterboy LIVE PLC Questions And Answers 14 December 20th, 2015 04:59 PM
Logix 5000 renaming UDT members lambles LIVE PLC Questions And Answers 1 July 1st, 2013 07:17 PM
Compact Logix Remote Racks The Plc Kid LIVE PLC Questions And Answers 10 September 29th, 2009 05:11 PM
Producer Consumer Messging between Control Logix & Compact Logix plcnovel LIVE PLC Questions And Answers 15 July 24th, 2006 10:04 AM


All times are GMT -5. The time now is 12:48 AM.


.