Search talk: var static

 
<< < 1 .. 5 6 7 8 > >> (Page 7 of 8)

Post by jari-koivuluoma on Problem trying Net Base Services 3.5.15.0 TCP connection CODESYS Forge talk (Post)
I have a need to send messages between 2 PLCs and I cant use network variables (because of size limit) so I tried writing this simple test program. This seems to work fine. I can send messages back and forth when a first "Start server" and then "Connect client". See the attached image. However, if I disconnect the client by setting ClientConnect to false and try to re-connect then the TCP_Client just gives me TIMEOUT error. When I stop and start the server again, then Im able to reconnect. How is this supposed to work? Why reconnecting wont work. There is not other way of disconnecting the client than setting xEnable of the TCP_Client to false. This is just a testing program and I will try it on 2 seperate devices once this works. PROGRAM PLC_PRG VAR CONSTANT mySize : UDINT := 255; END_VAR VAR Server: NBS.TCP_Server; ServerIpStr: STRING := '127.0.0.1'; ServerIP: NBS.IP_ADDR; ServerPort: UINT := 50000; ServerConnection: NBS.TCP_Connection; Client: NBS.TCP_Client; ServerRead: NBS.TCP_Read; ServerWrite: NBS.TCP_Write; ServerSend: STRING(mySize); ServerReceive: STRING(mySize); ServerConnect: BOOL; bServerSend: BOOL; IP: NBS.INADDR; ConnectedClientIP: STRING; ClientPort: UINT := 50000; ClientIpStr: STRING := '192.168.1.49'; ClientIP: NBS.IP_ADDR; ClientRead: NBS.TCP_Read; ClientWrite: NBS.TCP_Write; ClientSend: STRING(mySize); ClientReceive: STRING(mySize); ClientConnect: BOOL; bClientSend: BOOL; Error: BOOL; Message: BOOL; END_VAR // Server ServerIP.sAddr := ServerIpStr; Server( ipAddr := ServerIP, uiPort := ServerPort ); ServerConnection( xEnable := Server.xEnable, hServer := Server.hServer, ); IP := ServerConnection.IPAddress; ConnectedClientIP := F_Concat7( BYTE_TO_STRING(IP.S_un_b.s_b1),'.', BYTE_TO_STRING(IP.S_un_b.s_b2),'.', BYTE_TO_STRING(IP.S_un_b.s_b3),'.', BYTE_TO_STRING(IP.S_un_b.s_b4)); ServerRead( xEnable := ServerConnection.xActive, hConnection := ServerConnection.hConnection, szSize := SIZEOF(ServerReceive), pData := ADR(ServerReceive) ); IF ServerRead.xReady AND ServerRead.szCount > 0 THEN Message := TRUE; END_IF IF ServerRead.eError > 0 THEN Error := TRUE; END_IF ServerWrite( xExecute := ServerConnection.xActive AND bServerSend, hConnection := ServerConnection.hConnection, szSize := LEN(ServerSend)+1, pData := ADR(ServerSend) ); IF ServerWrite.xDone THEN bServerSend := FALSE; END_IF IF ServerWrite.eError > 0 THEN Error := TRUE; END_IF // Client ClientIP.sAddr := ClientIpStr; Client( xEnable := ClientConnect, ipAddr := ClientIP, uiPort := ServerPort, udiTimeOut := 10000000 ); ClientRead( xEnable := Client.xActive, hConnection := Client.hConnection, szSize := SIZEOF(ClientReceive), pData := ADR(ClientReceive) ); IF ClientRead.xReady AND ClientRead.szCount > 0 THEN Message := TRUE; END_IF IF ClientRead.eError > 0 THEN Error := TRUE; END_IF ClientWrite( xExecute := Client.xActive AND bClientSend, hConnection := Client.hConnection, szSize := LEN(ClientSend)+1, pData := ADR(ClientSend) ); IF ClientWrite.xDone THEN bClientSend := FALSE; END_IF IF ClientWrite.eError > 0 THEN Error := TRUE; END_IF
Last updated: 2024-10-03

Post by bbm1995 on Camera RTSP Feed CODESYS Forge talk (Post)
Hi dgrard, I had the same issue for a long time, but on a WAGO webvisu. Now I'm glad that I can share my solution. I don't know if you are trying to use the webvisu or the target visu, but this works on webvisu: Get "go2rtc" and set it up according to the documentation. I'm running the Windows binary. Here's my example of the go2rtc.yaml config file (contains working example streams): api: listen: ":1984" # default ":1984", HTTP API port ("" - disabled) origin: "*" # default "", allow CORS requests (only * supported) static_dir: "www" # default "", folder for static files (custom web interface) tls_listen: ":443" # default "", enable HTTPS server tls_cert: "./SSL/fullchain.pem" tls_key: "./SSL/privatekey.pem" streams: # Streams with multiple links will fall back on the next link. ABUS TVIP48511: - rtsp://<username>:<password>@<hostname>:<port>/ch1/main - rtsp://<username>:<password>@<hostname>:<port>/ch1/sub # Diagnostic connections Kirchhoff Institute for Physics - Germany: http://pendelcam.kip.uni-heidelberg.de/mjpg/video.mjpg Blanton Bottling, Kentucky - USA: http://camera.buffalotrace.com/mjpg/video.mjpg Tokyo - Japan: http://61.211.241.239/nphMotionJpeg?Resolution=320x240&Quality=Standard Tampere Hacklab - Finland: http://tamperehacklab.tunk.org:38001/nphMotionJpeg?Resolution=640x480&Quality=Clarity Soltorget Pajala - Sweden: http://195.196.36.242/mjpg/video.mjpg Kaiskuru Skistadion - Norway: http://77.222.181.11:8080/mjpg/video.mjpg webrtc: listen: ":8555" #ice_servers: # - urls: [ "stun:localhost:3478" ] # username: "" # credential: "" Access the webinterface of go2rtc and get the link of your stream. Use the link as for your browser frame in the visualization. Depending on your device, you need to be able to access the file /etc/lighttpd/lighttpd.conf or /etc/lighttpd/webvisu.conf and change the contents similar to this one, otherwise you'll get CORS and CSP errors in the browser and you won't be able to view the stream on the webvisu: # Webvisu specific settings $SERVER["socket"] =~ port_webvisu_used_any { url.redirect += ( "^/webvisu/?$" => "/webvisu/webvisu.htm" ) $HTTP["url"] =~ "^/webvisu/?" { var.response_header_policy_webvisu = ( # CSP for WebVisu, allowing inline sources. "Content-Security-Policy" => "default-src 'self' 'unsafe-inline'; media-src *; frame-src *", # CORS for WebVisu, allowing any origin to access. "Access-Control-Allow-Origin" => "*", # Tell older browsers that this page can only be displayed if all ancestor # frames are same origin to the page itself. "X-Frame-Options" => "SAMEORIGIN" ) # Response header policy for WebVisu setenv.set-response-header = var.response_header_policy_webvisu setenv.set-response-header += var.response_header_policy_common }
Last updated: 2023-11-14

