-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create library and refactor code and change it to OOP... #1
Comments
Hello @runtimevic, |
Hi @runtimevic Timer Library: Bundling timers into a single FB and bringing it into line with OOP: Refactoring: |
Hello @fisothemes
I think we should unify the names of the variables, tell me which of the 2 forms do you like the most? for us to change it... |
I think we should stick to the PLC programming convention used by Beckhoff, they already have pre-built Static Analysis configuration file, which saves us the headache of producing our own and makes reviews easier. The downloads for the config files are found in the link I gave.
|
|
bStart |
|
Yh I personally don't like it either, but in terms of PLC programming Hungarian notation is pretty much a thing to overcome the pitfalls of the language and it's implementations such as being case insensitive, difficult to read in plain text (metadata everywhere on the file) and potential clashes with reserved keyword, local enums and Tc2 stuff. |
|
With. So bStart unfortunately |
|
bStart, bPause, tPreSet, bDone, tElapsed. We'll stick with Beckhoff's conventions, https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/12073947403.html&id=3338831657965116106 |
https://alltwincat.com/2019/02/11/plc-naming-conventions/
bStart, bPause, tPreSet, bDone, tElapsed.
|
Adding i/o prefixes: Passing as OOP: I'm pretty much happy with everything else. |
Give me a few days and I'll send you the changes so you can see what you think... |
I have sent you a version, tell me what you think?, https://twincontrols.com/community/twincat-knowledgebase/factory-method-design-pattern/#post-470 Tomorrow if I have time I'll try it and if it works I'll send you a new version... |
I'm gonna run some tests them give me a moment. |
I love the idea of a polymorphic timer. I can see this coming in handy in situations when you have to create dynamic timers. One suggestion would be to add a type property to the base Timer class. It will allow for some introspection which will be be handy for situation like these: fbTimerCollection
.Insert(fbRStopwatch)
.Insert(fbRTimer);
fbTimerCollection.Get(14, ipTimer => ipTimer);
CASE ipTimer.Timer_Type OF
E_Timer_Type.Stopwatch:
// Do something
E_Timer_Type.RTimer:
// Do something
ELSE
// Default
END_CASE I use this pattern regularly when creating steps for sequencers and retentive timers ensure that a process has actually run it's course, even if it is paused.
Another thing is to probably reduce the use of fbRStopwatch.Input REF= stInput;
fbStopwatch.Input REF= stInput;
fbRStopwatch.Run();
fbStopwatch.Run();
stROutput := fbRStopwatch.Output;
stOutput := fbStopwatch.Output; This could cause unintended side-effects especially when working with dynamic memory. My one big gripe with Beckhoff at the moment is that they haven't fixed the STRUCT access bug Codesys fixed a long time ago, the one were that makes the compiler throw the towel when you try to access properties that are structs and methods that return structs. One way I solve this is by replacing STRUCTs with FB's with only properties. Aside from the 4-16bytes that are object headers mainly used for RPCs, they're the same in memory. Tomorrow, if I have time, I might investigate what happens when Overall, I like the idea and I have learnt quite a bit. Also, I didn't even know about the twincontrols website, thanks for that, And thanks again for contributing. |
Hello @fisothemes
You will tell me... |
Hello @fisothemes |
Hello, I'm trying to get up to speed with the changes you made. I like the changes so far. I didn't know you could access members of structs in property structs by using |
There are 4 things I checked for when running the timers to ensure that they run correctly.
Writing unit tests for this might be tricky. |
Hello @fisothemes,
congratulations for spreading your work, I think it is the right way to improve.
I liked your idea implementing timers...
Would you like me to create a single FB that groups them all..., refactoring the code and passing it to the OOP paradigm and also create a timer library...
Tell me if you are interested and we can do it collaborating or I do it and see if you like it...
I wait your answer...
The text was updated successfully, but these errors were encountered: