Programming S71500 using TIA V15 Small tips and Trix. PART#2

Programming S71500 using TIA V15 Small tips and Trix. PART#2

Hello again nice that you found the way back here. Don’t forget to register on my forum Swiaf to help me to form the new automation forum. https://swiaf.se/. As said before all this articles with code can be found here soon.

PART #2
Using variant pointer in TIA V15 and the new simplified ‘?= ‘ operator.
 
  

What is an Variant pointer? An Variant pointer is nothing else than a pointer that can point to a data area in your controller. Quite similar with the old any pointer but with a more symbolic approach. It can point on a datatype that you created yourself or any other predefined data type and even other blocks. You can easily check which datatype the any pointer points at by using the instruction: TypeOf. E.g.

An Example Calculating area of different objects.

We want to create a simple function that can calculate the area of different objects, in this example we use Circle, Rectangle and Triangle. First, we define our three different objects by means of creating three different data types:

DataType #01: TCircle: 2 reals one radius and one area variable:

DataType #02: TRectangle: 3 reals one Height, Base and one Area.

DataType #03 Triangle, Same data as above.

Now we want to create our function for calculating the area of any of the above objects. We create a new FC called SF_CalcArea. (I use to mark all my standardfunctions With SF in the beginning of the name). We define parameters in head as shown below.

We define one in/Out Parameter That is defined as a variant to be able to point on any object from which we want to calculate the area. Our function will return the calculated area and update the object .area variable. We define 3 Temp variables as references to the defined objects.

 E.g.

REF_TO “TCircle” : Defined as a reference to a circle. (Note the REF_TO in front of the declaration, this indicates that this is to be a reference to a variable, this is the new TIA V15 twist saving you time).  Do the same for the two other objects Rectangle and Triangle. 

We also define one constant PI: I use to name all my local constants to start with CF = Constant in Function. I always write my constants in capital letters, everything to make the program more readable. If I would have selected to make the constant global, (Defined in a tag table) I would name it C_PI instead… Anyway. I also define a return value = An output from my function to be a Real Value= The calculated area. 

Okay, Now the code, in older versions of Tia you had to use the instructions VARIANT_GET and VARIANT_Put to read and write values to variables pointed out by variant pointers. This was not that effective, in TIA V15 you simply use the new operators:

 =?  -> Assign attempt – In this case a reference to a tag of type Variant

^     -> Access the value of a referenced tag.

The code for the calculate object area will look at shown below:

First, we check the type of the object by using a case statement together with the type of instruction. Then we make one case per Object and write the code for calculating each area.

 E.g. TCircle:

#TmpCircle ?= #object.

We assign reference to an object of type TCircle. As we have already checked that the object is a circle we do not have to take care of the situation that the reference fails. You can always check the result by comparing it to Null, Se below.

We Calculate the area for the circle as we all know: Radius*Radius * PI. Note the operator **2 that is equal to power of 2 (from TIA V14). Also note when we reference the Circle we use the ^ operator, giving us the referenced value.

E.g. #Tmp_Circle^.Radius.

Since TIA V14 it is also possible to assign more than one variable with the same value by Separating them with := . We use this approach to assign both the result of the function and the object area.

 #CalcArea := TmpCircle^Area := [Calculated value]

To test the function, we create a new global DB: MyObjects and adds 3 Shape objects to it:

In OB1 we can now make calls to the function with different objects:

Please note that all this can be done in LAD and other languages as well.

Don’t hesitate to contact me if you have any questions or if u want to learn more about TIA portal.

Make comments, I love your feedback. If you like it, then like the article. If you hate it then write this as well. And finally, do not forget that any contact you make here at LinkedIn may be a new opportunity for yourself. Keep sharing.

Until then Have a nice day and good luck with your Coding.

 //Mattias Lindh, Mattias Lindh Automation AB.



Anoop Balagopal

Industrial Automation,Warehouse Automation,SIEMENS

5 年

When I compile the block,I am getting an error" Access through non-initialized pointer Can you please upload the programme

回复
Mattias Lindh

Automation Engineer @ Mattias Lindh Automation AB | PLC Programming Expert

6 年

Thanx for the feedback.

回复
Joakim Waldau

Automationsingenj?r p? AFRY BA Advanced Automation

6 年

I like what you are doing!

回复

要查看或添加评论,请登录

Mattias Lindh的更多文章

  • A life cycle of an OT network, how to prevent errors?

    A life cycle of an OT network, how to prevent errors?

    Preamble Isn't it strange? When we order a job to install a new network connection in our office. We demand a measuring…

    1 条评论
  • En Livscykel f?r ett industriellt n?tverk, hur f?rebygga fel?

    En Livscykel f?r ett industriellt n?tverk, hur f?rebygga fel?

    En beskrivning av vad som h?nder ?ver tid och hur problem kan f?rebyggas innan produktionen drabbas. En f?rklaring som…

  • IIOT

    IIOT

    This have been a topic for so many years now but… I do read a lot of posts where people still mix up the…

  • Industrial networks back to the future.

    Industrial networks back to the future.

    We are all talking about OPC UA TSN, Cloud computing, I4.0, etc.

    1 条评论
  • Programming S71500 using TIA V15 Small tips and Trix. PART#1

    Programming S71500 using TIA V15 Small tips and Trix. PART#1

    This is an article series focusing on useful tips and tricks useful when programming siemens S71500 in TIA portal V15…

  • Industrial networks and bus systems

    Industrial networks and bus systems

    Imagine your self being responsible for a big automation network. What do you have to face? You have the demands to be…

  • Is the IIoT a new dot-Com bubble?

    Is the IIoT a new dot-Com bubble?

    There are many good things when talking about the IIoT. New ways to save power, increase productivity and safety in…

    18 条评论
  • VPN connection to customer sites.

    VPN connection to customer sites.

    Having the possibility to remotely support customers have always been a good thing. Many of us remember sitting…

    1 条评论
  • How do we get more young people to be Interested in automation engineering?

    How do we get more young people to be Interested in automation engineering?

    I believe that many of you can relate to the situation sitting on a party, the person sitting next to you asks what are…

    6 条评论
  • Control system programming.

    Control system programming.

    For more than ten years I have been struggling with people that states that ladder is the only understandable way of…

    5 条评论

社区洞察

其他会员也浏览了