Post by timvh on Detect "Cancel" Press in FileOpenSave Dialog CODESYS Forge talk (Post)
Maybe there is a better way, but a long time ago I created a test application that worked like this: With a button I opened the dialog and I added a "Input configuration - OnDialogClosed" "Execute ST-Code" action to this same button which called the following Function when the dialog was closed: F_OnFileDialogClosed(pClientData); Below this Function which handled the result: // This function is called from the visualization when the dialog is closed. FUNCTION F_OnFileDialogClosed : BOOL VAR_INPUT pClientData : POINTER TO VisuElems.VisuStructClientData; END_VAR VAR dialogMan : VisuElems.IDialogManager; FileOpenCloseDialog : VisuElems.IVisualisationDialog; result : VisuElems.Visu_DialogResult; _sFileName : STRING(255); END_VAR // the DialogManager is provided via the implicitly available VisuManager dialogMan := VisuElems.g_VisuManager.GetDialogManager(); IF dialogMan <> 0 AND pClientData <> 0 THEN FileOpenCloseDialog := dialogMan.GetDialog('VisuDialogs.FileOpenSave'); // gets the FileOpenSave dialog IF FileOpenCloseDialog <> 0 THEN result := FileOpenCloseDialog.GetResult(); // gets the result (OK, Cancel) of the dialog IF result = VisuElems.Visu_DialogResult.OK THEN // Original code gvlFile.FileListProvider(); _sFileName := CONCAT(gvlFile.FileListProvider._stDirectory, gvlFile.FileListProvider.stFile); // do something with this file name... END_IF END_IF END_IF
Last updated: 2023-09-19

Post by sturmghost on Initialization of visualization variables and cyclic code execution CODESYS Forge talk (Post)
I'm looking for a smart and short way to implement initialization of visualization variables depending on the visualization input. For an easy example consider a rectangle which rests at XPos := 0 when the input state is false and at XPos := 50 when the input state is true. My visualization variables look like this: VAR_IN_OUT State : BOOL; END_VAR VAR XPos : INT; END_VAR I put this rectangle via a visualization frame element into another visualization and link a frame reference variable with the state to it. If the variable is true, the rectangle should rest at XPos := 50 and false at XPos := 0 at visualization init but how should I assign the 50 or 0 to the internal visualization variable XPos? I would need some init-methode for the visualization but I dont want a global init-method for such tasks. I want to do it inside of the visualization element but I can't see any solution for this? It would be good to be able to define ST-code within the visualization element which runs cyclic at each VISU_TASK task-cycle then I could just check the input state and change the XPos accordingly. Does someone have a solution?
Last updated: 2023-10-01

Post by riccardo on VisuElems.CurrentUserGroupId is not stable CODESYS Forge talk (Post)
GoodMorning everyone. I have a system that, in case of alarm, have to block. When the operator logs in must have to acknoledge the alarm and should operate in the system freely. To perform this I detect the logged User by (VisuElems.CurrentUserGroupID <> 0) with a similar code to the the following: PROGRAM AlarmMngt VAR alarm : BOOL:= FALSE; Ack : BOOL:= TRUE; PushBottonOpening : BOOL:= FALSE; Valve : BOOL := FALSE; Flag: BOOL := FALSE; END_VAR IF alarm AND Ack AND (NOT Flag) THEN valve := FALSE; PushBottonOpening := FALSE; Ack := FALSE flag := TRUE; ELSIF (NOT alarm) AND Ack THEN flag := FALSE; END_IF (* if the system is in alarm but there is a logged operator that acknowledge the alarm the system allows the valve opening.*) IF (VisuElems.CurrentUserGroupID <> 0) AND Ack AND Alarm AND PushBottonOpening THEN Valve := TRUE; ELSIF (VisuElems.CurrentUserGroupID = 0) AND Alarm THEN valve := FALSE; END_IF The problem I have is in the last 5 lines of the code: Even if there is a logged in user, the GroupID variable is subjected to a refresh that cyclically set for an instant it to 0 and this close the valve making difficult to the user to work Now I solved it creating a time hysteresys cycle but it is not a good solution. Someone is able to explane me why the GroupID variable is sobjected to this refresh and how to stabilize to avoiding it? Thank you in advance, Riccardo
Last updated: 2023-11-10

Post by open on How to create a stopwatch? CODESYS Forge talk (Post)
Hi @ph0010421, I tried the program the TimeTaken is calculated when stop is triggered. I want the TimeTaken to be continuously calculated and counting when a BOOL variable is true. I tried to program this way: Declaration: PROGRAM PLC_PRG VAR bStartStop: BOOL := FALSE; // Start/Stop button bReset: BOOL := FALSE; // Reset button bRunning: BOOL := FALSE; // Flag indicating whether the stopwatch is running tStartTime: TIME; // Variable to store the start time tElapsedTime: TIME; // Variable to store the elapsed time END_VAR Implementation: // Main program logic IF bReset THEN // Reset button pressed, reset the stopwatch bRunning := FALSE; tElapsedTime := T#0s; ELSIF bStartStop THEN // Start/Stop button pressed, toggle the running state IF bRunning THEN // Stop the stopwatch bRunning := FALSE; ELSE // Start the stopwatch bRunning := TRUE; tStartTime := tElapsedTime; END_IF; END_IF // Update the elapsed time when the stopwatch is running IF bRunning THEN tElapsedTime := tElapsedTime + T#1s; // Adjust the time increment as needed END_IF However counting of the seconds is not accurate. I tried changing the main task cycle time interval to 1000ms. The counting of seconds become slower. (see attached) Please help
Last updated: 2023-12-08

