lc625

You might know the OSCAT library (http://www.oscat.de). If not: This library contains a vast number of different functions (FC) and function blocks (FB) (didn´t count them, but probably up to 1000)! It free for private and commercial use. In the download section you will find “ready to use” libs for Codesys, S7,  PCWorx and a *.xml file as well. The three major topics (basic, building and network) are divided int several sub-sections. Every single FC or FB is described in delated documents, provided in English as well.

Unfortunately, no lib for OpenPLC.

Because I found out this lib to be very helpful in many cases I started recently converting it, in order to use it with OpenPLC.

Attached you´ll find the whole maths-section of the OSCAT basic library.

It contains 65 mathematical functions which might be very useful. I know it´s only 10% of the whole lib, but without starting you will not get anyhere.

As far as I know, there is no way to “import” a whole library into OpenPLC as it is. I followed Mr. Alves’ recommendations and put all the created FC / FB´s into an empty project (“OSCAT Maths” in the zip folder). To use the FC / FB´s in your project just copy-paste (C/P) the desired item into your project. You might receive an error while simulation in some cases. Don´t worry, it´s typical for OSCAT, that some FC / FB refer to another one. Just take a look to the ST code, you will find a comment, which FC / FB is required (hope I didn´t forget any 😊). C/P the missing one as well and you will be fine.

Be aware, that due to the missing import possibility everything must be done manually (C/P ST-code, modify code in some cases, declaring variables, checking and running simulation...). This might be prone to errors. I tested every FC / FB, but you never know…So don´t beat me up if you find a bug, just fix it and post. I added a brief description to every FC / FB. If you need more detailed information, download the regarding document (in this case Oscat basic Ver. 3.33; German PDF, English epup) form the download section (http://www.oscat.de).

To enrich this great OpenPLC project I would like to invite everyone who is interested in, to convert a part of the library. I suggest to post the regarding section here to prevent double activity (E.G: I´m going to convert the xxxxx-section of the Oscat lib). Myself I´m going on with the arithmetic functions.

The next lines are heading more or less to Mr. Alves himself.

There is a noteworthy number of important FC /FB´s using the basic Function “T_PLC_MS” or “T_PLC:US”. I´ve got no idea how to make OpenPLC compatible FC out of them. I attached a PDF file (“Mr_Alves”) containing the ST code of one example FB and the ST code of “T_PLC_MS” and “T_PLC_US” and the detailed description as well. There are two different approaches to T_PLC_MS and US. One I took from the lib for PLC Worx and one from the Codesys lib. I tried both, but without success. It would be great if you could help in this case. If this issue is solved, I can go on with the more complex FB´s. 

Quote 0 0
thiagoralves
Fantastic work lc625! About the T_PLC_US, OpenPLC runtime does not have a time() function implemented. I can work on creating one, but it will go to the bottom of my tasks list and might take a while to implement it. Meanwhile, you can derive a time() function by using %ML1025 special function which holds the number of scan cycles executed since the runtime started. Check https://openplc.discussion.community/post/support-for-rtc-on-special-functions-9900466?&trail=15

If you multiply %ML1025 with the task scan cycle period, you will get precisely the time in milliseconds, which is exactly the same output of the time() function.

PS: I've just created a special topic to encourage users share their custom Function Blocks. Can you please repost your code in there? Here is the link: https://openplc.discussion.community/?forum=751065
Quote 0 0
lc625
Repost is done. Additionally a few recources more. 
I will have a close look to the new registers. To T_PLC_MS and T_PLC_US as well. I will try to create two function blocks to replace the OSCAT ones. Unfortunately I´m sure that I will have to ask you for revision. 
Quote 0 0
netsapiens

Wow! Fantastic! 
Can I expect a PLC excuted at an absolute time?  

Quote 0 0
thiagoralves
OpenPLC on Linux (given the right configurations) already executes at an absolute time. It respects the cyclic time defined in the program task. However, it does not report back the internal timer to the user program in the form of the time() function. This is the function needed to implement T_PLC_MS and T_PLC_US. I'm suggesting, as a work around, to use the cycle counter instead.
Quote 0 0
lc625

Hi Mr. Alves

You gave me some ideas how to deal with the “time() problem”. I tried to find a solution for this issue. Please cast a critical eye over the FB´s in the ZIP-file. I´m curious about your opinion.

Three questions from my side:

1. Trying to test the FB´s, I get nothing else but a “0” in %ML1025 (using windows runtime, raspi not tested)

2. Is there a possibility to write the cycle time into “PLC_CYCL_TME” automatically? It would prevent timing errors, if task cycle time in res0 is changed without thinking about PLC_CYCL_TIME.

3. What will happen if you have more than one task with different cycle times? I think this might be the major difference between time() and this temporary solution.

Quote 0 0
thiagoralves
I'm in a hurry right now and haven't checked the .zip file, but I can tell you that %ML1025 only works under the OpenPLC Runtime, not on the simulation inside the editor. It will work on Windows as well, as long as it is the Runtime, not the Editor
Quote 0 0
lc625
You might have recognized that I converted some more section of the OSCAT lib already. There is one more almost ready, but one FB is using the T_PLC_MS FB. I don´t want to post stuff which is not working. So I'd rather wait for your judgement according to my approach. Meanwhile I'm working on more complex sections of the  lib: In there sections OSCAT defines own data types (a lot of them).
Could you please enable copy / paste for Data types in the editor (if it's possible for variables as well :-))? It would be a great help!
If I want to declare a data type of string with a definite length (e.g. 10), is this the right way? "DatatypeXY"; derivation type directly; base type string; initial Value (10).

PS: You posted: https://openplc.discussion.community/post/monitoring-update-10259223?pid=1309429983 Does this solve my %ML1025 issue as well? For updating the windows runtime, is it possible to clone the repository an run instal.sh again? as far as I know there is no upgrade / update functionality in Cygwin. I wasn't very lucky with the installer and the manual way successful.
Quote 0 0
thiagoralves
lc625 wrote:

Could you please enable copy / paste for Data types in the editor (if it's possible for variables as well :-))? It would be a great help!

You can copy and paste an entire POU, including all its variables and code. All you have to do is right click on the POU at the left panel tree and select "Copy POU". To paste it, right click on your project (the top item at the tree hierarchy on the left panel) and select "Paste POU". This is the ideal way to move FB from one project to another.
lc625 wrote:

If I want to declare a data type of string with a definite length (e.g. 10), is this the right way? "DatatypeXY"; derivation type directly; base type string; initial Value (10).

As far as I know, you cannot define the size of a STRING in IEC 61131-3. The size is automatically defined according to the string length. The initial value field on the Data Type configuration is related to the initial value that the variable will have upon initialization.
lc625 wrote:

PS: You posted: https://openplc.discussion.community/post/monitoring-update-10259223?pid=1309429983 Does this solve my %ML1025 issue as well? For updating the windows runtime, is it possible to clone the repository an run instal.sh again? as far as I know there is no upgrade / update functionality in Cygwin. I wasn't very lucky with the installer and the manual way successful.

Yes, the update will solve your %ML1025 issue on the monitoring page (kinda). %ML1025 is a special function, out of the modbus range, so the monitoring page cannot display it even after the update. What you can do is declare another variable on %ML0 and move the contents of the %ML1025 variable to it.

You can update your runtime manually on cygwin. Just make sure you remove the folder with the current installation and git clone it again:
rm -Rf OpenPLC_v3
git clone https://github.com/thiagoralves/OpenPLC_v3.git
cd OpenPLC_v3
./install.sh win


For your T_PLC project, I tried it and it didn't work. It turns out that there are some issues with DWORD conversion functions. I'll have to fix that later. I'm attaching my own T_PLC project here. There are a few issues with it that does not make it a perfect conversion from the OSCAT library one:
1. My approach uses Function Block instead of Function. The reason for that is because IEC 61131-3 won't allow external variable declaration inside functions. Therefore, when using the block, instead of just calling T_PLC_MS() as you would normally do with a function, you will have to declare it first (as it is a Function Block) and then use T_PLC_MS._T_PLC_MS.
2. The T_PLC_MS function from OSCAT outputs a DWORD variable. Due to DWORD bugs on the runtime I'm using UDINT instead. DWORD and UDINT are equivalent (same size, same sign), but might need conversion depending on how they are used. I suggest avoiding DWORD usage at all costs for now.
Quote 0 0
lc625

Hi Mr. Alves,

 

Yes, it is a dammed thing with DWORD. I must apologize for bothering you with these basic things. I have to admit, that I’m quite familiar with CODESYS. It turns out that CODESYS is not adhering to the IEC very closely. In fact, I never experienced any problems with arithmetic operations with DWORD using CODESYS. But to be honest you only calculate with numbers like INT, UINT and so on. To learn this, I had to pay my own fee. I had to re-convert almost the whole OSCAT Date and Time section again due to this. The OSCAT Lib for PLCWorx does exactly this: They got rid of all the DWORD stuff. They only rely on UDINT. In summary their approach is quite similar to yours. However, they are using PLC ticks and not cycles (might solve the problems I mentioned above). (https://d28lcup14p4e72.cloudfront.net/203128/4752127/Mr_Alves.pdf)

 

The Copy / Paste thing: I attached the next but one OSCAT section to be posted. It is not ready and not working without failures, just a sample. Please try to copy / paste all the data types. If I try out the way you suggested, I got copied all local variables but not the custom data types.

Quote 0 0