Post by gilbertamine on Comparing Arrays of structure
CODESYS Forge
talk
(Post)
Hi Everybody, I'm looking for a simple way of comparing two array of a structure. My structure is define like this : TYPE Positions_T : STRUCT PosX: DINT; PosY: DINT; PosZ: DINT; END_STRUCT END_TYPE I have multiples Var : ARRAY [0..220] OF Positions_T, that I need to compare quickly. I don't really want to do a Loop that goes by every 220 points and compare each one of them so I was wondering if there is another way. I came accross the MEM.Compare function, but it require to know the size in Bytes of the memory, and I don't know how to do that... Has anybody an idea on how to do the comparing easily ? Thanks in advance
Last updated: 2024-08-22
Post by dandyk on Dynamic Images
CODESYS Forge
talk
(Post)
Hello, I have very similar problem, but it seems that your solution does not work for me. I am using TwinCAT XAE Shell v3.1.4024.55 and TwinCAT Runtime. Sorry for writing here on codesys forge, but since I found the only relevant topic here and since TwinCAT is almost the same with CODESYS in many applications, I chose to write here. I simply need to dynamically update image in visualization based on camera trigger (I am doing a machine vision application). Camera triggers an image, my program processes it (applies thresholding, draws contours etc...) and saves the processed image in the runtime location (the same one you were mentioning). This was done successfully. I need to make it work at runtime, while the program is executing and I need to refresh the image in the visualization each time camera triggers a new image and program processes it. When I create image element in the visualization and define the bitmap ID variable as STRING which contains the image ID defined in the image pool, then it displays the image in the image pool, but does not work at runtime, while the program is executing. I also used the Bitmap Version. I declared it in Global variable list as integer with initial value of 0 and wrote the variable in the bitmap version in the image element in visualization. Each time new image is saved to the runtime location, I wrote a program to increment Bitmap Version by 1. It increments and the image does not update in the visualization, unfortunately. I think that bitmap version is working correctly and deletes the cached image as it is supposed to, but the Image Pool does not update the image ID with the new image... the path to the image is always the same... only the actual image changes with the same file name. Image Pool is not dynamic and cannot refresh the image in the path to the actual one at runtime. How can I refresh the image ID in the image pool at runtime? Bitmap version only deletes cached image and reloads the image from the image ID, but the image ID has the same image, because image pool won't update at runtime. Do you know any solution to this problem?
Last updated: 2024-04-06
Post by ofey on EtherCAT fieldbus
CODESYS Forge
talk
(Post)
Hi, everyone! I'm trying to set up a PLC controller and a connection to an EtherCAT slave device in Codesys. I want to create a flexible program that I can upload to multiple controllers with different remote IO connected (same program). On one plant i may have 5 AI-cards and 3 DO-cards, and on another I may have 4 AI-cards and 2 DO-cards. For not needing to maintain several different programs wih different devices defined in the program (one for each set up) I thought that using a remote IO would make it easier having a single program. That way I could refer to different memory addresses instead of predefined slots/channels and IO's, that would give me errors if there was a different IO on the plant than what the program expected. When I tried setting up the etherCAT master, I saw that I had to define the etherCAT slave devices with the different IO'cards for me to be able to refer to the memory addresses in a PRG. Exactly what I was trying to avoid. My setup is something like a program that can handle 16 separate pump controls. In a year maybe 6 plans get deployed, and depending on how large the project is, the number of pumps can vary between 4 and 16. And the managers dont want to have IO's for all 16 pumps on every cabinet, and I dont want to maintain 16 separate projects files in case of updates etc. I thought the best way to tackle this was having a single project that read/write data to the different pump IO's by remote IO (fieldbus ethercat) addresses. And the number of pump controls are activated by an external GUI. If pump 1-6 is activated by the GUI, then the PLC-program tries to read/write input/outputs from predefined addresses for the expected IO's. My test setup is a PFC200 WAGO controller and a EtherCAT fieldbus coupler (750-354) with some IO. I hope I didn't explain this too horrible, and if there is a more easy and elegant solution for this challenge I appreciate a feedback on this.
Last updated: 2024-04-08
Post by sturmghost on Visualization using methods and cyclic ST-calls
CODESYS Forge
talk
(Post)
Im looking for a way to implement ST-code into the visualization element without creating a helper POU or method in my device/application tree. Like visualization properties are evaluated at each VISU_TASK cycle I want to be able to create own ST code which interacts with the visualization interface variables. To be more specific I want to have a property which executes user defined ST-code at each VISU_TASK cycle exactly like its already possible for Input Configuration on various mouse and dialog events. Also a property for initialization (so only executed once) and a timed property would be nice. With the situation right now I'll have to create a POU function which handles the ST-code and misuse a property, like the text variable, to execute this POU function at each VISU_TASK cycle. Or does it exist and I don't know it?
Last updated: 2023-10-02
Post by timo on Visu: Angepasster Button mit Statusanzeige - welche Möglichkeiten gibt es?
CODESYS Forge
talk
(Post)
Hallo, Ich gehe gerade Möglichkeiten durch, wie ich Buttons so erstellen kann, dass ich sie nachträglich möglichst einfach bearbeiten kann um z.B. die Farben des Aktiven/Inaktiven Zustandes darzustellen. Die Buttons bestehen aus einem Hintergrund als Farbverlauf, einem Text und einem Icon. Ich habe zuerst den ESC Image Button verwendet, aber auch hier müsste ich nacheinander alle Buttons bearbeiten, wenn ich z.B. die Hintergrundfarbe anpassen will. Jetzt habe ich die Buttons als einzelne Visualisierungen erstellt und in der Visu jeweils als Frames eingeblendet. Den Zustand kann ich dann durch unsichtbare Elemente in der Buttonvisu darstellen. Weil hinter jeder Buttonvisu ein Frame meines Hintergrundes liegt, kann ich die einfach anpassen. Siehe Bild- der Frame ist der graue Hintergrund, das Rechteck ist die Umrandung für den Status mit einer transparenten Füllfarbe. Gibt es da eine einfachere Möglichkeit die Elemente zu verknüpfen, sodass ich einen Button habe, den ich nachträglich möglichst einfach abändern kann? Bei den Buttons bei denen ich keine Icons einblende, kann ich direkt den Text auf den Hintergrundframe setzen. Wenn ich hier aber das farbige Randungsrechteck für den Status über das Frame liege, verdeckt es diesen natürlich. Gibt es eine Möglichkeit Elemente so einzublenden, dass dahinter liegende Elemente angeklickt werden können? Alternativ muss ich die Aktion auch noch mit dem überlagertem Element verknüfen.
Last updated: 2024-04-22
Post by caprez95 on Deleting the trend recording history
CODESYS Forge
talk
(Post)
Hallo Ich möchte eine laufende Trendaufzeichnung stoppen, den Inhalt löschen und Trend-Diagramm auf 0 zurücksetzen. Laut Codesys soll das mit dem folgenden Code möglich sein: You can insert an input element in the visualization which the operator can use to delete the previous value recording in the trend visualization at runtime. The curve displayed until then is removed and the display starts over. In the application (example: in the program PLC_PRG), implement the following code: itfTrendRecording : ITrendRecording; itfTrendStorageWriter : ITrendStorageWriter; itfTrendStorageWriter3 : ITrendStorageWriter3; sTrendRecordingName : STRING := 'TrendRecording'; itfTrendRecording := GlobalInstances.g_TrendRecordingManager.FindTrendRecording(ADR(sTrendRecordingName)); xClearHistoryTrend: BOOL; IF xClearHistoryTrend THEN itfTrendRecording := GlobalInstances.g_TrendRecordingManager.FindTrendRecording(ADR(sTrendRecordingName)); IF itfTrendRecording <> 0 THEN itfTrendStorageWriter := itfTrendRecording.GetTrendStorageWriter(); IF __QUERYINTERFACE(itfTrendStorageWriter, itfTrendStorageWriter3) THEN itfTrendStorageWriter3.ClearHistory(); END_IF END_IF In the visualization of the trend recording, add a button for deleting the previous curve. Configure its Toggle property with the variable PLC_PRG.xClearHistoryTrend. ⇒ When xClearHistoryTrend is set to TRUE, the previously recorded curve is deleted. The recording immediately starts again. Dies löscht auch die Daten vom Trend, aber das Diagramm wird nicht auf 0 zurückgesetzt, sondern läuft einfach da weiter wo man gestoppt hat. Braucht es für den Diagramm-Reset noch einen zusätzlichen Befehl? Gruss
Last updated: 2024-06-11
Post by alexgooi on Codesys OPC DA server requires more then 2 GB of ram
CODESYS Forge
talk
(Post)
Dear Forum, We are currently running into a problem that the CODESYS OPC DA server is running out of RAM (larger than 2 GB). We have a setup of 10 Codesys controllers which features around 300.000 discoverable tags per controller. We are only interested in 10 percent of the tags to be communicated to the OPC-server, this is due to the fact the program consists of arrays of objects which on their part implements arrays of objects, simply reducing the number of discoverable tags is not an option The OPC-DA server loads all the discoverable tags, is it possible to: 1 let the OPC-DA server only load the tags that are requested by the SCADA/MES system. 2 let the OPC-DA server claim more memory. 3 run 2 OPC-DA servers in parallel? Thank you in advance
Last updated: 2024-01-25
Post by paulorb on STRUCT AT %MW1000
CODESYS Forge
talk
(Post)
Hi I am trying to use STRUCT to parse commands from Modbus/TCP, Modbus client will fill the bytes related to a specific command (type, parameters), then PLC (Codesys) will access the command parameters. A STRUCT will simplify a lot the process of parsing the data, so I don't need to parse byte per byte, address will be mapped to a struct and I can use it for parsing the data. From what I understood, the compiler does not allow me to specify the location of the struct for a %MW register. VAR_COMMAND AT %MW1002: structGenericModbusCommand; This will throw: Bad declaration, use '%ML' for 'structGenericModbusCommand' variable But If I change it to %ML, when you go online you see that it is actually allocating the struct in another memory address. When we go online, on GVL we can see: VAR_COMMAND. structGenericModbusCommand %ML1002 commandType COMMANDTYPE %MB8016 ... %MB8020 I am not specifying a pointer or a reference it is a struct type, why is it mapping to a %MW location (random one). How can I control where it is mapping to? I need a consistent way to map STRUCT to specific modbus address. Is it possible? Thanks, Paulo Note I am using a Codesys OEM: Schneider Machine Expert Logic Builder (M241)
Last updated: 2024-08-13
Post by mubeta on Some 'pathetic' errors in SoftMotion program
CODESYS Forge
talk
(Post)
Thank you for your interest. Your answers are in line with what I knew, so at least it comforts me that I did not misinterpret the situation. However, I don't have an exact match as, for this project over the past few days I have: 1) I have gone back to leaving the various FBs of the motion always called, all of them, and in the state machine I use a boolean to activate the various useful Execute. (But in the future I want to go back and try the programming technique with which I wanted to develop this project); 2) For the occasional error: SMC_FB_WASNT_CALLED_DURING_MOTION perhaps it was due to the fact that I had set the Ethercat bus synchronism only at the CAN master level, but not at the level of individual drives. I have now also activated it for the individual drives and it does indeed seem to have been resolved, but having also adopted the programming technique mentioned in point 1), I cannot say whether this was the solution to the problem, or instead the previous point. Is there an error ‘regulator or start not set’ in the device log before the error ‘motion generating FB wasn't called for at least one cycle’? I can't answer that right now. By now the machine is running and I am no longer there, at this one. Also, I seem to remember that the 'fbeFBerror' drive structure (5-element array), does not cycle, BUT ONCE THE 5 EVENTS AFTER SWITCHING ON, IT DOES NOT UPDATE ANYMORE (but that's another issue), so diagnostics were not easy.
Last updated: 2024-07-24
Post by hwillems on Ranges, Lambdas, on Fixed arrays of structs
CODESYS Forge
talk
(Post)
I do datastructures and algorithms in Codesys. For example a Struct of Person with thing's like IdNumber, Name, Age etc. as example. Now i do all kind of calculations, filters. So i have this pretty big Fixed Array with Structs. On this struct i want to do simple stuff you can do easily in C++/Python/Rust etc. For example i want to do this: AvererageAge := Average(Peoples.Age); Then it will return the average of all members ages. Or Sort struct on age etc. Or sort on alphabetical Name. Or use Lambda functions to filter/mutate out things like, filter out everybody above 18 years old. Or remove people who it's name start with "A". Currently i have to write my own custom function for example sorting on Age. And make a super specific function based on that particulare datastructure. Here an Example: (*Before calling this FIlter method, set the mNodeFilterSwitch to the desired filter.*) CASE mNodeFilterSelect OF (********************************[ Status Filters ]***********************************) NodeID: FOR x := ACS_OUT_BEGIN TO ACS_OUT_END BY 1 DO FOR y := ACS_IN_BEGIN TO ACS_IN_END BY 1 DO IF marrNode[y].Status.oiNodeID > marrNode[y + 1].Status.oiNodeID THEN mNodeTemp := marrNode[y + 1]; marrNode[y + 1] := marrNode[y]; marrNode[y] := mNodeTemp; END_IF; END_FOR; END_FOR; Started: FOR x := DES_OUT_BEGIN TO DES_OUT_END BY -1 DO FOR y := DES_IN_BEGIN TO DES_IN_END BY -1 DO IF marrNode[y].Status.oxStarted > marrNode[y - 1].Status.oxStarted THEN mNodeTemp := marrNode[y - 1]; marrNode[y - 1] := marrNode[y]; marrNode[y] := mNodeTemp; END_IF; END_FOR; END_FOR; Starting: FOR x := DES_OUT_BEGIN TO DES_OUT_END BY -1 DO FOR y := DES_IN_BEGIN TO DES_IN_END BY -1 DO IF marrNode[y].Status.oxStarting > marrNode[y - 1].Status.oxStarting THEN mNodeTemp := marrNode[y - 1]; marrNode[y - 1] := marrNode[y]; marrNode[y] := mNodeTemp; END_IF; END_FOR; END_FOR; END_CASE; I have like 30+ of these in the enum. Not really DRY code right? These are custom made bubble sort filters in a function. You pass in the Datastructure, and say what function you want. (This is an enum collection of sorting functions) And then the Array with Nodes of Structs gets ordered. Why can't we have Iterators and Lambda's and build in standard functions like regular languages? Also i use bubble sort because it's the easiest to implement because i can't get this to code DRY. Problem with ST (Even the new one with classes) that it's very limited for programming datastructures and algorithms. Yes you still not want dynamic memory and you need to choose the correct algorithm so you know the most extreme edge cases regarding the time it takes to execute the algorithms.(Real-time execution) How are other people dealing with this? Here for example saw some software using an adjusted ST language and having FOR EACH possibility: https://www.fernhillsoftware.com/help/iec-61131/structured-text/st-for-each.html You can then build your own custom Iterator functions. I wish the IEC 61131-3 standard would be more expressive and having more standard modern features, but still keep close to the fact of no dynamics memory and real-time systems.
Last updated: 2023-08-31
Post by gilbert-mh on CAA net base TCP client cause PLC to crash - Kernel message : N0HZ_local_softirq_pending 80
CODESYS Forge
talk
(Post)
Hello all, I have been trying to implement a TCP client on a Festo PLC (CPX-E-CEC-M1) and it looks like it works well except that after some time (greatly varies between a few hours to more than 100h) my PLC crash. When I look into the log file the only thing I see is that before the crash happens a few kernel warnings : N0HZ_local_softirq_pending 80 and then the crash. I've looked into this warning and from what I could find on the net it seems that this is warning is triggered when the ethernet link is down. I've tried to correct this bug for quite some time and what I know is that : - The crash is caused by my TCP client, when I remove it from my code I see no crash - The crash happens more quickly the more the TCP client is used. - The time before the crash is not directly proportional to the number of communications or their size. But it looks like it is just more likely to happen if the client connect to the server at a higher frequency. - The precedent observation makes it seem unlikely that the crash is caused by some memory overflow because then the crash speed would be more proportional to the amount of data exchanged. SO from these observations, I believe that the crash could be caused by the PLC trying to connect to a server while there is some kind of issue with the ethernet link resulting in the PLC getting stuck in some indefinite state and making it crash. This still seems a bit unlikely to me because if the ethernet is down it simply shouldn't be able to contact the server and the communication would just fail which doesn't cause my PLC to crash. Has anyone encountered the same kind of problem (with the same kernel message) ? I am pretty sure the warning is not the direct cause of the crash but just an indicator that something is wrong with my PLC. Thanks in advance
Last updated: 2024-01-12
To search for an exact phrase, put it in quotes. Example: "getting started docs"
To exclude a word or phrase, put a dash in front of it. Example: docs -help
To search on specific fields, use these field names instead of a general text search. You can group with AND
or OR
.