Post by ph0010421 on How to create a stopwatch? CODESYS Forge talk (Post)
Do you need an 'hours-run' counter? And 1 second resolution is ok? I think you're over-thinking it. (The task time needs to be < 1second) Have a look at the LAD... Then, the time in seconds can be made into hh:mm:ss with this FUNction Declarations: FUNCTION funSecondsToStringTime: string VAR_INPUT InSeconds: UDINT; END_VAR VAR AsString: STRING; Minutes: UDINT; Hours: UDINT; Seconds: UDINT; MinutesAsString: STRING(2); HoursAsString: STRING(2); SecondsAsString: STRING(2); END_VAR and the code: Hours := InSeconds / 60 / 60; //Derive hours Minutes := (InSeconds - (Hours * 60 * 60)) / 60; //Derive minutes Seconds := InSeconds - ((Hours * 60 * 60) + (Minutes * 60));//Derive seconds HoursAsString := UDINT_TO_STRING(Hours); MinutesAsString := UDINT_TO_STRING(Minutes); SecondsAsString := UDINT_TO_STRING(Seconds); IF LEN(HoursAsString) = 1 THEN HoursAsString := CONCAT('0',HoursAsString); END_IF; IF LEN(MinutesAsString) = 1 THEN MinutesAsString := CONCAT('0',MinutesAsString); END_IF; IF LEN(SecondsAsString) = 1 THEN SecondsAsString := CONCAT('0',SecondsAsString); END_IF; AsString := CONCAT(HoursAsString, ':'); //assemble string AsString := CONCAT(AsString,MinutesAsString); AsString := CONCAT(AsString,':'); AsString := CONCAT(AsString, SecondsAsString); funSecondsToStringTime := AsString;
Last updated: 2023-12-08

Post by nz-dave on Bool turning on in case stament in wrong state? CODESYS Forge talk (Post)
I had the FB called via a for loop to call a few instances of my FB I have removed it the for loop and just called them 1 by 1. Seems to have sorted the problem. tho, i have other FB's and for loops doing the same thing but they are all fine. below is basically what was happening. var: mVibrator : ARRAY[1..GVL_Settings.Number_Of_Products] OF Main_Vibrator; end_var Controller(PRG) call: FOR v := 1 TO GVL_Settings.Number_Of_Products BY 1 DO; mVibrator[v] (); END_FOR So at state 30: the mVibrator[1].start was turning on 30: Main_Mixer.Start := TRUE; Process_State := 2; IF Main_mixer.Done THEN Main_Mixer.Start := FALSE; Control_State := 40; END_IF but its not till state 50: that it is actual in the code. 50: Main_Suction_valve.Open_Input := TRUE; mVibrator[1].Start := TRUE; Process_State := 4; IF GVL_Weigh_hopper.LoadCell_Weight = 0 THEN Main_Suction_valve.Open_Input := FALSE; mVibrator1.Start := FALSE; Control_State := 60; END_IF Thanks for your input.
Last updated: 2023-12-16

Post by vipul on Multicast udp CODESYS Forge talk (Post)
Hi, Good afternoon can anybody help me with UDP Multicast code. I am not able to send or recieve data when code is dumped on linux device. Below is my code. Declaration: PROGRAM udp_multicast VAR oneTimeFlag :UINT :=0; state: INT:=0; driver: UDP.UDPDriver; //port : UDP.Port;//moved to GVL src_ipAddr_ud: UDINT; src_ipAddr_st:STRING := '192.168.127.155';//'192.168.1.155';//ipms ip address dst_ipAddr_ud:UDINT; group_ipAddr_st:STRING := '239.1.5.10'; //group_ipAddr_ud:UDINT; result: SysTypes.RTS_IEC_RESULT; //result of recieve function. bind: UDINT; //result of binding. resultCreate:SysTypes.RTS_IEC_RESULT;//result of port creation. timer:BLINK; temFlag :INT:= 0; post:INT :=0; checksumFunc:checksumXor; localStringBuf:STRING[500]; chksum:BYTE; dataBuffer:POINTER TO BYTE; checksumString:ARRAY[0..5] OF BYTE; recvSize:__XINT; errorCode:UDINT; joinGroupErrorCode:UDINT; END_VAR ************8 Implementation: IF oneTimeFlag <> 1 THEN oneTimeFlag:=1; resultCreate := driver.CreatePort(ADR(GVL.port)); src_ipAddr_ud := UDP.IPSTRING_TO_UDINT(sIPAddress:= src_ipAddr_st); GVL.group_ipAddr_ud := UDP.IPSTRING_TO_UDINT(sIpAddress:= group_ipAddr_st); GVL.port.IPAddress := src_ipAddr_ud; GVl.port.ReceivePort:= GVL.src_port;//port on which messages are expected. GVl.port.SendPort := GVL.dest_port; GVl.port.OperatingSystem := 0; //0- any system GVL.port.Socket :=3; //3- socket type is multicast bind := GVL.port.Bind(udiIPAddress:=src_ipAddr_ud,); GVl.port.JoinGroup(udiGroupAddress:= GVL.group_ipAddr_ud,udiInterfaceAddress:= src_ipAddr_ud,eLogCode=>joinGroupErrorCode); END_IF timer(ENABLE:=TRUE,TIMELOW:=T#100MS,TIMEHIGH:=T#100MS); IF timer.OUT = TRUE THEN GVL.port.Send(udiIPTo:=GVL.group_ipAddr_ud,GVL.dest_port,pbyData:=ADR(GVL.writeData),diDataSize:=SIZEOF(GVL.writeData)); ELSE SysMemSet(ADR(GVL.readData[0]),0,SIZEOF(GVL.readData)); result := GVl.port.Receive(ADR(GVL.readData),diDataSize:=SIZEOF(GVL.readData),udiIPFrom=>dst_ipAddr_ud,diRecvSize=>recvSize,eLogCode=>errorCode); SysMemMove(ADR(GVL.readDataBuf[0]),ADR(GVL.readData[0]),SIZEOF(GVL.readData)); END_IF post:=LEN(GVL.readDataBuf);
Last updated: 2024-01-14

Post by mondinmr on Direct Pointers in IOMapping for EtherCAT with IoDrvEthercatLib.ETCSlave_Dia CODESYS Forge talk (Post)
I have found a very interesting solution using: IoConfigTaskMap IoConfigConnectorMap IoConfigChannelMap The first is the list of IO tasks. The second is the connector for each IO module in the IOMap. The third is the individual input or output on the IOMap. One of the properties of the connector is another pointer to a connector, which corresponds with the connector of the EtherCAT slave. Through this information, it is possible to understand to which EtherCAT slave an IO connectormap corresponds. I am attaching an FB that allows for the construction of an IO map and finding the pointer to the actual IOs in the IOMap based on the bitoffset. FUNCTION_BLOCK IOExplorer VAR_INPUT END_VAR VAR_OUTPUT END_VAR VAR inputChannels: COL.LinkedList; outputChannels: COL.LinkedList; ulintFactory: COL.UlintElementFactory; END_VAR METHOD inputAtBitOffsetOfConnector : POINTER TO BYTE VAR_INPUT conn: POINTER TO IoConfigConnectorMap; bitOffset: UDINT; END_VAR VAR it: COL.LinkedListIterator; itf: COL.IElement; elem: COL.iUlintElement; channelInfo: POINTER TO ADVChannelInfo; bitOffsetR: UDINT; END_VAR inputChannels.ElementIterator(it); WHILE it.HasNext() DO it.Next(itfElement => itf); __QUERYINTERFACE(itf, elem); {warning disable C0033} channelInfo := TO___UXINT(elem.UlintValue); {warning restire C0033} IF channelInfo^.connectorField = conn THEN IF bitOffsetR = bitOffset THEN inputAtBitOffsetOfConnector := channelInfo^.addr; RETURN; END_IF bitOffsetR := bitOffsetR + channelInfo^.size; ELSE bitOffsetR := 0; END_IF END_WHILE inputAtBitOffsetOfConnector := 0; END_METHOD METHOD outputAtBitOffsetOfConnector : POINTER TO BYTE VAR_INPUT conn: POINTER TO IoConfigConnectorMap; bitOffset: UDINT; END_VAR VAR it: COL.LinkedListIterator; itf: COL.IElement; elem: COL.iUlintElement; channelInfo: POINTER TO ADVChannelInfo; bitOffsetR: UDINT; END_VAR outputChannels.ElementIterator(it); WHILE it.HasNext() DO it.Next(itfElement => itf); __QUERYINTERFACE(itf, elem); {warning disable C0033} channelInfo := TO___UXINT(elem.UlintValue); {warning restire C0033} IF channelInfo^.connectorField = conn THEN IF bitOffsetR = bitOffset THEN outputAtBitOffsetOfConnector := channelInfo^.addr; RETURN; END_IF bitOffsetR := bitOffsetR + channelInfo^.size; ELSE bitOffsetR := 0; END_IF END_WHILE outputAtBitOffsetOfConnector := 0; END_METHOD METHOD scanIO VAR_INPUT END_VAR VAR numTasks: DINT := IoConfig_Globals.nIoConfigTaskMapCount; tType: WORD; ioTask: POINTER TO IoConfigTaskMap; numCon: WORD; connector: POINTER TO IoConfigConnectorMap; numCh: DWORD; channelInfo: POINTER TO ADVChannelInfo; iTsk: DINT; iCon: WORD; iCh: DWORD; i: DINT; _tmpConnList: COL.IList; elem: COL.IUlintElement; itf: COL.IElement; tmpCh: POINTER TO ADVChannelInfo; lastE: DINT; e: COL.COLLECTION_ERROR; e1: Error; END_VAR VAR_INST lF: COL.ListFactory; END_VAR IF outputChannels.CountElements() > 0 OR inputChannels.CountElements() > 0 THEN RETURN; END_IF _tmpConnList := lF.CreateDynamicList(16, 16); //Iterate through all IO tasks FOR iTsk := 0 TO numTasks - 1 DO ioTask := ADR(IoConfig_Globals.pIoConfigTaskMap[iTsk]); //Store the type of the task (Input or Output) tType := ioTask^.wType; numCon := ioTask^.wNumOfConnectorMap; //Iterate through all connectors of the task FOR iCon := 0 TO numCon - 1 DO connector := ADR(ioTask^.pConnectorMapList[iCon]); numCh := connector^.dwNumOfChannels; //Iterate through all channels of the connector FOR iCh := 0 TO numCh - 1 DO //Create a new channel info object and fill it with the address, connector and size of the channel //Connectors is address of field connector in this case like EtherCAT slave //Address is the address of the IOMap //Size is the size of channel data in bits in IOMap channelInfo := __NEW(ADVChannelInfo); channelInfo^.addr := connector^.pChannelMapList[iCh].pbyIecAddress; channelInfo^.connectorField := connector^.pConnector; channelInfo^.size := connector^.pChannelMapList[iCh].wSize; //We put the channel info a temporary ordered list //Order is based on the address of IOMap lastE := TO_DINT(_tmpConnList.CountElements()) - 1; FOR i := 0 TO lastE DO _tmpConnList.GetElementAt(udiPosition := TO_UDINT(i), itfElement => itf); __QUERYINTERFACE(itf, elem); {warning disable C0033} tmpCh := TO___UXINT(elem.UlintValue); {warning restire C0033} //If the address of the channel is smaller than the address of the channel in the list IF tmpCh^.addr > channelInfo^.addr THEN //Insert the channel in the list at the current position _tmpConnList.InsertElementAt(TO_UDINT(i), ulintFactory.Create(TO_ULINT(channelInfo))); //Clear the channel info pointer channelInfo := 0; //Exit the loop i := lastE + 1; END_IF END_FOR //If the channel info is not 0, it means that the channel was not inserted in the list IF channelInfo <> 0 THEN //Add the channel to the end of the list elem := ulintFactory.Create(TO_ULINT(channelInfo)); _tmpConnList.AddElement(elem); END_IF END_FOR //Iterate temporary list and add the channels to the input or output list lastE := TO_DINT(_tmpConnList.CountElements()) - 1; FOR i := 0 TO lastE DO _tmpConnList.GetElementAt(udiPosition := TO_UDINT(i), itfElement => itf); __QUERYINTERFACE(itf, elem); {warning disable C0033} tmpCh := TO___UXINT(elem.UlintValue); {warning restire C0033} //If type is input, add the channel to the input list IF tType = TaskMapTypes.TMT_INPUTS THEN e := inputChannels.AddElement(ulintFactory.Create(TO_ULINT(tmpCh))); //If type is output, add the channel to the output list ELSIF tType = TaskMapTypes.TMT_OUTPUTS THEN e := outputChannels.AddElement(ulintFactory.Create(TO_ULINT(tmpCh))); ELSE __DELETE(tmpCh); END_IF END_FOR //Clear the temporary list _tmpConnList.RemoveAllElements(); END_FOR END_FOR END_METHOD
Last updated: 2024-02-13

