Search talk: move function

 
<< < 1 .. 31 32 33 34 > >> (Page 33 of 34)

Post by bmatlove on Re-create CoE online window in Visu CODESYS Forge talk (Post)
Hello, I am trying to re-create the CoE online window within a Visu for purposes of checking and interacting with device parameters occasionally for maintenance purposes. To minimize reliance on using the IDE for misc interactions. Ideally, I would like to exactly mimic the CoE online window within the IDE. I assume that it uses a few tricks to minimize overhead, such as only polling registers which are within the visual scope, for example. I'm afraid it might be too much to ask for a pre-built drop-in Visu module to exist for this task. Do I have any options aside from manually re-creating all the logic to do this, relying heavily on SdoInfo function blocks? Is there a way for me to reference the device ESI file to shortcut the process of determining how many registers there are and getting the address for each?
Last updated: 2025-12-27

Post by fredashbolt on Dynamically Update JSON Payload CODESYS Forge talk (Post)
I am trying to generate a JSON payload populated with a value that updates for use with a telemetry system, the payload is to be published by MQTT. I have established the MQTT client and can publish a working JSON payload but I can't get the payload to update as the value (iValue) changes. I am using a timer to trigger the .SetValue function periodically, but the JSON will only give the value as it is when it is first initialized using xFirst IF statement. Any suggestions? Thanks VAR pJsonData : POINTER TO JSON.JSONData := factory.Create(); fb_JBuilder : JSON.JSONBuilder; diRootIndex, diObject1Index : DINT; iValue : INT := 10 ; jsonArrayWriter : JSON.JSONByteArrayWriter; wsJsonData : WSTRING(1000); xFirst : BOOL := TRUE; utf8JsonData : STRING(2000); diTempVal : DINT ; PublishTimer : TON ; END_VAR IF xFirst = TRUE THEN fb_JBuilder ( pJsonData := pJsonData , diRootObj => diRootIndex ) ; diObject1Index := fb_Jbuilder.SetKeyWithObject ( "Device" , diParentIndex := diRootIndex ) ; diTempVal := fb_Jbuilder.SetKeyWithValue ( "Temp" , iValue , diParentIndex := diObject1Index ) ; xFirst := FALSE ; END_IF PublishTimer ( IN := PublishTimer.Q = 0 , PT := T#5S ) ; IF PublishTimer.Q THEN fb_JBuilder.SetValue ( iValue , diTempVal ) ; END_IF jsonArrayWriter( xExecute := PublishTimer.Q , pwData := ADR(wsJsonData), udiSize := SIZEOF(wsJsonData), jsonData := pJsonData^, xAsyncMode := FALSE ) ; JSON.Stu.ConvertUTF16toUTF8( ADR ( wsJsonData ) , ADR ( utf8JsonData ) , SIZEOF ( utf8JsonData ) , bStrictConversion := TRUE ) ;
Last updated: 2026-03-10

Post by nickpoon on SysProcessCreate stopped working after SP21? CODESYS Forge talk (Post)
I'm going through the process of updating the CODESYS Project a machine to 3.5 SP21 (old version was 3.5 SP20). One function that stopped working when upgrading was SysProcessCreate. I need to run a .exe file that is located in C:\Program Files\MQTTStream. Some initial searching suggested that there are new security rules that prevent the SoftPLC from reading/writing files to outside of its Device folder (located here - C:\Windows\System32\config\systemprofile\AppData\Roaming\CODESYS\CODESYSControlWinV3x64\24FD6770) Relocating files helped fix my JSON file reader/writer functions (which were failing previously), but not the case for SysProcessCreate. I've even attempted to just run window's cmd.exe and with: pszCommandLine = 'cd /d C:\Windows\System32\config\systemprofile\AppData\Roaming\CODESYS\CODESYSControlWinV3x64\24FD6770\PlcLogic\MQTTStream & sift-proxy.exe --grpc_uri="https://grpc-api.siftstack.com" --api_key="xxxxxxxxxxxxxxxxxxx" mqtt-client --broker_ip=10.0.10.101 --broker_port=1883 --config_file="mqtt_telemetry_config.json" --username Plantd --password 1234 --stream_metrics --storage_path="sift-proxy-logs"' I have not been able to find a lot of documentation on this, and I suspect the new update may have created a bug for SysProcessCreate. Any help would be greatly appreciated
Last updated: 2026-02-02

Post by konstantin on CAM Motion Recover after STO CODESYS Forge talk (Post)
Hello Mr. Seidel, both the master and the slave axis are modulo. Basically the situation is as follows: One master cycle is 100 units. Slave's modulo length is 2000 units. In the CAM table I defined 10 master cycles on X axis - 1000 units and on the Y axis is the slave - 2000 units. Then depending on the master position 0 to 1000 units the slave's position is plotted on the Y axis - 0 to 2000 units. For example, while the master is executing the 3rd cycle i.e. above 200 units, I trigger the STO function of the slave and it stops. The master executed his cycle but the slave was stopped during the execution. How can I set the slave to continue the CAM sequence from the point where it stopped i.e. third cycle of the master? When I reset the slave error and sync again, everyrhing starts from master's 0 position. Best Regards Konstantin Kolev
Last updated: 2026-02-13

Post by charleskirkland on Connect to Azure IoT Hub CODESYS Forge talk (Post)
It sounds like your TLS setup is basically correct, since the handshake works via OpenSSL, so the issue is likely on the CODESYS side rather than the certificates themselves. From what I’ve seen with the Azure IoT Hub Client SL library, you should double-check that the SAS token is actually being generated and passed correctly to the function blocks (especially wsDeviceSaS) and that the MQTT/HTTPS FB is really triggered cyclically-otherwise the controller won’t initiate the connection at all. Also, make sure DNS, time (NTP), and full certificate chain trust are properly configured on the controller, since IoT Hub authentication depends on them even when using SAS tokens. Another thing worth checking is the library/runtime version-there are reports that certain versions changed behavior and caused connection issues. I’d recommend starting with the official demo project (AzureMQTTDemo) and comparing it step by step with your setup to see what’s missing or not triggered. Speed Stars
Last updated: 2026-04-27

