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
Unread December 2nd, 2019, 08:59 PM   #1
dahnuguy
Member
United States

dahnuguy is offline
 
Join Date: Mar 2007
Location: SC
Posts: 679
SCL operator question TIA Portal V15

I just found a piece of code using an operator "+="

IF tag1 AND tag2 THEN
tag3 += tag4;
tag5 := tag5 + tag6;
END_IF;

I don't find "+=" anywhere in operators list, is this a typo?
  Reply With Quote
Unread December 2nd, 2019, 10:51 PM   #2
ASF
Lifetime Supporting Member
Australia

ASF is offline
 
Join Date: Jun 2012
Location: Australia
Posts: 3,013
If I had to guess (and it is a complete guess) I'd suggest that it's adding tag3 to tag4 and storing the result in tag4. Would that make sense, given what you know of the process?
  Reply With Quote
Unread December 2nd, 2019, 11:11 PM   #3
kalabdel
Member
Canada

kalabdel is offline
 
Join Date: Feb 2015
Location: Ontario
Posts: 487
Quote:
Originally Posted by ASF View Post
and storing the result in tag4.

Tag3




I was surprised by some code a read on Siemens forums and turns out there's a lot more that can be done in SCL that is not documented.
  Reply With Quote
Unread December 2nd, 2019, 11:26 PM   #4
mk42
Member
United States

mk42 is offline
 
Join Date: Jun 2013
Location: MI
Posts: 2,249
tag3 += tag4;
tag3 := tag3 + tag4;


The above two lines of code would do the same thing. += is a common operator in PC based languages, but I only learned it was supported in SCL in Siemens relatively last month. One of the posts in that thread said it was new in v15, so I guess that could be why it is new to everybody.
  Reply With Quote
Unread December 3rd, 2019, 12:05 AM   #5
ASF
Lifetime Supporting Member
Australia

ASF is offline
 
Join Date: Jun 2012
Location: Australia
Posts: 3,013
Quote:
Originally Posted by kalabdel View Post
Tag3
Whoops, yes, my mistake. I can no longer edit my post but hopefully the future visitors will read past my "complete guess" and onto the more concrete answers anyway!
  Reply With Quote
Unread December 3rd, 2019, 12:22 AM   #6
dahnuguy
Member
United States

dahnuguy is offline
 
Join Date: Mar 2007
Location: SC
Posts: 679
Quote:
Originally Posted by mk42 View Post
tag3 += tag4;
tag3 := tag3 + tag4;


The above two lines of code would do the same thing. += is a common operator in PC based languages, but I only learned it was supported in SCL in Siemens relatively last month. One of the posts in that thread said it was new in v15, so I guess that could be why it is new to everybody.
(I think this was written in V14. I had to "update" it to open it.)


This was my guess as well, but why would a person do the same thing two ways in the same operation?

If I were to like += for the brevity of it, and let's not leave out the fact that it isn't documented...then why would I then use x:= x+y on the very next line?

I assumed the whole project was written by a PC programmer. It is very PC like and mostly in SCL.

They had years to write and patch this monster and I have days to explain it all in "plain English" to non programmers to allow them to understand why it occasionally doesn't do what they think it should do.

What Joy.

Only STL written by Germans could be more fun.

Thanks to all who responded.
  Reply With Quote
Unread December 3rd, 2019, 01:27 AM   #7
CommissioningMan
Member
Denmark

CommissioningMan is offline
 
Join Date: Sep 2017
Location: Denmark
Posts: 84
I was surprised too when I noticed it. I love it.
Now we just need ++i and i++ :-)

Other operators:
i -= 1;
i := i - 1;

i *= 2;
i := i * 2;

i /= 3;
i := i / 3;

I usually don't use these if I'm writing code for others, but when I'm writing internal TCP comms blocks or the likes, shorthand it is!
__________________
All things Siemens and Beckhoff. Please let it be Beckhoff.
  Reply With Quote
Unread December 3rd, 2019, 01:33 AM   #8
mk42
Member
United States

mk42 is offline
 
Join Date: Jun 2013
Location: MI
Posts: 2,249
Quote:
Originally Posted by CommissioningMan View Post
Now we just need ++i and i++ :-)

I was thinking the same thing, but I've also heard that they're generally considered poor form in most of the modern languages these days. I think it is partly due to the fact that they can cause troubleshooting headaches when trying to read code and figure out what it does when the variable changes, and partly due to the fact that OOP means that indexing through arrays is old hat anyway.
  Reply With Quote
Unread December 3rd, 2019, 05:15 AM   #9
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is offline
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 14,002
The confusion in the 1st posts shows to me why it is a bad idea with this += nonsense.
Anything that is implied is a bad thing.
Better to spell it out.
__________________
Jesper
See my profile interests for Q&A
  Reply With Quote
Unread December 3rd, 2019, 06:53 AM   #10
cardosocea
Member
United Kingdom

cardosocea is offline
 
Join Date: Nov 2016
Location: Fields of corn
Posts: 1,472
Quote:
Originally Posted by JesperMP View Post
The confusion in the 1st posts shows to me why it is a bad idea with this += nonsense.
This is where computer programmers differ from PLC programmers...
  Reply With Quote
Unread December 3rd, 2019, 07:49 AM   #11
dahnuguy
Member
United States

dahnuguy is offline
 
Join Date: Mar 2007
Location: SC
Posts: 679
Quote:
Originally Posted by JesperMP View Post
The confusion in the 1st posts shows to me why it is a bad idea with this += nonsense.
Anything that is implied is a bad thing.
Better to spell it out.
I am ok with either but not both. Consistency is a peeve of mine.

I would rather not see anything in the program that is not documented.
What are they really saving with this anyway?
  Reply With Quote
Unread December 3rd, 2019, 07:55 AM   #12
dahnuguy
Member
United States

dahnuguy is offline
 
Join Date: Mar 2007
Location: SC
Posts: 679
Quote:
Originally Posted by cardosocea View Post
This is where computer programmers differ from PLC programmers...
Not true, lots of PLC programs are also full of spaghetti and weird obtuse indirect addressing and loops that do nothing.

I just spent 30 minutes looking at a weird if then nested inside an if then else if inside a loop that after all the variables were tracked down and understood, did nothing at all.

It is not all documented and easy to follow.

Not sure which camp is worse about comments and documenting the code in the code, I don't see much of it in either camp.

But for really opaque code, nobody beats the Germans.
  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
TIA Portal V15 & Redundant system osamamalhy LIVE PLC Questions And Answers 6 August 17th, 2019 10:16 AM
TIA Portal v15 - does it overwrite v14 / v13? uptown47 LIVE PLC Questions And Answers 20 March 8th, 2019 03:59 AM
TIA portal V15. Problems simulating HMI iansabey LIVE PLC Questions And Answers 8 December 13th, 2018 04:49 PM
run Step 7 without TIA Portal dmned64 LIVE PLC Questions And Answers 4 June 7th, 2017 06:39 AM
TIA Portal V12, Datablocks in SCL + Symbol Info Tony G LIVE PLC Questions And Answers 0 November 29th, 2013 06:55 PM


All times are GMT -5. The time now is 05:17 PM.


.