Post by dominggus on when going online, stuck on "Syncing file "visuelemsdatetime.tl_datetime.txt" CODESYS Forge talk (Post)
Hi, We are currently using a Raspberry Pi 4 CM4 module in a EdgeBox RPI 200 - Industrial Edge Controller running the latest CODESYS Runtime Package 4.11.0.0. On the PC (actually an Intel Macbook Pro running Windows 10 in Parallels) we run CODESYS V3.5.19.50. Yesterday end of day when I was about to logoff and head home, I wanted to send the latest build to the Raspberry I clicked the Login button to compile a new version and then sync the application and all the files, it get's stuck on the last file to sync (see attached screenshot). This takes eternally, although sometimes, when I use my SFTP client (Cyberduck) and go into the raspberry and refresh the directory /var/opt/codesys/PlcLogic/visu/, or when I open the actual file visuelemsdatetime.tl_datetime.txt, it gets un-stuck (forcing a refresh, which might fix the syncing issue) and CODESYS continues and I can click the Start button to start the application. But this SFTP force refresh trick does not always help either... What could be the issue here? network connectivity? Can someone please help me out?
Last updated: 2024-03-02

Post by joshskellig on Publish a JSON payload via MQTT Publish (using IIot Libraries) CODESYS Forge talk (Post)
I am trying to figure out how to get a JSON payload to properly publish to my MQTT Broker. I am able to generate JSON using the examples from Codesys, but when I send that payload via MQTT there are characters that are extra or not recognized by my MQTT client. Any idea what could be causing it? PROGRAM PLC_PRG VAR hostname: STRING := 'localhost'; port: UINT := 1883; topic: WSTRING(1024) := "testing/"; payload: BYTE; factory : JSON.JSONDataFactory; eDataFactoryError : FBF.ERROR; pJsonData : POINTER TO JSON.JSONData := factory.Create(eError => eDataFactoryError); fb_JBuilder : JSON.JSONBuilder; wsValue : WSTRING := "Value1"; diRootIndex, diObject1Index : DINT; iValue : INT := 1234; jsonArrayWriter : JSON.JSONByteArrayWriter; wsJsonData : WSTRING(1000); xFirst : BOOL := TRUE; mqttClient: MQTT.MQTTClient; mqttPublish: MQTT.MQTTPublish; mqttPublishProperties: MQTT.MQTTPublishProperties := (bPayloadFormatIndicator := 1, wsContentType := "application/json"); END_VAR // Json Functionality IF xFirst THEN fb_JBuilder(pJsonData := pJsonData, diRootObj => diRootIndex); fb_JBuilder.SetKeyWithValue("Key1", wsValue, diParentIndex := diRootIndex); diObject1Index := fb_JBuilder.SetKeyWithObject("Key2", diParentIndex := diRootIndex); fb_JBuilder.SetKeyWithValue("Key3", iValue, diParentIndex := diObject1Index); xFirst := FALSE; END_IF jsonArrayWriter(pwData := ADR(wsJsonData), udiSize := SIZEOF(wsJsonData), jsonData := pJsonData^, xAsyncMode := FALSE); MSU.StrTrimW(pString:= ADR(wsJsonData)); // MQTT Functionality mqttClient( sHostname:=hostname, uiPort:=port, eMQTTVersion:=MQTT.MQTT_VERSION.V5 ); mqttPublish( mqttClient:=mqttClient, pbPayload:=ADR(wsJsonData), udiPayloadSize:=SIZEOF(wsJsonData), wsTopicName:=topic, mQTTPublishProperties:=mqttPublishProperties );
Last updated: 2024-04-10

Post by culius on JSON CODESYS Forge talk (Post)
Hey guys, I am trying to write a JSON. First time after login in PLC after download everthing works. But when I want to change values during runtime and try to recreate the JSON nothing happens. When forcing the xStart as an impulse i want to recreate it and see 2 as Key3 instead of 1 from the first run. Any Idea how to make this work? PROGRAM test VAR factory : JSON.JSONDataFactory; eDataFactoryError : JSON.FBF.ERROR; pJsonData : POINTER TO JSON.JSONData := factory.Create(eError => eDataFactoryError); fb_JBuilder : JSON.JSONBuilder; wsValue : WSTRING; diRootIndex, diObject1Index : DINT; iValue : INT; jsonArrayWriter : JSON.JSONByteArrayWriter; wsJsonData : WSTRING(1000); xFirst : BOOL := TRUE; END_VAR IF xFirst THEN fb_JBuilder(pJsonData := pJsonData, diRootObj => diRootIndex); wsValue := "Value1"; fb_JBuilder.SetKeyWithValue("Key1", wsValue, diParentIndex := diRootIndex); diObject1Index := fb_JBuilder.SetKeyWithObject("Key2", diParentIndex := diRootIndex); iValue := iValue + 1 ; // -----------!!! secound run should increment key3!!!!------------ fb_JBuilder.SetKeyWithValue("Key3", iValue, diParentIndex := diObject1Index); xFirst := FALSE; END_IF jsonArrayWriter(xExecute := TRUE, pwData := ADR(wsJsonData), udiSize := SIZEOF(wsJsonData), jsonData := pJsonData^, xAsyncMode := FALSE); Kind Regards
Last updated: 2024-04-30

Post by kblundy on Change the Opening Position of the Dialog using VU.FbOpenDialog CODESYS Forge talk (Post)
I hope the community can help me with this. I need to use the Visu Utils FbOpenDialog to control the opening and closing of a dialog. I have the Opening and Closing working, but I can’t get the dialogue's position to be controlled. The code looks like this: PROGRAM OPEN_DIALOG VAR xOpenLatchSettingDialog : BOOL; TopLeftDialog : VisuStructPoint ; fbOpenLatchSettingsDialog : VU.FbOpenDialog ; END_VAR IF xOpenLatchSettingDialog THEN xOpenLatchSettingDialog:= FALSE ; TopLeftDialog.iX := 100; TopLeftDialog.iY := 23; fbOpenLatchSettingsDialog(sDialogName := 'visu_AlarmLatchSettings', xExecute := xOpenLatchSettingDialog , xModal := TRUE, itfClientFilter := VU.Globals.OnlyTargetVisu, pTopLeftPosition := ADR(TopLeftDialog)); CloseVisuDialog(sDialogName:= 'visu_AlarmLatchSettings'); ELSE xOpenLatchSettingDialog:= TRUE ; IF fbOpenLatchSettingsDialog.xError THEN xOpenLatchSettingDialog := FALSE; END_IF END_IF I can't seem to work out a way to make the values in TopLeftDialog.iX and TopleftDialog.iY be passed correctly in the call and for it to change the position of the dialogue box. The code is compiled, but the position has not been changed. Any guidance or suggestions for revising this code would be incredibly valuable. Your insights could be the key to solving this issue.
Last updated: 2024-05-05

Post by mxj262 on FB having single input but initialized with Array CODESYS Forge talk (Post)
I am adding elements of an ARRAY using pointer to access each element inside a FOR loop and the FOR loop does not stop! What is the right way to use pointers in such case?? I have another loop that is not using pointer and it stops but the loop using pointer keep on adding. METHOD FB_Init: BOOL VAR_INPUT bInitRetains: BOOL; // TRUE: the retain variables are initialized (reset warm / reset cold) bInCopyCode: BOOL; // TRUE: the instance will be copied to the copy code afterward (online change) END_VAR VAR_IN_OUT // basically REFERENCE TO window_buffer: ARRAY [*] OF INT; // array of any size END_VAR THIS^.windowPtr := ADR(window_buffer[0]); THIS^.windowSize := UPPER_BOUND(window_buffer, 1) - LOWER_BOUND(window_buffer, 1) + 1; FUNCTION_BLOCK FB500 VAR_INPUT END_VAR VAR_OUTPUT END_VAR VAR windowPtr: POINTER TO INT; windowSize: DINT; currentIndex: UINT; element1:INT; element2:INT; i:INT; j:INT; sum:DINT:=0; END_VAR element1:=windowPtr[0]; // read the first element of the Array dynamic memorry element2:=windowPtr[1]; FOR i:=0 TO (TO_INT(windowSize-1)) BY 1 DO // this loop does not stop Sum:=sum + windowPtr[i]; END_FOR FOR j:=0 TO 5 BY 1 DO // this loop stops j:=j+1; END_FOR https://ibb.co/k3DhkZT
Last updated: 2024-05-06

Post by hanoues on setting date and time on CPX-E CODESYS Forge talk (Post)
Hello, Can anybody here tell me how to modify the time and date on my CPX-E? I used the code I found on CODESYS online help, but it doesn't work. What am I missing? FUNCTION current_date_time : STRING VAR stUTC_Timestamp : SysTime; //utc time // ULINT#1528280694913 stLocal_TimeStamp : SysTime; //local time but is in general equal // ULINT#1528280694913 stdNow : SysTimeDate; //local time in an object to access each number (day, month...) dtNow : DATE_AND_TIME;//DT#2018-6-6-10:24:54 todNow : TIME_OF_DAY; // TOD#10:24:54.913 datNow : DATE; // D#2018-6-6 END_VAR SysTimeRtcHighResGet(stUTC_Timestamp); // ULINT#1528273494913 SysTimeRtcConvertHighResToLocal(stUTC_Timestamp, stdNow); //convert UTC ULINT to Local SysTime // stdNow.wYear = UINT#2018 // stdNow.wMonth = UINT#6 // stdNowy.wDay = UINT#6 // stdNow.wHour = UINT#10 // stdNow.wMinute = UINT#24 // stdNow.wSecond = UINT#54 // stdNow.wMilliseconds = UINT#913 // stdNow.wDayOfWeek = UINT#3 // stdNow.wYday = UINT#157 SysTimeRtcConvertDateToHighRes(stdNow, stLocal_TimeStamp); // ULINT#1528280694913 dtNow := TO_DT(stLocal_TimeStamp / 1000 ( ms )); // DT#2018-6-6-10:24:54 todNow := TO_TOD(stLocal_TimeStamp MOD TO_ULINT(T#1D)); // TOD#10:24:54.913 datNow := TO_DATE(dtNow); // D#2018-6-6 (convert to appropriate string) current_date_time := concat('$N[', TO_STRING(dtNow)); current_date_time:= concat(current_date_time,'.'); current_date_time:= concat(current_date_time, TO_STRING(stdNow.wMilliseconds)); current_date_time:= concat(current_date_time,'] - '); RETURN;
Last updated: 2024-05-21

Post by wollvieh on Display minutes as hours & minutes CODESYS Forge talk (Post)
Here a code for an Operation Counter with : days,hours,minutes,seconds as an example, maybe it points you the right direction ? FUNCTION_BLOCK OperationDayHour VAR_INPUT IN : BOOL; // Betrieb Takt : BOOL; // 1Hz Systemtakt END_VAR VAR_OUTPUT BetrTag : UDINT; // Ausgabe Betriebstage Betrstd : UDINT; // Ausgabe Betriebsstunden Betrmin : UDINT; // Ausgabe Betriebsminuten Betrsec : UDINT; // Ausgabe Betriebsekunden BetrString : STRING; // Ausgabe als String END_VAR VAR ///Erkennung Taktflanke Flanke: R_TRIG; END_VAR VAR_IN_OUT BetrsecAbsolut: UDINT; //Ein/Ausgangsvariable Betriebssekunden RETAIN !!! END_VAR Flanke(CLK:= Takt, Q=> ); (*Erkennung Taktflanke*) IF (IN AND Flanke.Q) THEN (*Sekunden hochzählen*) BetrsecAbsolut := BetrsecAbsolut + 1; END_IF Betrsec := BetrsecAbsolut MOD 60; Betrmin := ( BetrsecAbsolut / 60) MOD 60; Betrstd := ( BetrsecAbsolut / 60 / 60 ) MOD 24; BetrTag := ( BetrsecAbsolut / 60 / 60 /24 ); BetrString := RIGHT ( UDINT_TO_STRING( BetrTag + 100000),5); BetrString := CONCAT (BetrString, 'd_'); BetrString := CONCAT (BetrString,RIGHT ( UDINT_TO_STRING( Betrstd + 100000),5)); BetrString := CONCAT (BetrString, 'h_'); BetrString := CONCAT (BetrString, RIGHT ( UDINT_TO_STRING( Betrmin + 100),2)); BetrString := CONCAT (BetrString, 'm_'); BetrString := CONCAT (BetrString, RIGHT ( UDINT_TO_STRING( Betrsec + 100),2)); BetrString := CONCAT (BetrString, 's');
Last updated: 2024-05-27

