Unable to Connect to Modbus RTU Device
CODESYS Forge
talk
(Thread)
Unable to Connect to Modbus RTU Device
Last updated: 2024-09-03
Unable to Connect to Modbus RTU Device
CODESYS Forge
talk
(Thread)
Unable to Connect to Modbus RTU Device
Last updated: 2024-09-04
How to revert to previous version library
CODESYS Forge
talk
(Thread)
How to revert to previous version library
Last updated: 2024-09-06
Unable to add alarm configuration object to project
CODESYS Forge
talk
(Thread)
Unable to add alarm configuration object to project
Last updated: 2024-09-27
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 otbeka on CmpCrypto CryptoGenerateHash Not Outputting
CODESYS Forge
talk
(Post)
Unfortunately I noticed that, and tried: * using CryptoGeteAlgorithmByID within the function call * inputting the raw byte pointer as a testByte * instantiating the _hHash handle within the function body * using a different cryptoID or the raw DINT values from the RtsCryptoID DUT ... to no avail. The pReturn value is also set to 0, which would indicate that it is OK, right? This is odd given that the function is the same within the CryptoDemo example project here, just with a newer version. Is it possible that there is something wrong with the way my bytestring is being set up? I use the following DUTs here: TYPE MESSAGE : STRING(255); END_TYPE TYPE HASH_CODE : ARRAY[0..19] OF BYTE; END_TYPE
Last updated: 2024-09-06
Post by nico01 on Integer with comma in visualization
CODESYS Forge
talk
(Post)
Hello everyone, I created a visualization with a lot of REAL, with one or two digits after the decimal point. This causes me problems in terms of rounding and memory... is it possible to display an integer with a comma, like with PROFACE or SIEMENS? It's just an "abuse" of display, the comma is just on the visualization. This limits the memory (16 versus 64 bytes) and rounding is easier to manage... See print screen on proface software THANKS
Last updated: 2023-09-20
Post by ojz0r on INT_TO_WORD function not working
CODESYS Forge
talk
(Post)
That calculation will not work the way you expect it to. If PumpFillSpeed is limitied to 0-50 then the only whole number would be 50/50 = 1 everything else is 0.0-0.9999... and since you are using word and integer only 50 would work since there is no representation for mantissa in integer values. Declare a temporary real variable and do the calculation and then do a REAL_TO_WORD in the DRV2Speed assignment.
Last updated: 2024-01-26
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 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
Connection to device closed
CODESYS Forge
talk
(Thread)
Connection to device closed
Last updated: 2023-08-25
Sysmac Studio to Codesys
CODESYS Forge
talk
(Thread)
Sysmac Studio to Codesys
Last updated: 2023-09-20
OPC UA Client unable to connect to CeDeSys OPC UA Server but able to connect to other OPC UA Server
CODESYS Forge
talk
(Thread)
OPC UA Client unable to connect to CeDeSys OPC UA Server but able to connect to other OPC UA Server
Last updated: 2018-10-30
Pointer To
CODESYS Forge
talk
(Thread)
Pointer To
Last updated: 2009-01-23
Sysfile copy to server
CODESYS Forge
talk
(Thread)
Sysfile copy to server
Last updated: 2012-01-13
Pointer to Softmotion axis
CODESYS Forge
talk
(Thread)
Pointer to Softmotion axis
Last updated: 2023-11-23
CoDeSys to access
CODESYS Forge
talk
(Thread)
CoDeSys to access
Last updated: 2007-01-15
How to remove user ?
CODESYS Forge
talk
(Thread)
How to remove user ?
Last updated: 2018-07-03
string to time
CODESYS Forge
talk
(Thread)
string to time
Last updated: 2010-03-08
how to add TextList
CODESYS Forge
talk
(Thread)
how to add TextList
Last updated: 2012-07-06
Button to close browser
CODESYS Forge
talk
(Thread)
Button to close browser
Last updated: 2022-09-22
Connect to MCP 3008
CODESYS Forge
talk
(Thread)
Connect to MCP 3008
Last updated: 2018-09-16
How to implement IVisuStreamReader
CODESYS Forge
talk
(Thread)
How to implement IVisuStreamReader
Last updated: 2023-03-02
Variable name to string
CODESYS Forge
talk
(Thread)
Variable name to string
Last updated: 2015-03-19
To search for an exact phrase, put it in quotes. Example: "getting started docs"
To exclude a word or phrase, put a dash in front of it. Example: docs -help
To search on specific fields, use these field names instead of a general text search. You can group with AND
or OR
.