songyanghua
Hello, when I referenced the official document ADDING NEW BLOCKS TO OPENPLC EDITOR'S LIBRARY to create a custom block, I found an error during compilation and found that TEST was not found. After checking, I followed the requirements of each step to set it. On the Win11 system, I hope you can help me. I haven't found the reason for several days!
0e3299f2fb9758a349c83a334cb4c0dd.png17c9f4a5a9e78bda26026cd8e97fa14d.png49e31f5864b567d4db9f47ca35ae5488.png

Delete that module to pass

Reply 0 0
songyanghua
Ok, indeed I just need to modify some logic as shown below. The delay down timer has 8 groups of inputs and outputs, each group is an independent timer (for example, IN1 and OUT1 are independent timers). When the input signal is on a rising edge, the output is set to 1. When the input signal is on the falling edge, the output remains set to 1 and starts counting, if the input remains low for the timed time, the output will move to low after the set delay value. If the input moves high again within the timing time, the timing time will be reset. The parameters are as follows (each input and output is an independent parameter configuration): Minimum pulse width time range: 0-3600000ms, step size 10ms, default value is 150ms. Input and output data are of type Boolean, and the default value for input data is False=0. I just want to implement this functionality but I don't know how to modify it in code. Please advise!
11.png
Reply 0 0
thiagoralves
Indeed, for that type of functionality you don't have to modify any code on OpenPLC Editor. You can implement this logic on ladder logic itself (or any other language provided by the editor like Structured Text, Function Block Diagram, etc). Start by picking the language you want to write this thing on. Then create a new Function Block on that language (grey plus icon on project tree -> Function Block). Then create 8 inputs and 8 outputs for your block on the variable panel. You might also need an input to provide the temporization time (I don't know if you want this time to be hardcoded on the block or provided by the user). Then it will be just a matter of connecting several TOFs to your inputs and adding any extra logic you might want.
Reply 0 0
songyanghua
事实上,对于这种类型的功能,您不必在OpenPLC编辑器上修改任何代码。您可以在梯形图逻辑本身(或编辑器提供的任何其他语言,如结构化文本、功能块图等)上实现此逻辑。首先选择你想用什么语言来写这个东西。然后在该语言上创建一个新的功能块(项目树上的灰色加号图标 ->功能块)。然后在变量面板上为您的块创建 8 个输入和 8 个输出。您可能还需要一个输入来提供时间化时间(我不知道您是否希望此时间在块上硬编码或由用户提供)。然后,只需将多个 TOF 连接到您的输入并添加您可能需要的任何额外逻辑即可。
I understand what you mean, but what I want is to integrate this module into the compiler in a custom form so that I don't have to copy and paste the method blocks you mentioned every time I recreate the project. Integrated into the compiler, no matter how many projects are re-created, just drag them out.
Reply 0 0
thiagoralves
Start by creating the blocks first and making sure they work and compile just fine. Once you have that, you can use the OpenPLC Import Tool I mentioned earlier to import your custom block to the OpenPLC library. If you have the original OpenPLC downloaded from autonomylogic.com installed, then it will work just fine.
Reply 0 0
songyanghua
首先创建块,并确保它们正常工作和编译正常。一旦你有了它,你可以使用我之前提到的OpenPLC导入工具将你的自定义块导入到OpenPLC库中。如果您安装了从 autonomylogic.com 下载的原始OpenPLC,那么它将正常工作。
To create a block, I want to directly modify the source code's logic method as shown in the screenshot above to meet my requirements for these 8 inputs and manually add them to my OPENPLC project. This will help me understand the entire operation better. Thank you very much, if I want to manually modify the structured programming code, which parts of the screenshot above need to be changed to achieve my purpose?
Reply 0 0
thiagoralves
It is kinda pointless to help you if you keep refusing to take in my advices. Follow the directions I sent you. Create your block on the editor, export your project, and then use the OpenPLC Import tool to import your block to the OpenPLC library. Then you can manually inspect the files that were modified by the tool (refer to the guide on Documentation for the manual procedure and modified files) if you really want to understand the whole process better. However, the tool should be able to do it all automatically for you. You don't have to modify any source code yourself.
Reply 0 0
songyanghua
如果你一直拒绝接受我的建议,帮助你是没有意义的。按照我发给你的指示。在编辑器上创建块,导出项目,然后使用 OpenPLC 导入工具将块导入到 OpenPLC 库。然后,如果您真的想更好地了解整个过程,您可以手动检查该工具修改的文件(请参阅文档指南以了解手动过程和修改的文件)。但是,该工具应该能够自动为您完成所有操作。您不必自己修改任何源代码。
Ok, after your answer, I agree with your suggestion, this may be less errors for me, but I am not very comfortable with this method of creating 8 inputs and 8 outputs on the variable panel. Familiar, Mine is the Win11 operating system, and where to enter this command to import python 3 import_tool.py <filename.st>, if it is convenient for you, can you take a few minutes to record a simple video for my reference, And make it clearer and clearer for anyone who wants to do this in the future? Thanks!
Reply 0 0
songyanghua
13.png