Post by mp9876 on Problem using MeasureFrequence FB CODESYS Forge talk (Post)
Hi everyone, new at Codesys and PLC programming in general. I am using Codesys Win V3.5 SP20 I would like to measure an encoder's frequency output (obtaining that pulse train from Factory IO) and intended to use the MeasureFrequence FB (Intern/CAA/Utilities/CAA Mathematics/3.5.19.0). As mentioned in the title what I need to measure is low frequency, such as lower than 40hz (a cycle every 25mS) or so; I could even go lower frequency if required as this is for test purposes) therefore I am not expecting problem measuring a low frequency with that FB The library in question appears to be installed as I can retrieve it from the Library Repository. I can also see it from the Device's Library Manager. Problem arises when I am trying to instantiate this particular FB. I go like this: VAR MeasF:MeasureFrequence; END_VAR Please note that as soon as I start typing the "MeasureFrequence", the MeasureFrequence comes out as a viable option in auto-typing; seems to indicate that the FB is recognized somehow. But there is no way I can compile this as it comes back with the following: C0046: Identifier 'MeasureFrequence' not defined. Tried to rename that to ABC instead of MeasF; same issue. Possibly that the library is not properly installed ? Placeholder ? I would greatly appreciate a bit of guidance if possible. Thank you and regards, Mike
Last updated: 2024-06-24

Post by timvh on How to implement an interface (IElement)? CODESYS Forge talk (Post)
See: https://forge.codesys.com/prj/codesys-example/element-collect/home/Home/ This contains an application "OnlineChangeSafeLinkedListExample". What you should do is create a new interface which has your "Priority" property. Then your FB should extend the base element function block and implement your own interface: E.g. FUNCTION_BLOCK MyElement EXTENDS COL.LinkedListElementBase IMPLEMENTS I_MyInterface Then the __QUERYINTERFACE does the magic to check if your "element" also implements your interface. Something like this: // Compares this element with itfElement. // Returns 0 if the elements are equal, < 0 if the element is less than itfElement, // > 0 if the element is greater than itfElement. // This method will be called from sorted collections (e.g. |COL.SortedList|) to sort the elements. // IMPORTANT: The underlying value to be compared with MUST NOT be changed during the lifecycle of the object. METHOD ElementCompareTo : INT VAR_INPUT (* The element to compare*) itfElement : COL.IElement; END_VAR VAR itfIntElement : I_MyInterface; xResult : BOOL; END_VAR // We use integer iInt1 for sorting. xResult := __QUERYINTERFACE(itfElement, itfIntElement); IF xResult THEN IF iInt1 < itfIntElement.Priority THEN ElementCompareTo := -1; ELSIF iInt1 > itfIntElement.Priority THEN ElementCompareTo := 1; ELSE ElementCompareTo := 0; END_IF ELSE ElementCompareTo := -1; END_IF
Last updated: 2024-07-22

Post by trusty-squire on CNC - How to manipulate SMC_GeoInfo objects CODESYS Forge talk (Post)
I have an application using CNC GCode interpolation, but I need to modify the GCode provided to the PLC based on certain parameters. I am currently attempting to modify the SMC_GeoInfo objects in the SMC_OutQueue using the code below. Note that all the other code is pretty standard and works fine, but when I add the below it errors. PROGRAM TEST VAR fbReadCncFile : SMC_ReadNCFile2; fbCncInterpreter : SMC_NCInterpreter; arrCncInterpreter : ARRAY[1..99] OF SMC_GeoInfo; pGeoInfo: POINTER TO SMC_GeoInfo; giGeoInfo: SMC_GeoInfo; // ... END_VAR // ... Some code here in order to read CNC file using SMC_ReadNCFile2 and provide to SMC_NCInterpreter pGeoInfo := SMC_GetObj(poq:=ADR(fbCncInterpreter.poqDataOut), n:=1); IF pGeoInfo <> 0 THEN giGeoInfo := pGeoInfo^; // Do some manipulation here, then update the queue at the same position MC_SetObj(poq:=ADR(fbCncInterpreter.poqDataOut) , n:=0 , pgi:=ADR(giGeoInfo) ); END_IF It throws an error when I get to the line giGeoInfo := pGeoInfo^; Error: EXCEPTION [AccessViolation] occured: App=[Sim.Device.Application], Task=[PathTask] How do I use SMC_GetObj and access the data? It creates a pointer with the value as shown in the photo, but all the dereferenced values say dereference of invalid pointer.
Last updated: 2024-07-26

Post by julianramirez on ModbusFB write update CODESYS Forge talk (Post)
Hello everyone, I am testing the ModbusFB library tcp server and so far I am able to create holding registers successfully, however, I am trying to identify after each write which registers got updated (i.e. function code, write value). I can even see the var udiNumWriteRequests, which increases with every write. I noticed that there is logging with the LogStatusInfo method. After I call it I am able to read in the console stuff that I want. Nevertheless, this is only available at the logs and is not easy to decode because it consists on several messages, I would like to know if there is a way for me to retrieve this information from the function itself with pointers or if there is any way to copy the logs messages (assuming that I can filter them with the LoggingOptions to only show what I need) inside the runtime code and not in the console. Thanks for your help :)
Last updated: 2024-09-16

