hi. It's kind a object programming in C++. I can remember doing similar staff (moving objects) while I was developing a program for my programming courses some 17 years ago. Back then I was using vectors of pointers. The software simulated the bus network transporting people. I was using this technique of coping the object from one to another while simulating passengers stepping in and out of a given bus.
I had a simillar problem in the past. You have to create structs or variables to connect ant associate with the visuelements. Input and output variables directly from a fb instance maybe couldnt work. The problem could be that if a fb isnt called the used memory isnt defined so its difficult to display in debugging mode. When u associate variables then u reserve the place in memory.
Hi Everyone! I would like to know if is it possible to index a structure like an array. I mean, what about if I need to fill one structure with data comming from an array? I'm thinking that maybe with a FOR loop, I can fill the structure but I cannot found any way to do that. Some tricks to do it? thanking you in advance! Kind regards,
Post or email a code example if you'd like and I can take a look, however, if you want to take an array of 100 data points and put them into a structure, you are probably best just making the structure an array, or make arrays inside the base structure. Hard to give advice without knowing how the data comes in, but that might work. Another option is to use pointers to "point" into the different elements of the structure. Sometimes a simple memcpy instruction can do what you need, though I try to avoid them usually, as pointers can be a bit "fragile" if not used carefully. (Also, never store them, use ADR() each time to avoid pointing to bad data). Maybe make a post on reddit / r/ plc and show what you are trying to do... they are helpful.
do something like: bFoundValue := FALSE for x:=0 to 50 if array[x] == 345 then bFoundValue := TRUE; end_if end_for where 0 and 50 are the limits of the array, and 345 is the value you are looking for.
@@SquishyBrained Thanks for you respond, I have an array: power : ARRAY[0..2] OF INT := [100, 200,300]; and a variable x : INT; . and I want to check if x is in the array.
@@rechard30 n=2; (* assign a value to n equal to size of your array*) bFoundValue:=false; (* initialize bFoundValue with value false, if it gets set to true at end of the scan, meaning x int is fallen into your array*) For i=0 to n If power[i] == x then bFoundValue := true; Else bFoundValue := false; End_if; End_for;
This is video is fantastic, LOVE it. I have a question which buzzes me a lot. I saw you used FB array to handle 2 Pizza Oven, in the real world, each oven has its own buttons, so is there a more advanced way to assign these buttons to its FB instead of writing out every instance FB.
Sunh Hao there are a few ways to get it done, typically you either assign the io globally and "pass in" the io with the FB function call... the other way is to assign the io inside the function blocks and link it up there. neither is perfect, but both work.
Thanks for your reply. Could u be more specific with the second way. When I use OMRON PLC, the IO addresses is stored in DM, then I made a Read_I_Point FB, give it a Input Address, like input point 12.5( it's 125 in Data Memory), then the FB gives back the current state of this input. I'm trying to implement a Read_I_Point FB by using pointer to point to IX0.0, so if I want the state of IX2.4, just add a index to the pointer so it can return the right state back, but I am confused that IX0.0's address is 0 read by ADS(), and QX0.0's address is still 0. Could u tell me is this doable? And , how to do data block move in Beckhoff PLC? Thanks.
You can do it that way, but since I just got started with PLCs about 6 years ago, I never dealt with the 'direct addressing' of IO. TwinCAT supports it, so you could feed in a pointer to the IO or something I'd imagine, but I never do that. I typically just declare them at %I* and %Q*, and then once you build the project they show up in system manager as "linkable" IO. Then, head to the actual devices, and link them to the function block IO. I prefer not to deal with linking IO manually like you are talking about.
Gotcha, Thanks. I have about 20 identical things, and everyone of them has a bunch of IO, so it's painful to type 20 times to put these IO to the instance.
Sunh Hao I understand. I've never had a machine with so many identical things. usually I just bite the bullet and spend an hour linking it. there are better ways but I'm not that up on them. I know there is a c# automation interface for twincat for automating those tasks, but I've not used it. you could check the beckhoff webinars (if using twincat even)
This is very good video. I'm having issues with matching visualization part of the code with PLC. Could you please show what was changed on Visualization side. I'm using Somachine software with your instructions so that might caused some issues as well, but so far I was able to recreate all the examples in previous videos with out major issues. Thank You
+Geronimo Bee Hello, I'm also using Somachine, 4.1 SP 2 . Just curious, which Windows platform is it running on ? I'm running on Windows 10 VM ware Windows 7 virtual machine.
I guess I'm unclear on the problem you are having... can you elaborate? I've not used that software, but the viz I made is rather simple, just a few buttons and indicators. not much logic behind the scenes.
+SquishyBrained Sorry My question was for "+Geronimo Bee" obviously not the way to contact him. I'm working on a PLC / Servo project using structured text for the first time in a non class room environment. Your tutorials are extremely helpful to me. Thanks !
Hi Geronimo Bee, The simplest you can do is change in MAIN the pizza array back to 1 pizza oven like this: fbMyPizzaOven(bLoadPizza:=bLoadPizza , bRemovePizza:=bRemovePizza); (Or change in the visualization on all positions oven i=1 etc. by: fbMyPizzaOven[1].....) & in the visualisation you must change the pizza on deck, oven and done to the following to make it work again: NOT MAIN.fbMyPizzaOven.stPizzaOnDeck.bExist NOT MAIN.fbMyPizzaOven.stPizzaInOven.bExist NOT MAIN.fbMyPizzaOven.stPizzaDone.bExist Good luck!
I don't believe you can, but worth a shot I guess... Just put the new def down below and see if it compiles. Not sure they really differentiate between the name of file and name of struct (or functions, etc) but it would be kinda nice to keep the tree clean if possible. Folders help though.
@@SquishyBrained You can't--I just tried it. However, you can create folders and reference DUTs from one to another, as you say. I have lots of folders now :)
FOR nFor:=0 TO MAX_OVENS-1 DO fbPizzaOven[nFor](bLoadPizza:=bLoad, bRemovePizza:=bRemove); END_FOR This code just runs for once, anyone knows how to fix this and get continuous values from FB instance?
You sure it's only running once? It won't show it running on the screen in your nFor variable but if you do like i=0 before the loop and then i++ inside it you should be able to count how many times it runs.
@@SquishyBrained I've figured it out from stackoverlow, someone had a same problem, they have used arrays for input of FB instace, I've done this and now it's working: bLoad : ARRAY[1..10] OF BOOL; bRemove : ARRAY[1..10] OF BOOL; --------------------------------------------------------------------------------------------------- FOR nFor:=1 TO MAX_OVENS BY 1 DO fbPizzaOven[nFor](bLoadPizza:=bLoad[nFor], bRemovePizza:=bRemove[nFor]); END_FOR Can you tell me how to write parametric code which is resuable and doesn't have static variables in Function Block? I mean if I have more input then I don't add more function block instances.
It appears that structures are actually the labVIEW equivalent of clusters ? Is that right?. Actually clusters sounds more intuitive :) "Functional blocks" more like "Subvi" equivalent?
12:31, Dude I get it, thank you. Much Love. Watching till end now. - Cam
hi. It's kind a object programming in C++. I can remember doing similar staff (moving objects) while I was developing a program for my programming courses some 17 years ago.
Back then I was using vectors of pointers. The software simulated the bus network transporting people. I was using this technique of coping the object from one to another while simulating passengers stepping in and out of a given bus.
Nice. Tc3 has real OOP, but I've not used it much.
Absolutely excellent , thank you very much.
How to link FB instance to visualisation elements, it gives me errors. Also my loop for only runs for once, any suggestions?
I had a simillar problem in the past.
You have to create structs or variables to connect ant associate with the visuelements.
Input and output variables directly from a fb instance maybe couldnt work.
The problem could be that if a fb isnt called the used memory isnt defined so its difficult to display in debugging mode.
When u associate variables then u reserve the place in memory.
Hi Everyone!
I would like to know if is it possible to index a structure like an array.
I mean, what about if I need to fill one structure with data comming from an array? I'm thinking that maybe with a FOR loop, I can fill the structure but I cannot found any way to do that. Some tricks to do it?
thanking you in advance!
Kind regards,
Post or email a code example if you'd like and I can take a look, however, if you want to take an array of 100 data points and put them into a structure, you are probably best just making the structure an array, or make arrays inside the base structure. Hard to give advice without knowing how the data comes in, but that might work. Another option is to use pointers to "point" into the different elements of the structure. Sometimes a simple memcpy instruction can do what you need, though I try to avoid them usually, as pointers can be a bit "fragile" if not used carefully. (Also, never store them, use ADR() each time to avoid pointing to bad data).
Maybe make a post on reddit / r/ plc and show what you are trying to do... they are helpful.
Do we have to define stPizzaOnDeck,, in STRUCT_PIZZA? Im getting an error "no initial value for constant value 'stNULL_PIZZA' "
Bruck not sure what you did, but it thinks you made a constant. Check the Github if you can't work it out.
yeah I checked it out It works!!
how to Check if an array (INT) contains a specific value
(INT)?
do something like:
bFoundValue := FALSE
for x:=0 to 50
if array[x] == 345 then
bFoundValue := TRUE;
end_if
end_for
where 0 and 50 are the limits of the array, and 345 is the value you are looking for.
@@SquishyBrained Thanks for you respond,
I have an array: power : ARRAY[0..2] OF INT := [100, 200,300];
and a variable x : INT; .
and I want to check if x is in the array.
@@rechard30
n=2; (* assign a value to n equal to size of your array*)
bFoundValue:=false; (* initialize bFoundValue with value false, if it gets set to true at end of the scan, meaning x int is fallen into your array*)
For i=0 to n
If power[i] == x then
bFoundValue := true;
Else
bFoundValue := false;
End_if;
End_for;
Thanks for the video. How do I use the DT as well as TIME variables? Thank you
Andy Leinen watch episode 10 :)
Excellent
Interesting presentation. How do you integrated codesys to visual studio? It works perfect.
This is video is fantastic, LOVE it.
I have a question which buzzes me a lot. I saw you used FB array to handle 2 Pizza Oven, in the real world, each oven has its own buttons, so is there a more advanced way to assign these buttons to its FB instead of writing out every instance FB.
Sunh Hao there are a few ways to get it done, typically you either assign the io globally and "pass in" the io with the FB function call... the other way is to assign the io inside the function blocks and link it up there. neither is perfect, but both work.
Thanks for your reply. Could u be more specific with the second way.
When I use OMRON PLC, the IO addresses is stored in DM, then I made a Read_I_Point FB, give it a Input Address, like input point 12.5( it's 125 in Data Memory), then the FB gives back the current state of this input. I'm trying to implement a Read_I_Point FB by using pointer to point to IX0.0, so if I want the state of IX2.4, just add a index to the pointer so it can return the right state back, but I am confused that IX0.0's address is 0 read by ADS(), and QX0.0's address is still 0. Could u tell me is this doable? And , how to do data block move in Beckhoff PLC? Thanks.
You can do it that way, but since I just got started with PLCs about 6 years ago, I never dealt with the 'direct addressing' of IO. TwinCAT supports it, so you could feed in a pointer to the IO or something I'd imagine, but I never do that. I typically just declare them at %I* and %Q*, and then once you build the project they show up in system manager as "linkable" IO. Then, head to the actual devices, and link them to the function block IO. I prefer not to deal with linking IO manually like you are talking about.
Gotcha, Thanks. I have about 20 identical things, and everyone of them has a bunch of IO, so it's painful to type 20 times to put these IO to the instance.
Sunh Hao I understand. I've never had a machine with so many identical things. usually I just bite the bullet and spend an hour linking it. there are better ways but I'm not that up on them. I know there is a c# automation interface for twincat for automating those tasks, but I've not used it. you could check the beckhoff webinars (if using twincat even)
This is very good video. I'm having issues with matching visualization part of the code with PLC. Could you please show what was changed on Visualization side. I'm using Somachine software with your instructions so that might caused some issues as well, but so far I was able to recreate all the examples in previous videos with out major issues.
Thank You
+Geronimo Bee
Hello, I'm also using Somachine, 4.1 SP 2 . Just curious, which Windows platform is it running on ? I'm running on Windows 10 VM ware Windows 7 virtual machine.
I guess I'm unclear on the problem you are having... can you elaborate? I've not used that software, but the viz I made is rather simple, just a few buttons and indicators. not much logic behind the scenes.
+SquishyBrained Sorry My question was for "+Geronimo Bee" obviously not the way to contact him.
I'm working on a PLC / Servo project using structured text for the first time in a non class room environment. Your tutorials are extremely helpful to me.
Thanks !
Hi Geronimo Bee,
The simplest you can do is change in MAIN the pizza array back to 1 pizza oven like this:
fbMyPizzaOven(bLoadPizza:=bLoadPizza , bRemovePizza:=bRemovePizza);
(Or change in the visualization on all positions oven i=1 etc. by: fbMyPizzaOven[1].....)
& in the visualisation you must change the pizza on deck, oven and done to the following to make it work again:
NOT MAIN.fbMyPizzaOven.stPizzaOnDeck.bExist
NOT MAIN.fbMyPizzaOven.stPizzaInOven.bExist
NOT MAIN.fbMyPizzaOven.stPizzaDone.bExist
Good luck!
SquishyBrained an you create multiple structs in one DUT?
I don't believe you can, but worth a shot I guess... Just put the new def down below and see if it compiles. Not sure they really differentiate between the name of file and name of struct (or functions, etc) but it would be kinda nice to keep the tree clean if possible. Folders help though.
@@SquishyBrained You can't--I just tried it. However, you can create folders and reference DUTs from one to another, as you say. I have lots of folders now :)
Gear Videos just my level.
FOR nFor:=0 TO MAX_OVENS-1 DO
fbPizzaOven[nFor](bLoadPizza:=bLoad, bRemovePizza:=bRemove);
END_FOR
This code just runs for once, anyone knows how to fix this and get continuous values from FB instance?
You sure it's only running once? It won't show it running on the screen in your nFor variable but if you do like i=0 before the loop and then i++ inside it you should be able to count how many times it runs.
@@SquishyBrained I've figured it out from stackoverlow, someone had a same problem, they have used arrays for input of FB instace, I've done this and now it's working:
bLoad : ARRAY[1..10] OF BOOL;
bRemove : ARRAY[1..10] OF BOOL;
---------------------------------------------------------------------------------------------------
FOR nFor:=1 TO MAX_OVENS BY 1 DO
fbPizzaOven[nFor](bLoadPizza:=bLoad[nFor], bRemovePizza:=bRemove[nFor]);
END_FOR
Can you tell me how to write parametric code which is resuable and doesn't have static variables in Function Block? I mean if I have more input then I don't add more function block instances.
It appears that structures are actually the labVIEW equivalent of clusters ? Is that right?. Actually clusters sounds more intuitive :)
"Functional blocks" more like "Subvi" equivalent?
Engineered Systems Development Inc. yes, and yes. Very similar programming concepts between different vendors.