I have downloaded it but I don't know which entry to insert. ST files from
Reply 0 0
songyanghua
14.png
 
Is this the correct way to create blocks?
Reply 0 0
songyanghua
How to import the generated ST?

15.png
Reply 0 0
thiagoralves
If your block compiles and run the way you want it to run, then yes, that’s the correct way of doing it. To export the project into an .st file you need to click on the orange down arrow button on the toolbar:
IMG_0039.jpeg
 
Once you have the .st file, copy it over to the same folder where your OpenPLC Import tool is located. Then open command prompt (on Windows) or Terminal (on Linux), navigate to the folder where the OpenPLC Import tool is located, and then finally type
python3  import_tool.py  <your st file>
 
Keep in mind that you must have Python3 installed in your system for this command to work.
Reply 0 0
songyanghua
如果你的块按照你想要的方式编译和运行,那么是的,这是正确的方法。要将项目导出到 .st 文件中,您需要单击工具栏上的橙色向下箭头按钮:
IMG_0039.jpeg
 
获得 .st 文件后,将其复制到 OpenPLC 导入工具所在的同一文件夹中。然后打开命令提示符(在Windows上)或终端(在Linux上),导航到OpenPLC导入工具所在的文件夹,最后键入
  1. 蟒蛇3 import_tool。.py <您的 st 文件>
 
 
请记住,您必须在系统中安装 Python3 才能使用此命令。
OK, thank you for your answer. Two more questions:
1. Would it be enough to put our custom TOF8 block here for program0? Do you need to connect to another line?
2. Is the screenshot below placed in the directory for this action?
3. I generated 2 STs, which one is the correct ST? still need both
4. Can any version of Python 3 be used?16.png17.png
18.png19.png
Reply 0 0
songyanghua
20.png
Is there an error? The terminal did not respond?
Reply 0 0
thiagoralves
1. All you have to do is to declare your block, you don't have to place it in a program. However, it would be interesting to write a short program using it just to make sure the block works as intended, otherwise you might end up with a block that doesn't work as you wanted it to work. 
 
2. Yes
 
3. OpenPLC Editor only generates one .st when you click on the orange down arrow. Please use OpenPLC Editor otherwise this process won't work.
 
4. Any recent version of Python 3 should do. I see you have Python 3.11, that should work just fine.
 
On your last screenshot, that's not how you should do it. The < > are just placeholders for the actual name of your .st file. You should not include them in your command. For example, if your .st file is called my_program.st then your command should be:
Reply 0 0
songyanghua
1.您所要做的就是声明您的区块,您不必将其放置在程序中。但是,使用它编写一个简短的程序以确保块按预期工作会很有趣,否则您最终可能会得到一个无法按预期工作的块。
 
2. 是
 
3. OpenPLC 编辑器仅在单击橙色向下箭头时生成一个 .st。请使用OpenPLC编辑器,否则此过程将不起作用。
 
4. 任何最新版本的 Python 3 都应该这样做。我看到你有Python 3.11,应该可以正常工作。
 
在上一个屏幕截图中,这不是您应该这样做的方式。< >只是 .st 文件实际名称的占位符。不应将它们包含在命令中。例如,如果您的 .st 文件名为 my_program.st,那么您的命令应该是:
  1. python3  import_tool.py   my_program.st
 
 
Okay, thank you very much for your patient answer. I have gained some understanding, but if I use this method, how can I add modules that are not included? For example, I want to add a fixed pulse width timer PT2, where each input and output is an independent timer (for example, IN1 and OUT1 are independent sets of timers). When the input receives the rising edge of the signal, the output is set to 1. Regardless of how long the high level signal at the input continues, the duration of the high level output is a fixed value. Minimum pulse width time range: 0-3600000ms, step size 10ms, default value is 150ms.
The input and output data are of BOOLEAN type, and the default value for input data is False=0.
Reply 0 0
Reply