Post by timvh on USB Game Controller with Raspberry Pi CODESYS Forge talk (Post)
I'm not sure it will work, but you could try it with the CmpCharDevice library. You could create a function block that looks something like this: As input for the filename, you have to use your Linux device, e.g.: '/dev/input/event0' '/dev/input/by-path/platform-button@23-event' Off course you must also pass the pointer to the memory where the data can be written to and the size (count in number of bytes) of the buffer. FUNCTION_BLOCK FB_CharDevice VAR_INPUT szFilename: STRING; pbyBuffer : POINTER TO BYTE; udCount : UDINT; END_VAR VAR_OUTPUT iState : INT := 0; nrBytesRead : DINT; END_VAR VAR xInit : BOOL := TRUE; dFlags: DINT := CmpCharDevice.ACCESS_MODE.O_RDONLY + DINT#4000; // see details for flags: http://linux.die.net/man/2/open, + DINT#4000 is for non-blocking hDevice: CmpCharDevice.CmpCharDevice_Implementation.RTS_IEC_HANDLE := -1; Result : CmpCharDevice.CmpCharDevice_Implementation.RTS_IEC_RESULT; END_VAR IF xInit THEN hDevice := CmpCharDevice.CDOpen(szFilename, dFlags ,Result); // if it would not succeed, the result is -1 (Invalid handle) IF hDevice <> 16#FFFFFFFF AND Result = 0 THEN iState := 5; END_IF xInit := FALSE; END_IF IF iState = 5 THEN nrBytesRead := CmpCharDevice.CDRead(hDevice, pbyBuffer, udCount, Result); ELSE nrBytesRead := 0; END_IF Make sure you close the connection properly, maybe by overwriting the default FB_Exit method of the FB: // Clean up device IF hDevice <> 16#FFFFFFFF THEN __TRY CmpCharDevice.CDClose(hDevice,Result); __CATCH ; __ENDTRY iState := 0; END_IF
Last updated: 2026-05-01

Post by shamcke on Array with generic constant as persistent variable CODESYS Forge talk (Post)
Hello, I have written a function block that uses a generic constant for the upper bound of an array. I wanted to have this array in the persistent memory area, thus I constructed my FB as follows: FUNCTION_BLOCK FbWithGenericArrayLength VAR_GENERIC CONSTANT uiArrayLength : UINT := 10; END_VAR VAR PERSISTENT arr : ARRAY[1..uiArrayLength] OF INT; END_VAR In my PLC_PRG I declare an instance of said FB PROGRAM PLC_PRG VAR myFb : FbWithGenericArrayLength<10>; END_VAR This compiles just fine. When I let CODESYS fill my persistent list, it adds duplicate entries {attribute 'qualified_only'} VAR_GLOBAL PERSISTENT RETAIN // Generated instance path of persistent variable PLC_PRG.myFb.arr: ARRAY [1..uiArrayLength] OF INT; // Generated instance path of persistent variable PLC_PRG.myFb.arr: ARRAY [1..uiArrayLength] OF INT; END_VAR so I manually delete the duplicate. When i now compile, I get errors ------ Build started: Application: Device.Sim.Device.Application ------- Typify code... [ERROR] Sandbox_FW31: PersistentVars [Device: PLC Logic: Application](Line 4): C0161: Border 'uiArrayLength' of array is no constant value [ERROR] Sandbox_FW31: PersistentVars [Device: PLC Logic: Application](Line 4): Type of mapped variable is not equal to original type Compile complete -- 2 errors, 0 warnings Build complete -- 2 errors, 0 warnings : No download possible Is is simply not possible to use a generic constant for the persistent array? Thanks in advance. Edit: It seems I can manually replace the uiArrayLength in the persisten list by the value 10 I used as the generic constant for this particular instance.
Last updated: 2026-05-29

Post by imdatatas on CFC editor: enable inline value entry on unconnected input pins (as in Ladder Logic editor) CODESYS Forge talk (Post)
In the CODESYS Ladder Logic editor, there's a really practical feature available while logged in (online) to the PLC: for an existing function block (e.g. TON or MC_MoveAbsolute), double-clicking on an unconnected input pin directly opens a value entry window right in the editor — with no need to assign any variable — and you can type a value directly. Likewise, if the input pin is of an ENUM or STRUCT type, it lets you pick a value of that type straight from a dropdown list. It also doesn't require assigning a variable or adding it to a watch list, etc. Unfortunately, in the CFC editor you can't write values directly to those unconnected input pins the way you can in Ladder — CFC only supports monitoring/display there. I wish this existing Ladder editor feature were also available in CFC — it would make the CFC editor far more usable. I think this would be a relatively small addition to the CFC editor, but it would make a real difference in daily commissioning and debugging work. It would be great to hear the development team's thoughts on whether this could be considered for a future release. Thanks in advance for reading!
Last updated: 2026-09-10

Post by manuknecht on Opening a Dialog on a specific Client from ST CODESYS Forge talk (Post)
I managed to find a solution that seems to work reliably. As the VU.Globals.CurrentClient-filter accesses the CURRENTCLIENTID or at least a similar, internal variable it can only be used if called from a certain client (e.g. from a button in a visualization). My solution works by implementing a new client filter that compares the client ID of all clients to the ID of the last client that was used. The variable containing the data of the last client is defined as: G_LastClient : VU.IVisualizationClient; // Copy of last client that detected click This last client is then updated every time a button is pressed using the Execute ST-Code input configuration of the button: G_LastClient := VU.PublicVariables.Clients.Current; Next, I created a function block that implements the client filter interface as so: FUNCTION_BLOCK FB_LastClientFilter IMPLEMENTS VU.IVisualizationClientFilter VAR_INPUT END_VAR VAR_OUTPUT END_VAR VAR END_VAR Then i added a method to the FB called IsAccepted which is used to filter out the client. When creating the method, it should automatically be filled with the according variable declaration, as it is defined in the interface: (* For every client can be desided, if it is accepted. ``TRUE``: Client is accepted*) METHOD IsAccepted : BOOL VAR_INPUT (* The client, to check*) itfClient : VU.IVisualizationClient; END_VAR Now the client can be compared to the last used client as such: // check if clientID corresponds to clientID of last recorderd client IF itfCLient.ClientId = G_LastClient.ClientId THEN IsAccepted := TRUE; ELSE IsAccepted := FALSE; END_IF To make use of this custom client filter, initialize a variable with the client filter: LastClient : FB_LastClientFilter; // Client filter to find last used client Then use this client filter when opening or closing a dialog from ST: fbOpenMyDialog(itfClientFilter:=LastClient,xExecute:=TRUE,sDialogName:='VIS_MyDialog_DLG');
Last updated: 2023-09-27

Post by tcarlbom on Read tag values using external program CODESYS Forge talk (Post)
This is my first time posting in this forum and I am new to codesys. I am a fullstack developer and I am trying to figure out how the following. What would be the best approach to create a own/custom tag browser? Either directly in codesys ide or using a separate custom program (perhaps a winforms application). 1.a. Shall I parse the .project xml file to get a list of all tags in the project? 1b. Shall I use python scripting in codesys ide to get a list of tags? Once one have selected some tags. These tags shall be exposed to a python program which will be acting as a edge computer. It’s fine to be able to import a file. 2a. I found a library called codesys plchandler which (as I understand) acts a rest api server. Is this correct? If so, can I query the api from a custom python script, ie can query what tags exist in project and or read tag values? My research so far. From earlier projects I know that using opc ua would be perfect for this but from my opinion it’s bloating the plc since it’s resource intensive. So opc ua is not an option. Codesys automation server is neat. But I don’t want to rely on some cloud services and subscription based pricing. There seem to be several interesting codesys libraries like mqtt, tcp server and NVL sender which would help me expose plc tags. But all have a common problem. One have to manually write what tags which will be used in these function blocks. I want a similar experience like “selecting” tags in the opc ua or the codesys tracing, ie a tag browser.
Last updated: 2024-06-28

Post by youness on No source code available (cip object) CODESYS Forge talk (Post)
Hi yotaro, hope your problem was resolved. I had the same, but with an other library title. This exception is not detected during compilation, but rather at a given position in the program (when switching to a given visualization). Although the exception is generated at this point, it does not involve the visualization in question. This error is due to one of 3 reasons: 1) A division by zero somewhere: The program is able to detect divisions by zero at compile time. But in the case of a variable, which takes a valid value at init and changes to 0 at a later stage. 2) An invalid pointer: (either because it has a value of 0, or because it points outside the memory reserved for the program) is being dereferenced. Locate any pointers or interfaces you have in the code and check them - you should also be wary of mixing inline modifications and pointers. 3) Array overflow: Generally when a processing operation is executed outside the array's definition range. Example: a write loop with n iterations is executed on an array of dimmension n-1. On the other hand, the error message may not appear. In the latter case, the error may have fatal consequences, as the overflow has induced writing to potentially forbidden memory areas. This problem can be explained by the fact that it's not always the adjacent memory areas of PLC_PRG that are overwritten, but the memory areas that are randomly allocated to the array during compilation. In this case, however, there is no entry in the log, so you need to integrate the "Implicit Check function", which checks the line of code generating the error. To integrate this functions, click on Application --> POU for implicit controls Regards,
Last updated: 2024-07-16

Post by maldus512 on How to adapt Codesys Control SL to custom board CODESYS Forge talk (Post)
Hello everyone, I have been given the task to develop I/O drivers for a custom made, Linux based board to allow for Codesys applications to run and control the hardware. I have successfully installed Codesys Control SL for ARM/Linux and tested it with a simple demo application. Now I should start interfacing the runtime to the actual hardware; I should be able to interact with 2 RS485 serial ports, a few GPIOs and an I2C port, all of which already have the corresponding /dev/ interface in the Linux system. I am having trouble understanding how it should be approached. I have found sporadic references that fail to lead to a really comprehensive documentation. For example: The store page (https://store.codesys.com/en/codesys-control-for-linux-arm-sl-1.html#options) mentions a "runtime package" that should allow "Integration of existing C code" and "Usage of local I/Os", which seems exactly what I need to interact with custom peripherals. I have found no further reference to Codesys-C interpop. The Codesys Help page for the runtime package has a page on the "Development of Drivers" (https://content.helpme-codesys.com/en/CODESYS%20Control/rtsllinuxrbpdriverdevelopment.html) that suggests to either "Implement a function block" or "Implement I/O drivers". Those in turn lead to this page (https://forge.codesys.com/drv/io-drivers/doc/Generic/) which describes briefly an XML schema to describe new devices; unfortunately, it doesn't mention what to do with such a description (i.e. how does the runtime know about it) or how it is in any way connected to the actual hardware. Could anyone give me some pointers? I should also mention I have no prior experience with Codesys, so maybe I'm missing an obvious answer.
Last updated: 2024-08-09

Post by fmon on Modbus : dis- / re-connect cable: modbus does not re-start CODESYS Forge talk (Post)
Hello, I am using codesys Modbus TCP client (4.4.0.0) to communicate with a python modbus server (package pyModbusTCP). I first start my python server on the distant machine. After a fresh codesys compilation, a plc connection/transfer and a PLC run, the modbus connection is OK. Every time in this context the connection is created correctly. When I shut down the server, the modbus connection falls, that is normal. When I restart the python server, impossible to recreate the modbus connexion. With the client autoreconnection, I see on my server that the client tries to connect but unsuccesfully. I have the following message : DEBUG:pyModbusTCP.server:accept new connection from ClientInfo(address='192.168.1.20', port=33476) DEBUG:pyModbusTCP.server:Exception during request handling: NetworkError('recv return null') I tried to stop the codesys client and to restart it with these commands : Modbus_TCP_Client.xStop := True; // Or False Modbus_TCP_Client.Enable := True; // Or False Modbus_TCP_Server.Enable := True; // Or False I tried to confirm the error manually to force reconnection with: Modbus_TCP_Server_Motors.xConfirmError := TRUE; I tried also this command to STOP/RESET/START client and server (codesys side) but nothing happens : status_client := Modbus_TCP_Client.SetCommunicationState(eRequestedState := DED.DEVICE_TRANSITION_STATE.STOP); // .RESET & .START The answer of this function when executed is "status_client = NOT_SUPPORTED" It seems that is a socket problem, but I do not understand if it is on the client or server side. I tried a modbus simulator called "ananas.exe" and the result is the same. Impossible to get a modbus reconnection. What is different at the first connection and at a reconnection attempt ? Thanks for your help
Last updated: 2025-03-14

Post by fmon on Modbus TCP client reconnection problem CODESYS Forge talk (Post)
Hello, I am using codesys Modbus TCP client (4.4.0.0) to communicate with a python modbus server (package pyModbusTCP). I first start my python server on the distant machine. After a fresh codesys compilation, a plc connection/transfer and a PLC run, the modbus connection is OK. Every time in this context the connection is created correctly. When I shut down the server, the modbus connection falls, that is normal. When I restart the python server, impossible to recreate the modbus connexion. With the client autoreconnection, I see on my server that the client tries to connect but unsuccesfully. I have the following message : DEBUG:pyModbusTCP.server:accept new connection from ClientInfo(address='192.168.1.20', port=33476) DEBUG:pyModbusTCP.server:Exception during request handling: NetworkError('recv return null') I tried to stop the codesys client and to restart it with these commands : Modbus_TCP_Client.xStop := True; // Or False Modbus_TCP_Client.Enable := True; // Or False Modbus_TCP_Server.Enable := True; // Or False I tried to confirm the error manually to force reconnection with: Modbus_TCP_Server_Motors.xConfirmError := TRUE; I tried also this command to STOP/RESET/START client and server (codesys side) but nothing happens : status_client := Modbus_TCP_Client.SetCommunicationState(eRequestedState := DED.DEVICE_TRANSITION_STATE.STOP); // .RESET & .START The answer of this function when executed is "status_client = NOT_SUPPORTED". Is it normal ? It seems that is a socket problem, but I do not understand if it is on the client or server side. I tried a modbus simulator called "ananas.exe" and the result is the same. Impossible to get a modbus client reconnection. What is different at the first client connection and at a reconnection attempt ? Thanks for your help
Last updated: 2025-03-17

Post by otbeka on CAA File Handling: "Read only" error CODESYS Forge talk (Post)
Hi, On CODESYS V3.5.19.50 I am using the latest 3S File Access library (CAA File & CAA Types) to save and retrieve configuration data from the User Data section of an SD card, via file called config.txt. The application reads the file to memory once upon initialisation, and then the only other operation is overwriting the file with the updated configuration whenever the user changes the settings. An issue is ocurring, seemingly randomly, where the config.txt file, and all surrounding directories, cannot be written to by the unit, returning a READ_ONLY_CAA error upon file open. This sometimes does not clear even after power-cycling the PLC several times, yet checking the file permissions with ls -l shows normal read, write, and execute access. I am wondering if this is caused by the PLC itself or by an issue in my application. I have included my CAA File handler function block (SD_Card_Bin(FB).txt) and any associated types/calls below: TYPE ConfigData : STRUCT Config : ARRAY[0..256] OF STRING(64); NumberOfStrings : UDINT; END_STRUCT END_TYPE TYPE Buffer : STRUCT Data : ARRAY[0..SIZEOF(ConfigData)] OF BYTE; DataLength : UDINT; END_STRUCT END_TYPE A case within my MAIN PRG: mode.WriteConfigDataToFile: VisuElems.CURRENTVISU := 'Screen_Write'; IF xModeHasChanged THEN iErrorCount := 0; iRoute := 0; END_IF CASE iRoute OF 0: inBuffer := ConfigData_To_Buffer(GVL.UnitData); xConfigError := FALSE; xDataConfigured := FALSE; iRoute := 1; 1 : //Read Data from Card SD_Card_Bin.strFileName :=FileName; SD_Card_Bin.iFileOperation := 2; SD_Card_Bin(xExecute :=TRUE, WriteBuffer := inBuffer, xDone =>xDataConfigured, xError=>xConfigError, strErrorCodes=>strError); IF xDataConfigured THEN SD_Card_Bin(xExecute :=FALSE); IF xConfigError THEN iRoute := 32767; ELSE iRoute :=100; END_IF END_IF 100: // The end bCurMode := mode.DisplayProcessVariables; 32767: // Config error iErrorCount := iErrorCount + 1; IF iErrorCount > 2 THEN // Repeats 3 times, if no progress abandons and returns error bCurMode := mode.WriteError; ELSE iRoute := 0; // Try again END_IF END_CASE I'd like to rule out my application as the cause of this bug - help via comments or criticism would be greatly appreciated.
Last updated: 2025-03-19

Post by laurits on Max lines of code, codesys CNC ? CODESYS Forge talk (Post)
Hi, yes now its working, to get "QUEUE.bFull" to work, I've had to set the "QUEUE.nNumReservedEntries" to 3. (I tried different values here, only effect for larger values i can see is the the queue capacity gets smaller.) I've noticed the movement is slowing down when it reaches the end of the "fill Up", must be because of the "checkVelocity" can only see the current "QUEUE". Any way of solving this ? BUF : ARRAY[0..20000] OF SMC_GEOINFO; xp : ARRAY[1..100000] OF REAL; yp : ARRAY[1..100000] OF REAL; CASE iState OF 000: IF R_TRIG_bStart.Q THEN iState := iState + 1; END_IF bReady := FALSE; //initialize Queue GEO.dT1:=0; GEO.dT2:=1; GEO.dToolRadius := 0; GEO.dVel := 15000; GEO.dVelEnd := 15000; GEO.dAccel := 2000; GEO.dDecel := 2000; GEO.iObjNo := 0; GEO.piDestPos.dX := 0; GEO.piDestPos.dY := 0; QUEUE.bEndOfList := FALSE; QUEUE.nPastMarker := -1; QUEUE.nWritePos := 0; QUEUE.pbyBuffer := ADR(BUF[0]); n := 0; sMC_CheckVelocities(bExecute:= FALSE); SM3_CNC.SMC_SetQueueCapacity(ADR(QUEUE), SIZEOF(BUF)); QUEUE.nNumReservedEntries := 3; 001: FOR i := 1 TO SIZEOF(xp)/SIZEOF(xp[1]) DO xp[i] := UDINT_TO_REAL(i) * 0.01; yp[i] := UDINT_TO_REAL(i) * 0.01; END_FOR iState := iState + 1; 002: WHILE NOT QUEUE.bFull DO // when the Queue is full, wait until it has been processed by the following FBs n := n + 1; GEO.iSourceLine_No := n; GEO.piStartPos := GEO.piDestPos; // copy last destination GEO.iMoveType := LIN; // generate linear movement GEO.iObjNo := GEO.iObjNo + 1; // calculate number GEO.piDestPos.dX := xp[n]; // generate position GEO.piDestPos.dY := yp[n]; SMC_CalcLengthGeo(pg := ADR(GEO)); // calculate length of object with the help of the standard function SMC_AppendObj(poq:=ADR(QUEUE), pgi:=ADR(GEO)); //append object to queue IF n = UDINT_TO_DINT( SIZEOF(xp)/SIZEOF(xp[1])) THEN // all target positions processed QUEUE.bEndOfList := TRUE; iState := iState + 1; EXIT; END_IF END_WHILE sMC_CheckVelocities(bExecute:= TRUE, poqDataIn:= ADR(QUEUE)); bReady := TRUE; // Send message to smc_interpolator to start 003:
Last updated: 2025-06-04

Post by testlogic on Sending Sequential Modbus TCP Packets CODESYS Forge talk (Post)
I have a Modbus TCP slave device where I need to do sequential writes to the same register. The register I'm writing to is kind of like a command line, each packet is a command word encoded in Hexadecimal. I am having difficulty implementing this system in CoDeSys 3.5 SP19. I feel like the structure of the program should be something along the lines of (Pseudocode): ModbusTCPSend(Command Register, Command1) ModbusTCPSend(Command Register, Command2) ModbusTCPSend(Command Register, Command3) I have tried to implement this with a rising edge trigger wMot1OPCode := 16#E1; //Stop Motor & Kill Program xMot1SendOP := TRUE; //Send OP on rising edge xMot1SendOP := FALSE; //Reset wMot1OPCode := 16#9E; //Disable Motor xMot1SendOP :=TRUE; //Send OP on rising edge xMot1SendOP := FALSE; //Reset Where "wMot1OPCode" is the IO map for writing to the command register, and "xMot1SendOP" is the rising edge trigger for that modbus channel. However, this doesn't work. The device never responds to the modbus commands. It seems like the trigger variable is switched too quickly for modbus to send the packet. I know the modbus register is working, because I can set the channel to cyclic and the device will respond. However, I can't use this reliably because I need each command to be sent once, in order. Cyclic keeps re-sending the commands and seems like it could miss a command as well if one was sent in-between cycle time. I have also trying using the Application trigger as described by https://faq.codesys.com/pages/viewpage.action?pageId=24510480, but this is also not working for me. See attached picture for my FBD code. This seems like a simple function, I can't tell what I'm doing wrong here. Thanks for the help.
Last updated: 2024-03-06

Post by tk096 on High Cycle Times for SoftMotion_PlanningTask when using AxisGroup CODESYS Forge talk (Post)
Hi, under this circumstances the performance of a Raspberry Pi 4 should be sufficient to run a Softmotion robotics application. A closer look at the project would be required. Maybe you could contact the codesys support? Usually it is recommended to run the planning task cyclically every 2ms with task priority of 0 on a dedicated core. In the task configuration you can have a look at the average and maximum execution time of the planning task. You could use the function block SMC_TuneCPKernel (https://content.helpme-codesys.com/en/libs/SM3_Robotics/Current/SM3_Robotics/POUs/AdministrativeConfiguration/Computation/SMC_TuneCPKernel.html) to define suitable values for the parameters 'fSyncBufferDuration' and 'fPlanningInterval'. However, as previously mentioned, the performance of a Raspberry Pi 4 with realtime patch should be sufficient. The 'fPlanningInterval' parameter specifies the maximum planning step width in seconds. The cycle time of the planning task should not permanently exceed this value. A higher value reduces the computational effort, but can lead to a violation or no full utilization of the set limit values for velocity, acceleration and jerk. From a starting value of 0.016 seconds, the value should be increased gradually until the performance is acceptable. The parameter 'fSyncBufferDuration' specifies the size (in seconds) of the buffer between the planning and fieldbus task. The cycle time of the planning task must not exceed this value at peak times (this will lead to the error SMC_CP_QUEUE_UNDERRUN). A higher value can compensate for peaks in the cycle time of the planning task. At the same time, however, this also increases the latency for executing interrupts and aborting movements.
Last updated: 2024-03-22

Post by xcqt on Oop best practice CODESYS Forge talk (Post)
Hi all, I’m currently trying to improve my OOP structure in CODESYS and I’m looking for some input on how others approach this. I understand the basics like inheritance, interfaces, abstract FBs, methods, and properties, but I still struggle a bit with the overall architecture and what’s considered clean or scalable in bigger projects. As an example, I’m working on two different energy meter function blocks: FB_EnergyMeter_MQTT reads data from MQTT (strings) FB_EnergyMeter_Modbus reads data from Modbus (words) Both have their own Update() method and implement the same interface (something like IF_EnergyMeter). Later on, I’ll probably add more meter types, but they should all behave the same from the controller’s point of view. Now, there’s a FB_GridControl block that needs power data from these meters. I see two options here: Define the meter blocks inside FB_GridControl and call them directly (for example fbModbusMeter.UpdateModbus()). Keep the meter blocks outside and pass them into FB_GridControl as interface references, so the control block doesn’t know which specific type of meter it’s dealing with. Option 2 feels cleaner and more flexible to me, but I’m not entirely sure how to handle the data flow in that case. Should I pass the meter instance through an interface reference (REFERENCE TO IF_EnergyMeter)? Or is there a better way to link the external FBs to the control block? I’d like to hear how you structure this kind of setup or see an example from someone who has done something similar. EDIT: I think i need to do something like this fbModbusUpdateInput(wInput:= wWordValue); fbMqttUpdateInput(strInput:= strStringValue); IF bUseMqtt THEN Meter REF = fbMqttUpdateInput; ELSE Meter REF = fbModbusUpdateInput; END_IF fbControl.SetMeter(UsedMeter := Meter); Or am i thinking wrong? Thanks, Thomas
Last updated: 2025-10-16

Post by e13740e on Parameterized Property syntax for array element processing CODESYS Forge talk (Post)
Since parameterized (indexed) properties are not possible, I decided to use architectural approach "Indexing Property Adapter" to achieve the intended goal — avoiding code duplication for validated access to array elements. Essence: Create a Function Block Adapter (FB_PropertyAdapter) that encapsulates the logic for working with a single element of the target array (e.g., with one settings structure). Declare Properties inside the adapter block for accessing each individual field of the data structure. All validation logic is implemented within the Set accessors of these properties. Data Binding via VAR_IN_OUT: The adapter block receives a reference to a specific data element from the global array through its VAR_IN_OUT section, which ensures direct work with the original data without copying. Create an Array of Adapters: In the parent POU (e.g., FB_SettingsManager), an array of these adapter blocks is created — one for each element of the global array that needs to be managed. Initialize Bindings: In a FOR loop, each adapter instance from the array is given a reference to the corresponding data element. Result: This approach allows accessing the data via the index of the adapter array, and then through the property name, which simulates the behavior of an indexed property: MyAdapterArray[Index].MyProperty Thus, the validation and data access logic is written only once inside the adapter block and is then reused multiple times by creating instances of it in an array. This completely solves the problem of code duplication while providing a clean, scalable, and object-oriented architecture compatible with standard CODESYS features. Question closed.
Last updated: 2025-10-19

Post by dclements on Feature Request: Read-Only References / Pointer-to-Const Support CODESYS Forge talk (Post)
I would like to suggest adding support for persistent read-only references or pointers in CODESYS, similar to a C++ pointer-to-const (const T*). For example, something conceptually similar to: POINTER TO CONSTANT ST_MyData or REFERENCE TO CONSTANT ST_MyData The important distinction is that the reference itself may still be passed around or reassigned, but the referenced object cannot be modified through that reference. CODESYS currently supports VAR_IN_OUT CONSTANT, which provides read-only reference semantics for parameters, but there does not appear to be an equivalent type that can be stored in a variable or returned from a method. A practical use case is a registry that owns long-lived definitions. The registry needs to retain ownership of the data while downstream systems maintain persistent references to it. Currently, the main options are: Return the struct by value, which loses reference semantics and requires a copy. Return POINTER TO ST_Definition, which allows consumers to modify registry-owned data. Convert the structure into a Function Block and expose a getter-only interface, which provides the desired encapsulation but introduces more complexity and memory overhead. A read-only reference/pointer type would allow libraries to expose persistent, zero-copy access to internally owned data while preserving encapsulation. This would be particularly useful for library APIs and object-oriented CODESYS architectures where ownership of data should remain with one component while other components are allowed to observe it. Similar requests for constant references/pointers have been discussed on CODESYS Forge previously, so this appears to be a recurring use case rather than something specific to one application.
Last updated: 2026-09-01

Post by rmarco on Generic Variables and FDB CODESYS Forge talk (Post)
Hello everyone, I am running into a highly frustrating issue in the FBD editor regarding a Function Block with generic constants (VAR_GENERIC CONSTANT). I created a FB using ST, with a generic var, useful for having a variable sized array, as follows: FUNCTION_BLOCK Coil VAR_GENERIC CONSTANT maxEvents: USINT := 5; END_VAR VAR events: ARRAY[0..maxEvents-1] OF IEvent; END_VAR These FBs have also several methods. I declare them as follows in code: VAR coil1: CDL.Coil<(maxEvents:=1)>; END_VAR and when using them in ST, I have no problems. However, when trying to use them in FDB, I do not know how to do that, as some strange misalignment happens. Here's what happens: When I add the block to my FBD canvas and assign coil1 as the instance name, the compiler throws this error: 'coil1' is not an instance of 'CDL.Coil<(maxEvents:=1)>'. Same occurs when I try to instantiate blocks such as 'coil1.turnOn' or similar. Here is what I have already tried, none of which worked: - Deleting the <(maxEvents:=1)> parameter from the text inside the FBD box. - Deleting the block entirely, dropping an "Empty Box", and typing coil1 above it to let the IDE auto-complete and format the block. - Running a full "Clean All" and rebuilding the code. I am aware that I could bypass the graphical editor by calling it in Structured Text. However, I need to keep this logic compatible to FBD. Has anyone encountered this specific FBD parsing bug with generic variables? Thanks in advance for any insights. Best regards, Marco
Last updated: 2026-06-29

Post by clesio on CAA.File.Write – Unexpected characters when writing a CSV file CODESYS Forge talk (Post)
Hello everyone, I am trying to create a routine in CODESYS to export a report to a CSV file using the CAA.File library. The file is created successfully, but I am getting some unexpected/unknown characters in the generated CSV. The problem seems to be related to the SIZEOF() function. I am using it for the szSize parameter of File.Write, as recommended in the CODESYS documentation. However, when I use SIZEOF(), the CSV contains extra characters and parts of previous strings. I also tried using LEN(), but in my application the file is created empty, even though the string and the calculated length appear to be correct. Here is the relevant part of my code: PROGRAM Relatorio VAR // Bool b_Executa_fb_Cria_Arquivo : BOOL; b_Executa_fb_Fecha_Arquivo : BOOL; b_Escreve_dados : BOOL; b_Erro_fb_Escreve : BOOL; //STR s_Nome_Arquivo : STRING; s_Palavra : STRING; s_Palavra_Anterior : STRING; s_Data_Atualizada_Formatada : STRING; s_Dia : STRING; s_Mes : STRING; s_Ano : STRING; s_Hora_Atualizada_Formatada : STRING; s_Hora : STRING; s_Minu : STRING; s_Segu : STRING; //INT i_modo_fb_Cria_Arquivo : INT; i_ErroID_fb_Escreve : INT; //UINT i_Tamanho_Palavra : UINT; // Blocos de Funcao fb_Cria_Arquivo : FILE.Open; fb_Fecha_Arquivo : FILE.Close; fb_Escreve : FILE.Write; // DATA E HORA sc_DataTime : SysTimeRtc.RTS_SYSTIMEDATE; // STRUCT = sc uidResultRtcGet : UDINT; //stGetDate : SysTimeRtc.RTS_SYSTIMEDATE; uidResultConvertToDate : UDINT; uidResult : RTS_IEC_RESULT; END_VAR VAR_INPUT //BOOL b_SET_Executa_fb_Cria_Arquivo : BOOL; b_RES_Executa_fb_Cria_Arquivo : BOOL; b_Executa_fb_Escrita : BOOL; // INT i_Linhas_Cabecalho : INT; i_Linhas_Cabecalho_Anterior : INT; END_VAR // Para Testes s_Nome_Arquivo := 'relatorio/Teste1M.CSV'; i_modo_fb_Cria_Arquivo := 0; // TRATAMENTO DE DATOS DATA e HORA uidResultRtcGet := SysTimeRtcGet(uidResult); uidResultConvertToDate := SysTimeRtcConvertUtcToDate(dwTimestampUtc := uidResultRtcGet, pDate := sc_DataTime); // FORMATA DATA EM UMA STRING s_Dia := UINT_TO_STRING(sc_DataTime.wDay); s_Mes := UINT_TO_STRING(sc_DataTime.wMonth); s_Ano := UINT_TO_STRING(sc_DataTime.wYear); s_Data_Atualizada_Formatada := CONCAT(s_Dia, CONCAT('/', CONCAT(s_Mes, CONCAT('/', s_Ano)))); // FORMATA HORA EM UMA STRING s_Hora := UINT_TO_STRING(sc_DataTime.wHour); s_Minu := UINT_TO_STRING(sc_DataTime.wMinute); s_Segu := UINT_TO_STRING(sc_DataTime.wSecond); s_Hora_Atualizada_Formatada := CONCAT(s_Hora, CONCAT(':', CONCAT(s_Minu, CONCAT(':', s_Segu)))); // ABRE e CRIA ARQUIVO IF (b_SET_Executa_fb_Cria_Arquivo OR b_Executa_fb_Cria_Arquivo) AND NOT(b_RES_Executa_fb_Cria_Arquivo) THEN b_Executa_fb_Cria_Arquivo := TRUE; ELSE b_Executa_fb_Cria_Arquivo := FALSE; END_IF fb_Cria_Arquivo( xExecute := b_Executa_fb_Cria_Arquivo, sFileName := s_Nome_Arquivo, eFileMode := i_modo_fb_Cria_Arquivo, xExclusive := FALSE, ); //i_Tamanho_Palavra := SizeOf(s_Palavra); // ESCREVE NO ARQUIVO fb_Escreve( xExecute := b_Executa_fb_Escrita, hFile := fb_Cria_arquivo.hFile, szSize := SIZEOF(s_Palavra), pBuffer := ADR(s_palavra) ); // FECHA ARQUIVO fb_Fecha_Arquivo( xExecute := b_Executa_fb_Fecha_Arquivo, hFile := fb_Cria_arquivo.hFile ); IF Criacao_Edicao_Arquivos.b_Escreve_Cabecalho THEN CASE i_Linhas_Cabecalho OF 1 : s_palavra := 'ESTERILIZADOR'; 2: s_palavra := 'MAQ4; $R$L'; 3: s_palavra := CONCAT(CONCAT('CLIENTE: ',GVL.sReceitaAtual), '$R$L'); 4: s_palavra := CONCAT(CONCAT('NUMERO LOTE: ',DINT_TO_STRING(GVL.Lote)), '$R$L'); 5: s_palavra := CONCAT(CONCAT('OPERADOR: ', DINT_TO_STRING(GVL.Operador)), '$R$L'); 6: s_palavra := CONCAT(CONCAT('DATA: ', s_Data_Atualizada_Formatada), '$R$L'); 7: s_palavra := CONCAT(CONCAT('HORA: ', s_Hora_Atualizada_Formatada), '$R$L'); 8: s_palavra := '$R$L'; 9: s_palavra := 'PARAMETROS AJUSTADOS $R$L'; 10: s_palavra := CONCAT('TEMPO PRE COND.: ', CONCAT(INT_TO_STRING(GVL.rc_T_PreCondicionamento), ' min $R$L')); 11: s_palavra := CONCAT('PULSOS INERTIZACAO 1: ', CONCAT(INT_TO_STRING(GVL.rc_PulsosInertizacao_1), ' PULSOS $R$L')); 12: s_palavra := CONCAT('PULSOS INERTIZACAO 2: ', CONCAT(INT_TO_STRING(GVL.rc_PulsosInertizacao_2), ' PULSOS $R$L')); 13: s_palavra := CONCAT('PULSOS AERACAO: ', CONCAT(INT_TO_STRING(GVL.rc_PulsosAeracao_2), ' PULSOS $R$L')); 14: s_palavra := CONCAT('PRESSAO DE VACUO 1: ', CONCAT(REAL_TO_STRING(GVL.rc_PV1_max), ' bar $R$L')); 15: s_palavra := CONCAT('PRESSAO DE VACUO 2: ', CONCAT(REAL_TO_STRING(GVL.rc_PV2), ' bar $R$L')); 16: s_palavra := CONCAT('PRESSAO INERTIZACAO 1: ', CONCAT(REAL_TO_STRING(GVL.rc_PN1), ' bar $R$L')); 17: s_palavra := CONCAT('PRESSAO INERTIZACAO 2: ', CONCAT(REAL_TO_STRING(GVL.rc_PN2), ' bar $R$L')); 18: s_palavra := CONCAT('PRESSAO AERACAO: ', CONCAT(REAL_TO_STRING(GVL.rc_PAR), ' bar $R$L')); 19: s_palavra := CONCAT('PRESSAO ETO: ', CONCAT(REAL_TO_STRING(GVL.rc_PressaoETO), ' bar $R$L')); 20: s_palavra := CONCAT('PRESSAO Compl.: ', CONCAT(REAL_TO_STRING(GVL.rc_PressaoETO_2), ' bar $R$L')); 21: s_palavra := CONCAT('MASSA ETO: ', CONCAT(REAL_TO_STRING(GVL.rc_QuantidadeETO), ' Kg $R$L')); 22: s_palavra := CONCAT('TEMPO PRE COND. Vacuo/Vapor: ', CONCAT(INT_TO_STRING(GVL.rc_T_Vapor_1), ' min $R$L')); 23: s_palavra := CONCAT('SET-POINT: ', CONCAT(REAL_TO_STRING(GVL.ihm_SPTemperatura), ' °C $R$L')); 24: s_palavra := CONCAT('TEMPO ESTERILIZACAO: ', CONCAT(INT_TO_STRING(GVL.rc_TempoEsterilizacao), ' min $R$L')); 25: s_palavra := CONCAT('TEMPO PARADA: ', CONCAT(INT_TO_STRING(GVL.rc_T_PressaoParada), ' min $R$L')); 26: s_palavra := CONCAT('UMIDADE: ', CONCAT(REAL_TO_STRING(GVL.rc_UmidadeRelativa), ' % $R$L')); 27: s_palavra := '$R$L'; END_CASE END_IF Note: The code I am attaching does not include the execution/sequence management of the function blocks. I have omitted this part to keep the example focused on the CSV writing routine. The function blocks are triggered and managed by a separate state machine. I am not sure what the correct approach is in this case, especially since the official documentation recommends using SIZEOF() for szSize. I will attach my code and a screenshot of the generated CSV showing the issue. Has anyone experienced something similar or could suggest the correct way to write a changing STRING to a CSV file using CAA.File.Write?
Last updated: 2026-09-08

Post by clesio on CAA.File.Write – Unexpected characters when writing a CSV file CODESYS Forge talk (Post)
Hello everyone, I am trying to create a routine in CODESYS to export a report to a CSV file using the CAA.File library. The file is created successfully, but I am getting some unexpected/unknown characters in the generated CSV. The problem seems to be related to the SIZEOF() function. I am using it for the szSize parameter of File.Write, as recommended in the CODESYS documentation. However, when I use SIZEOF(), the CSV contains extra characters and parts of previous strings. I also tried using LEN(), but in my application the file is created empty, even though the string and the calculated length appear to be correct. Here is the relevant part of my code: PROGRAM Relatorio VAR // Bool b_Executa_fb_Cria_Arquivo : BOOL; b_Executa_fb_Fecha_Arquivo : BOOL; b_Escreve_dados : BOOL; b_Erro_fb_Escreve : BOOL; //STR s_Nome_Arquivo : STRING; s_Palavra : STRING; s_Palavra_Anterior : STRING; s_Data_Atualizada_Formatada : STRING; s_Dia : STRING; s_Mes : STRING; s_Ano : STRING; s_Hora_Atualizada_Formatada : STRING; s_Hora : STRING; s_Minu : STRING; s_Segu : STRING; //INT i_modo_fb_Cria_Arquivo : INT; i_ErroID_fb_Escreve : INT; //UINT i_Tamanho_Palavra : UINT; // Blocos de Funcao fb_Cria_Arquivo : FILE.Open; fb_Fecha_Arquivo : FILE.Close; fb_Escreve : FILE.Write; // DATA E HORA sc_DataTime : SysTimeRtc.RTS_SYSTIMEDATE; // STRUCT = sc uidResultRtcGet : UDINT; //stGetDate : SysTimeRtc.RTS_SYSTIMEDATE; uidResultConvertToDate : UDINT; uidResult : RTS_IEC_RESULT; END_VAR VAR_INPUT //BOOL b_SET_Executa_fb_Cria_Arquivo : BOOL; b_RES_Executa_fb_Cria_Arquivo : BOOL; b_Executa_fb_Escrita : BOOL; // INT i_Linhas_Cabecalho : INT; i_Linhas_Cabecalho_Anterior : INT; END_VAR // Para Testes s_Nome_Arquivo := 'relatorio/Teste1M.CSV'; i_modo_fb_Cria_Arquivo := 0; // TRATAMENTO DE DATOS DATA e HORA uidResultRtcGet := SysTimeRtcGet(uidResult); uidResultConvertToDate := SysTimeRtcConvertUtcToDate(dwTimestampUtc := uidResultRtcGet, pDate := sc_DataTime); // FORMATA DATA EM UMA STRING s_Dia := UINT_TO_STRING(sc_DataTime.wDay); s_Mes := UINT_TO_STRING(sc_DataTime.wMonth); s_Ano := UINT_TO_STRING(sc_DataTime.wYear); s_Data_Atualizada_Formatada := CONCAT(s_Dia, CONCAT('/', CONCAT(s_Mes, CONCAT('/', s_Ano)))); // FORMATA HORA EM UMA STRING s_Hora := UINT_TO_STRING(sc_DataTime.wHour); s_Minu := UINT_TO_STRING(sc_DataTime.wMinute); s_Segu := UINT_TO_STRING(sc_DataTime.wSecond); s_Hora_Atualizada_Formatada := CONCAT(s_Hora, CONCAT(':', CONCAT(s_Minu, CONCAT(':', s_Segu)))); // ABRE e CRIA ARQUIVO IF (b_SET_Executa_fb_Cria_Arquivo OR b_Executa_fb_Cria_Arquivo) AND NOT(b_RES_Executa_fb_Cria_Arquivo) THEN b_Executa_fb_Cria_Arquivo := TRUE; ELSE b_Executa_fb_Cria_Arquivo := FALSE; END_IF fb_Cria_Arquivo( xExecute := b_Executa_fb_Cria_Arquivo, sFileName := s_Nome_Arquivo, eFileMode := i_modo_fb_Cria_Arquivo, xExclusive := FALSE, ); //i_Tamanho_Palavra := SizeOf(s_Palavra); // ESCREVE NO ARQUIVO fb_Escreve( xExecute := b_Executa_fb_Escrita, hFile := fb_Cria_arquivo.hFile, szSize := SIZEOF(s_Palavra), pBuffer := ADR(s_palavra) ); // FECHA ARQUIVO fb_Fecha_Arquivo( xExecute := b_Executa_fb_Fecha_Arquivo, hFile := fb_Cria_arquivo.hFile ); IF Criacao_Edicao_Arquivos.b_Escreve_Cabecalho THEN CASE i_Linhas_Cabecalho OF 1 : s_palavra := 'ESTERILIZADOR'; 2: s_palavra := 'MAQ4; $R$L'; 3: s_palavra := CONCAT(CONCAT('CLIENTE: ',GVL.sReceitaAtual), '$R$L'); 4: s_palavra := CONCAT(CONCAT('NUMERO LOTE: ',DINT_TO_STRING(GVL.Lote)), '$R$L'); 5: s_palavra := CONCAT(CONCAT('OPERADOR: ', DINT_TO_STRING(GVL.Operador)), '$R$L'); 6: s_palavra := CONCAT(CONCAT('DATA: ', s_Data_Atualizada_Formatada), '$R$L'); 7: s_palavra := CONCAT(CONCAT('HORA: ', s_Hora_Atualizada_Formatada), '$R$L'); 8: s_palavra := '$R$L'; 9: s_palavra := 'PARAMETROS AJUSTADOS $R$L'; 10: s_palavra := CONCAT('TEMPO PRE COND.: ', CONCAT(INT_TO_STRING(GVL.rc_T_PreCondicionamento), ' min $R$L')); 11: s_palavra := CONCAT('PULSOS INERTIZACAO 1: ', CONCAT(INT_TO_STRING(GVL.rc_PulsosInertizacao_1), ' PULSOS $R$L')); 12: s_palavra := CONCAT('PULSOS INERTIZACAO 2: ', CONCAT(INT_TO_STRING(GVL.rc_PulsosInertizacao_2), ' PULSOS $R$L')); 13: s_palavra := CONCAT('PULSOS AERACAO: ', CONCAT(INT_TO_STRING(GVL.rc_PulsosAeracao_2), ' PULSOS $R$L')); 14: s_palavra := CONCAT('PRESSAO DE VACUO 1: ', CONCAT(REAL_TO_STRING(GVL.rc_PV1_max), ' bar $R$L')); 15: s_palavra := CONCAT('PRESSAO DE VACUO 2: ', CONCAT(REAL_TO_STRING(GVL.rc_PV2), ' bar $R$L')); 16: s_palavra := CONCAT('PRESSAO INERTIZACAO 1: ', CONCAT(REAL_TO_STRING(GVL.rc_PN1), ' bar $R$L')); 17: s_palavra := CONCAT('PRESSAO INERTIZACAO 2: ', CONCAT(REAL_TO_STRING(GVL.rc_PN2), ' bar $R$L')); 18: s_palavra := CONCAT('PRESSAO AERACAO: ', CONCAT(REAL_TO_STRING(GVL.rc_PAR), ' bar $R$L')); 19: s_palavra := CONCAT('PRESSAO ETO: ', CONCAT(REAL_TO_STRING(GVL.rc_PressaoETO), ' bar $R$L')); 20: s_palavra := CONCAT('PRESSAO Compl.: ', CONCAT(REAL_TO_STRING(GVL.rc_PressaoETO_2), ' bar $R$L')); 21: s_palavra := CONCAT('MASSA ETO: ', CONCAT(REAL_TO_STRING(GVL.rc_QuantidadeETO), ' Kg $R$L')); 22: s_palavra := CONCAT('TEMPO PRE COND. Vacuo/Vapor: ', CONCAT(INT_TO_STRING(GVL.rc_T_Vapor_1), ' min $R$L')); 23: s_palavra := CONCAT('SET-POINT: ', CONCAT(REAL_TO_STRING(GVL.ihm_SPTemperatura), ' °C $R$L')); 24: s_palavra := CONCAT('TEMPO ESTERILIZACAO: ', CONCAT(INT_TO_STRING(GVL.rc_TempoEsterilizacao), ' min $R$L')); 25: s_palavra := CONCAT('TEMPO PARADA: ', CONCAT(INT_TO_STRING(GVL.rc_T_PressaoParada), ' min $R$L')); 26: s_palavra := CONCAT('UMIDADE: ', CONCAT(REAL_TO_STRING(GVL.rc_UmidadeRelativa), ' % $R$L')); 27: s_palavra := '$R$L'; END_CASE END_IF Note: The code I am attaching does not include the execution/sequence management of the function blocks. I have omitted this part to keep the example focused on the CSV writing routine. The function blocks are triggered and managed by a separate state machine. I am not sure what the correct approach is in this case, especially since the official documentation recommends using SIZEOF() for szSize. I will attach my code and a screenshot of the generated CSV showing the issue. Has anyone experienced something similar or could suggest the correct way to write a changing STRING to a CSV file using CAA.File.Write?
Last updated: 2026-09-08

Post by dwpessoa on CNC Jumps G20 - SMC_NCInterpreter and long time to process CODESYS Forge talk (Post)
I am studying and developing a Softmotion+CNC system for a machine that executes multiple pieces. The G code program is written by the machine operator and each cycle execute 1 piece. The programs are large, exceeding 1000 lines and using up to 8 axes (X, Y, Z, A, B, C, P and Q). The machine needs to run cyclically, executing N pieces (selected by the Operator)... so I tested it using Looping and counters (G36 G37 and G20) and it worked, but it takes a long time to process, and the more pieces I need, the longer the processing time and this is totally impracticable. I found this solution which was very good, and for a few cycles it works well, but for 99999 pieces of a program with 1000 lines, it doesn't work very well... Another solution I tested is to maintain the interpolator with an automatic restart, that is, I load the program without looping (without G20) and give it another start as soon as it finishes. This partially resolved it, but there is still a delay in processing SMC_NCInterpreter in each restart :(. Another solution I thought of is to manually create the SMC_GEOINFO structure and then reuse it, avoinding the Interpreter, but reading the documentation and checking the structure filled by standard blocks, I noticed that there doesn't seem to be a "JUMP" function in the structure! In other words, the SMC_NCInterpreter actually keeps copying and copying the program section for each jump (G20)... If I repeat a 10-line program 1000 times, I will have a structure with more than 10000 lines... possibly this is the cause of take so long to process. Has anyone ever had a problem like this? I believe the same thing happens with typical applications with manipulator robots using Codesys in continuous cycles, and I would like to know if there is any solution, or even if I am misinterpreting the G20 question in SMC_GEOINFO. Thanks!
Last updated: 2023-09-20

<< < 1 .. 31 32 33 34 > >> (Page 33 of 34)

Showing results of 837

Sort by relevance or date