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
thiagoralves
That’s the output of the MatIEC transpiler. It is heavily based on C defines to translate IEC ST code to C, which can add quite a bit to complexity. These functions are time manipulation functions to compare time (LE is less than or equal), add time and subtract time. Time to timespec converts IEC time to the regular C time struct. 

As I said before, it will be a million times easier for you to just write your blocks in PLC language and then let the tool convert it for you. Trying to make sense of the MatIEC output will just give you headache.
Reply 0 0
songyanghua
这是MatIEC转译器的输出。它在很大程度上基于C定义将IEC ST代码转换为C,这可能会增加相当多的复杂性。这些函数是比较时间(LE 小于或等于)、加时间和减去时间的时间操作函数。时间到时间规范将 IEC 时间转换为常规 C 时间结构。

正如我之前所说,用PLC语言编写块,然后让工具为您转换它会容易一百万倍。试图理解 MatIEC 输出只会让您头疼。
Ok, I see. I just think the source code you wrote is very smart and powerful, which is a level I can't reach. So I also want to take this opportunity to learn from you all! I will also try to use PLC languages and tools to generate blocks to achieve my goals. Another problem is that I want to set the range of pulse width. Will a prompt box pop up when this range is exceeded? Can only the error message be displayed below?
Reply 0 0
thiagoralves
You can't popup errors as the runtime does not have that capability. The runtime runs on a PLC, which is a headless device. This is not something that makes sense on a PLC while it is running. What you can do is turning on an error output pin when something wrong happens
Reply 0 0
songyanghua
无法弹出错误,因为运行时没有该功能。运行时在 PLC 上运行,PLC 是一个无外设设备。这在 PLC 运行时没有意义。您可以做的是在发生错误时打开错误输出引脚
What is the way to turn on the error output pin when an error occurs? Are the prompts in the box below the same as when an error occurs during program operation? Or by printing out the error message like print(), is it possible?
Reply 0 0
thiagoralves
You can create an ERROR pin for your block and set it to true when something wrong happens, or something like that. Avoid printing from a PLC, that's not very common, unless you're logging something. I don't know what you mean by "the box below". If you're talking about the console output, that is only relevant for the compilation process. It won't be able to validate signals during the run time.
Reply 0 0
songyanghua
您可以为块创建一个 ERROR 引脚,并在发生错误或类似情况时将其设置为 true。避免从PLC打印,这并不常见,除非您正在记录某些内容。我不知道你说的"下面的盒子"是什么意思。如果您谈论的是控制台输出,则仅与编译过程相关。它将无法在运行时验证信号。
Ok, can you tell me some usage or examples of incorrect pins? I'm going to try and learn how to use them to give some error messages when my pulse width range is exceeded! Thanks!
Reply 0 0
thiagoralves
Screenshot 2023-10-16 at 12.09.53 PM.png
 
Screenshot 2023-10-16 at 12.09.38 PM.png
Reply 0 0
songyanghua
Screenshot 2023-10-16 at 12.09.53 PM.png
 
Screenshot 2023-10-16 at 12.09.38 PM.png
There seems to be a problem with the judgment of PT value here, isn't it written in the form of T #?24.png
Reply 0 0
thiagoralves
Stop editing C source code as you clearly have no idea what you are doing. Work only on the PLC code side to make your life simpler, just like what I've been trying to tell you over the past 50 posts.
Reply 0 0
songyanghua
停止编辑C源代码,因为您显然不知道自己在做什么。只在PLC代码端工作,让你的生活更简单,就像我在过去50篇帖子中一直试图告诉你的那样。
But the logic of how I wrote the code is not wrong. I just tried it and didn't want to modify it. How should I write the type of this PT to determine the size? When it outputs true and the error pin is between 0-300000 ms, it does not write as T#
Reply 0 0
thiagoralves
Screenshot 2023-10-17 at 8.37.08 AM.png
Reply 0 0
songyanghua
alright, thank you very much. I will try to implement it via the method you provided! Because when I tested the TP module again, I found that when the PT value of the pulse width was not given, it seemed that one second had elapsed for the pulse. Can I change this one second? Another question is, can the initial value of the pulse width PT in the timer be set to a fixed value? It can be set to a default value of 150ms or 200ms when no other controls are connected to provide it with a value. When I connect, it will become the value I gave, maybe 1000ms or 2000ms; because when I tested the TP module again, I found that when the PT value for the pulse width is not given, it seems like one second has elapsed for the pulse . can i change for a second
Reply 0 0
thiagoralves
Yes, you can do all that by writing your custom TP block, which in turn can be just a wrapper for the real TP with your own logic around it.
Reply 0 0
songyanghua
是的,您可以通过编写自定义 TP 块来完成所有这些工作,而自定义 TP 块又可以只是真实 TP 的包装器,并带有您自己的逻辑。
What about logical operators like XOR? He has two inputs and can set the input data IN1 to False=0 and IN2 to True=1 without connecting the inputs?
Reply 0 0
songyanghua

Hello, may I ask for your advice? The minimum pulse width time range is 0-300000ms, with a step size of 1ms and a default value of 150ms. You have the time range in this screenshot and the default value is available, but how do you need to set the step size of 1ms or 100ms?

Reply 0 0
Reply