OTee#Vritual PLC_Part04_Let’s make a Function!

This is a new series of articles using a Virtual PLC called OTee. In the fourth article, we will create Functions on the OTee Platform, which allows you to reuse code and improve the readability of your programs.

Come on, let’s enjoy FA.

Foreword

Thank you from the bottom of my heart for visiting my technical blog and YouTube channel.

We are currently running the “Takahashi Chris” radio show with Full-san (full@桜 八重 (@fulhause) / X) which I deliver every Wednesday night.

Sharing, not hoarding, technical knowledge

We publish technical information related to factory production technology and control systems for free, through blogs and videos.

With the belief that “knowledge should be accessible to everyone,” we share practical know-how and real-world troubleshooting cases from our own field experience.

The reason we keep it all free is simple: to help reduce the number of people who struggle because they simply didn’t know.

If you’ve ever thought:

  • “Will this PLC and device combination actually work?”
  • “I’m having trouble with EtherCAT communication—can someone test it?”
  • “I want to try this remote I/O, but we don’t have the testing environment in-house…”

Feel free to reach out!If lending equipment or sharing your configuration is possible, we’re happy to verify it and share the results through articles and videos.

(We can keep company/product names anonymous if requested.)

How can you support us?

Currently, our activities are nearly all unpaid, but creating articles and videos takes time and a proper testing environment.If you’d like to support us in continuing and expanding this content, your kind help would mean a lot.

Membership (Support our radio show)

This support plan is designed to enhance radio with Mr Full.

https://note.com/fulhause/membership/join

Amazon Gift List (equipment & books for content production)

Lists equipment and books required for content creation.

https://www.amazon.co.jp/hz/wishlist/ls/H7W3RRD7C5QG?ref_=wl_share

Patreon (Support articles & video creation)

Your small monthly support will help to improve the environment for writing and verifying articles.

https://www.patreon.com/user?u=84249391

Paypal

A little help goes a long way.

https://paypal.me/soup01threes?country.x=JP&locale.x=ja_JP

Just trying to share things that could’ve helped someone—if only they’d known.

Your support helps make knowledge sharing more open and sustainable.

Thank you for being with us.

soup01threes*gmail.com

https://x.com/3threes2

Technical knowledge shouldn’t be kept to ourselves.

Reference Link

http://soup01.com/en/category/otee_en/

Project Replication

If you want to duplicate the current project, click the … button on the Project List screen → click Duplicate.

Set a new name for the project.

Global Variable Definition

By creating a Global variable, the same variable can be accessed in different programs. Click on the “Add Variable Group” button below to create a new variable group.

Done!A new variable group is created as shown below.

Rename the Global variable group and add the new variable to the Global variable group with the Add Variable button.

Done!Finally, rename the Global variable appropriately as well.

In this article, we created a group of Global variables called GVL and declared a real type variable called rData in it.

Function

Next, add a Function in the project by clicking on the + button in the Tool bar.

The Create an entity screen will appear and Type should be set to Function.

Next, set the Function name in the Name field and click the Save button to save the settings.

Done!Function has been added.

VAR

Define the input/output parameters and other parameters of the Function on the right side of the screen.

In this article, we want to make the Scaling program a function, so we define the following input parameters.

This is the Local variable definition area.

Return Type

Return Type can return the result of an operation after the Function execution is completed.

In this article, the Return value of Scaling’s function is a real number type.

Program

Here is the content of the function.

rTemp:=rRawUpper-rRawLower;

if rTemp <= 0.0 then

rTemp:= 10.0;

end_if;

FCScaling:=(rInput-rRawLower)*((rEngUnitUpper-rEngUnitLower)/rRawUpper-rRawLower)+rEngUnitLower;

MAIN Program

Finally, let’s call the function we just created in the MAIN program. In the figure below, the program is scaling the value 0-32767 to 4-20.

Access Global variable

We want to access the Global variable we just registered from the MAINPRO program, so click the + button next to External.

A new group of variables has been added.

Click on the “Import a Global” button shown below.

Here you can select the Global variable you defined earlier.

Done!Registration is now complete.

Then you can assign the result of your function to the global variable.

Result

Done!

The Global variable rData now also contains the Scaling value.

シェアする

  • このエントリーをはてなブックマークに追加

フォローする