Post by koerbejm on Probleme beim aktivieren von Lizenzen CODESYS Forge talk (Post)
Liebe Codesys-Gemeinde, ich habe folgendes Problem und bitte um Hilfe: Um eine auf meinem dem Raspberry Pi laufende Steuerung ohne große Mühe duplizieren zu können, habe ich mir ein Image der SD Karte mit Win32 Diskimager erstellt. Dieses konnte ich bisher ohne weitere Probleme auf eine weitere Micro-SD karte ausrollen. Anschließend habe ich mich via Putty auf den PI geschaltet, die vorherige Lizenz (die ja für den vorheringen PI zulässig war) gelöscht über - sudo su - rm -r /var/opt/codesys/cmact_licenses/ - reboot Um dann via Codesys 3.5 SP16 Patch 4 eine neue Lizenznummer ">>Tools>Lizenzmanager>Lizenz aktivieren" zu aktivieren und das wars. Durch die Umstellung des Lizensierungsverfahrens klappt diese Variante nun nicht mehr. Ich habe mir neue Lizenzen von Codesys gekauf, doch sobald ich diese in die Ticket-ID eintrage und aktivieren möchte bekomme ich folgende Fehlermeldung: ReturnCode: 403046401, An internal error has occured. Please try it again later. (siehe Bild im Anhang "Fehler_Codesys3.5V16.png") Ich habe dann meine Codesys-Version auf Version 3.5 SP20 geupdated und das selbe versucht mit dem Resultat, dass ich nun folgende Fehlermeldung erhalte: "Der ausgewählte Container "...." paßt nicht zu Ihrem Ticket. Bitte wählen Sie einen passenden aus." --> Siehe Bild im Anhang "Fehler_Codesys3.5V120.png" Was genau kann/muss ich tun, damit ich einfach wie bisher meine Steuerungen duplizieren kann? Verwendete Hardware: Raspberry Pi 3 Model B+ Verwendete Lizenz: Codesys Control Basic L Viele Grüße und Danke, Jan
Last updated: 2024-10-23

Post by fefefede on Get the numer of day CODESYS Forge talk (Post)
Hello i tro to create a program to turn on or off the air condition in relationship temperature and numer of day. I can't get the number of day. I try this after installing SysTime library but this not work and have this error on debug ------ Build started: Application: Device.Sim.Device.Application ------- Typify code... Generate code... [ERROR] giorno_accensione_aria: PLC_PRG Device: PLC Logic: Application: C0032: Cannot convert type 'Unknown type: 'SysTimeCore(TRUE)'' to type 'TIME' [ERROR] giorno_accensione_aria: PLC_PRG Device: PLC Logic: Application: C0035: Program name, function or function block instance expected instead of 'SysTimeCore' [ERROR] giorno_accensione_aria: PLC_PRG Device: PLC Logic: Application: C0032: Cannot convert type 'Unknown type: 'DayOfWeek(CurrentTime)'' to type 'INT' [ERROR] giorno_accensione_aria: PLC_PRG Device: PLC Logic: Application: C0035: Program name, function or function block instance expected instead of 'DayOfWeek' [INFORMATION] giorno_accensione_aria: PLC_PRG Device: PLC Logic: Application: C0181: Related position Build complete -- 4 errors, 0 warnings : No download possible PROGRAM PLC_PRG VAR Temperatura: UDINT; AriaCondizionata: BOOL := FALSE; CurrentDayOfWeek: INT; //Variabile Giorno CurrentTime: TIME; GiornoDellaSettimana: INT; DayOfWeek: INT; END_VAR CurrentTime := SysTimeCore(TRUE); // Ottieni l'ora corrente CurrentDayOfWeek := DayOfWeek(CurrentTime); CASE GiornoDellaSettimana OF 1: // Azioni per Lunedì 2: // Martedì se più 10° accend altrimenti spegni IF Temperatura >= 10 THEN AriaCondizionata := TRUE; ELSE AriaCondizionata := FALSE; END_IF 3: // Mercoledì se più di 50° accendi altrimenti spegni IF Temperatura >=50 THEN AriaCondizionata := TRUE; ELSE AriaCondizionata := FALSE; END_IF 4: // Giovedì se più di 40° accendi altrimenti spegni IF Temperatura >=40 THEN AriaCondizionata := TRUE; ELSE AriaCondizionata := FALSE; END_IF 5: // Venerdì se più di 50° accendi altrimenti spegni IF Temperatura >=50 THEN AriaCondizionata := TRUE; ELSE AriaCondizionata := FALSE; END_IF 6: // Sabato se più di 25° accendi altrimenti spegni IF Temperatura >=25 THEN AriaCondizionata := TRUE; ELSE AriaCondizionata := FALSE; END_IF 7: // Domenica sempre spenta AriaCondizionata := FALSE; END_CASE
Last updated: 2023-09-14

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 john-robinson on Limiting Memory Access of an Array to Within its Bounds CODESYS Forge talk (Post)
Recently we had an issue regarding some simple code to calculate a rolling average. The code indexes from zero to 199 to properly store the current input into a circular buffer which then allows us to calculate a rolling average: VAR input_5s : REAL; outs_arr : ARRAY[0..199] OF REAL; i : USINT := 0; END_VAR ___ //this code runs every five seconds, calculating a rolling average outs_arr[i] := input_5s; i := i + 1; output := OSCAT_BASIC.ARRAY_AVG(ADR(outs_arr), SIZEOF(outs_arr)); IF i >= SIZEOF(outs_arr) THEN i := 0; END_IF There is a simple bug in this code where the index will be set to 0 when it has surpassed the length of the array in bytes (800 in this case) rather than larger than the number of reals in the array (200). The solution here is simple, replacing i >= SIZEOF(outs_arr) with i >= SIZEOF(outs_arr)/SIZEOF(outs_arr[0]). In this example when the index increased to 201 and the line outs_arr[201] := input_5s was called, codesys arbitrarily wrote to the address in memory that is where outs_arr[201] would be if the array was that long. I would like to find a way to wrap the codesys array inside of a wrapper class that checks if an input is within the bounds of an array before writing to that value. I know how I would implement that for a specific array, I could create a method or class that takes an input of an array of variable length, ie. ARRAY[*] OF REAL, but I don't know how to make this for any data type. I am wondering if anyone has ever done anything similar to this, or has any better suggestions to ensure that none of the programmers on this application accidentally create code that can arbitrarily write to other locations in memory.
Last updated: 2024-03-05

<< < 1 .. 5 6 7 8 > >> (Page 7 of 8)

Showing results of 187

Sort by relevance or date