Post by ihatemaryfisher on Sorting array of any-sized structure
CODESYS Forge
talk
(Post)
In my machine's operation, I need to display multiples tables containing arrays of structured variables. The arrays change during operation, and my supervisor has advised me to write a new bubble-sort for each array. I think I can make a function to sort an array of any data type. This was my own project, and I'm a relatively new coder. I want to know the weaknesses in my approach, and a better method, if one exists. As far as I can test, the function accepts an array of a structured variable of any size, and sort it by any VAR in that structure. But it relies heavily on pointers, which I've heard are bad practice? Function call: // SORT BY BYTE-SIZED VAR IF xDoIt[6] THEN FUNBubbleSortSansBuffer( IN_pbySourcePointer := ADR(astArray[1]), // address of first byte in first element of array IN_pbyComparePointer:= ADR(astArray[1].byCompByte), // points to first byte of the comparing variable (variable you sort by) IN_uiStructureSize := SIZEOF(TYPE_STRUCTURE), // size, in bytes, of the structured variable IN_uiCompareSize := SIZEOF(astArray[1].byCompByte), // size, in bytes, of the comparing variable (variable you sort by) diArrayElements := UPPER_BOUND(astArray,1), // number of elements in array IN_xSmallToLarge := xSortOrder // whether to sort by small2large or large2small ); END_IF Function: FUNCTION FUNBubbleSortSansBuffer : BOOL VAR_INPUT IN_pbySourcePointer : POINTER TO BYTE; // points to beginning of array (first byte of first element) IN_pbyComparePointer: POINTER TO BYTE; // points to first byte of the comparing variable (variable you sort by) IN_uiStructureSize : UINT; // size, in bytes, of the structured variable IN_uiCompareSize : UINT; // size, in bytes, of the comparing variable (variable you sort by) diArrayElements : DINT; // number of elements in array IN_xSmallToLarge : BOOL; // whether to sort by small2large or large2small END_VAR VAR j : DINT; // repeat iteration over array until array ends i : DINT; // iterarte over array, swapping when necesary k : DINT; // iterator from 1 to size of structure (stepping 'through' a single element in array) dwSize : DWORD; // internal var for use in MEMUtils.MemCpy(<size>) // FOR SORTING BY BYTE VAR pbySourcePointer : POINTER TO BYTE; pbySourcePointer2 : POINTER TO BYTE; pbyComparePointer : POINTER TO BYTE; pbyComparePointer2 : POINTER TO BYTE; pbyPointerToBuffer : POINTER TO BYTE; // pointer to single byte buffer byBufferByte : BYTE; // single byte buffer END_VAR dwSize := UINT_TO_DWORD(IN_uiStructureSize); // get structure size (number of bytes) pbyPointerToBuffer := ADR(byBufferByte); // assign pointer to address of buffer byte (because MEMUtils.MemCpy requires a pointer input) CASE IN_uiCompareSize OF // depending on the size of the VAR to sort by (current functionality for BYTE and WORD/INT 1: // BYTE (8 BIT) FOR j := 1 TO diArrayElements DO // for number of elements in array FOR i := 1 TO (diArrayElements-1) DO // same thing, but row[i+1] row is included in swap logic pbySourcePointer := IN_pbySourcePointer + dwSize*(i-1); // point at #1 byte in array element[i] pbySourcePointer2 := pbySourcePointer + dwSize; // point at #1 byte in array element[i+1] // NOTE: because of memory locations, each array element is offset from one another by a number of bytes equal to the size of the structure // We can "walk" from array[i] to array[i+1] via steps equal to the size of the structure // e.g., ADR(array[i+1]) == ADR(array[i]) + SIZEOF([array datatype]) pbyComparePointer := IN_pbyComparePointer + dwSize*(i-1); // point to sorting variable in array element[i] pbyComparePointer2 := pbyComparePointer + dwSize; // point to sorting variable in array element[i+1] // using sort order (small -> large/large -> small) IF SEL(IN_xSmallToLarge, (pbyComparePointer2^ > pbyComparePointer^),(pbyComparePointer2^ < pbyComparePointer^)) THEN // This is where it gets tricky. We've identified pointers for the starting bytes of aArray[i] and aArray[i+1] // and we know the size of aArray[i]. We are going to swap individual bytes, one at a time, from aArray[i] and aArray[i+1] // this allows us to use only a single byte var as a buffer or temporary data storage // e.g., consider a structure consisting of a word, a byte, and a string. it is stored like this // |------WORD-------| |--BYTE-| |STRING------...| // astArray[1] == 1000 0100 0010 0001 1100 0011 1010 1010.... etc // astArray[2] == 0001 0010 0100 1000 0011 1100 0101 0101.... etc // performing a single swap (copy into a buffer, etc.) of the first byte of each array element creates this // astArray[1] == 0001 0100 0010 0001 1100 0011 1010 1010.... etc // astArray[2] == 1000 0010 0100 1000 0011 1100 0101 0101.... etc // incrementing the pointer adresses for the swap by 1 and swapping again swaps the next byte in each array element // astArray[1] == 0001 0010 0010 0001 1100 0011 1010 1010.... etc // astArray[2] == 1000 0100 0100 1000 0011 1100 0101 0101.... etc // continuing this from k to SIZEOF(TYPE_STRUCTURE) results in a toally swapped row FOR k := 1 TO IN_uiStructureSize DO // copy single byte[k] of array element 1 to buffer MEMUtils.MemCpy(pbyDest := (pbyPointerToBuffer), pbySrc := (pbySourcePointer+k-1), dwSize := 1); // copy single byte[k] of array element 2 to 1 MEMUtils.MemCpy(pbyDest := pbySourcePointer+k-1, pbySrc := (pbySourcePointer2+k-1), dwSize := 1); // copy buffer to byte[k] array element 2 MEMUtils.MemCpy(pbyDest := (pbySourcePointer2+k-1), pbySrc := pbyPointerToBuffer, dwSize := 1); END_FOR END_IF END_FOR END_FOR
Last updated: 2023-08-17
Post by macros8 on Translation - How to get text as reference in Frames translated?
CODESYS Forge
talk
(Post)
Hi, thanks for the link. Maybe I create elements in incorrect way. I always use Interface Editor to create variables which are used inside element (see pics). After that I place element in my visu and use Reference property to link variable or set the value. In that case the value of string is not transferred to general text list for translation as I mentioned before. Do I have to all properties which influence behavior of my element create in Frame configuration instead? What´s the difference to the Interface editor? Thanks a lot. M.
Last updated: 2024-01-02
Post by umdee on Error when monitoring LAD programs
CODESYS Forge
talk
(Post)
System Information from the computer being used: OS Name Microsoft Windows 11 Pro Version 10.0.22631 Build 22631 Other OS Description Not Available OS Manufacturer Microsoft Corporation System Manufacturer Dell Inc. System Model Latitude 5500 System Type x64-based PC System SKU 08B9 Processor Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz, 2112 Mhz, 4 Core(s), 8 Logical Processor(s) BIOS Version/Date Dell Inc. 1.3.11, 6/11/2019 SMBIOS Version 3.2 Embedded Controller Version 255.255 BIOS Mode UEFI BaseBoard Manufacturer Dell Inc. BaseBoard Product 0M14W7 BaseBoard Version A00 Platform Role Mobile Secure Boot State On PCR7 Configuration Elevation Required to View Windows Directory C:\WINDOWS System Directory C:\WINDOWS\system32 Boot Device \Device\HarddiskVolume1 Locale United States Hardware Abstraction Layer Version = "10.0.22621.2506" User Name CARDASSIA-IX\Engineer Time Zone Eastern Daylight Time Installed Physical Memory (RAM) 16.0 GB Total Physical Memory 15.8 GB Available Physical Memory 4.67 GB Total Virtual Memory 18.5 GB Available Virtual Memory 2.52 GB Page File Space 2.63 GB Page File C:\pagefile.sys Kernel DMA Protection Off Virtualization-based security Not enabled Windows Defender Application Control policy Enforced Windows Defender Application Control user mode policy Off Device Encryption Support Elevation Required to View Hyper-V - VM Monitor Mode Extensions Yes Hyper-V - Second Level Address Translation Extensions Yes Hyper-V - Virtualization Enabled in Firmware Yes Hyper-V - Data Execution Protection Yes
Last updated: 2024-03-19
Post by hjohnson123 on Automatically selecting a visualization element
CODESYS Forge
talk
(Post)
I'm looking to automatically select a text field element in my visualization. I'm not sure if this is possible, as I don't know how to get the data on specific elements. I am wanting automatic selection of the text field, as I am using a keyboard-input barcode scanner, which should always input the barcode into the text field whenever a barcode is scanned. Does anyone know if this can be done?
Last updated: 2024-05-21
Post by jinlee on Camera RTSP Feed
CODESYS Forge
talk
(Post)
Hi, I followed your guidance and used go2rtc. There is a link generated from go2rtc I can copy into the web browser element in the visualisation. It somehow only appear within the software when it is running, but not on the webvisu. I want to display the camera feed onto the webvisu. My camera is reolink 810a which supports IP protocol. My project is pretty simple, just a web browser element with assigned URL.
Last updated: 2024-09-17
Post by trusty-squire on Display Units/Scale on Path3D visualization
CODESYS Forge
talk
(Post)
Hi, Is it possible to display the units along the X,Y axis of the Path3D element? It correctly shows the CNC path to be followed, but there's no indication of scale or size of what's being displayed. I looked at the documentation and my first inclination is that this is not possible, and the option option would be to somehow recreate the Path3D functionality into the XY Chart visu element - which is not ideal. Any suggestions or pointers would be appreciated!
Last updated: 7 days ago
Post by mondinmr on Shared Memory Access Issues
CODESYS Forge
talk
(Post)
In Windows I need create shared memory in PC software and connect from CODESYS. If shm is not GLOBAL doesn't work due different users between runtime and PC software. PC software need admin privileges. Name need "Global\\" before key. Very unsafe!!! If CODESYS create shared I cannot find key PC side. In Linux I can create shared memory as standard user, bind in the runtime docker, use keys without any "Global\\". Much more safe!!! If CODESYS create shared you need play with permissions to use app as standard user. I prefer create form PC software as standard user.
Last updated: 2024-01-30
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 ofey on Symbol configuration / GVL
CODESYS Forge
talk
(Post)
Hi! I have som variables that I communicate to a Modbus Master. These variables are declared in a "Global Variable List" where I have assigned them memory addresses. To organize this mapping I want to make a MODBUS list where I show all the variable names together with the memory address. Is there an easy way to export this list from CODESYS? Either through script or some export function maybe?
Last updated: 2023-10-11
Post by ofey on Symbol configuration / GVL
CODESYS Forge
talk
(Post)
Hi! I have som variables that I communicate to a Modbus Master. These variables are declared in a "Global Variable List" where I have assigned them memory addresses. To organize this mapping I want to make a MODBUS list where I show all the variable names together with the memory address. Is there an easy way to export this list from CODESYS? Either through script or some export function maybe?
Last updated: 2023-10-11
Post by tvm on Ranges, Lambdas, on Fixed arrays of structs
CODESYS Forge
talk
(Post)
Have you looked at this? https://forge.codesys.com/prj/codesys-example/element-collect/home/Home/ It's not exactly what you're looking for, but I've been able to make some things work more efficiently using this library.
Last updated: 2023-08-31
Post by awatson on User Management (Configuration Dialog)
CODESYS Forge
talk
(Post)
Hello I have just posted on a topic - about the reference for the element you have taken a screen shot for - "REFERENCE TO VisuUserMgmtProvider" https://forge.codesys.com/forge/talk/Visualization/thread/0591457fe4/ - do you know anything about it?
Last updated: 2023-11-17
Post by macros8 on Viewing PDF in WebBrowser Visual Element
CODESYS Forge
talk
(Post)
No, you can´t. I have only tried different browsers on my PC and then on my HMI device. Unfortunately the device´s browsers did not support pdf file as I needed so I had to switch to *.txt.
Last updated: 2024-03-01
Post by andrew-budaiev on Tank Level Display
CODESYS Forge
talk
(Post)
If I want to display level in the tank, what's usual approach? Is there tank or vessel element I can use? I see there is bar display, but I can't make it fill the shape I need.
Last updated: 2024-04-03
Post by tomas111 on Text List Fallback Value
CODESYS Forge
talk
(Post)
What version of codesys? Need to avoid in any specific element? Try writing %s in the text, it should work. Or better yet, attach a screenshot.
Last updated: 2024-04-17
Post by damian177 on Visualization - table element
CODESYS Forge
talk
(Post)
Hi, In my application I use table elemnt with filled by STRING ARRAY. I would like to implement the following functionality : When I click on second row, that this row will be cleared. Anyone can help me?
Last updated: 2024-04-25
Post by sturmghost on Codesys Visu Update Frame Parameters No Dialog Appears to update
CODESYS Forge
talk
(Post)
This is still a huge problem. Does someone know how to update the frame references (not manually for every frame-element...)?
Last updated: 2024-08-12
Post by maralani on Retain memory change to ZERO
CODESYS Forge
talk
(Post)
Hi, thanks for help, I add some retain variable , then some other variable change to zero , andI was not able to change the value
Last updated: 2023-09-19
Post by nano on Library for arrays
CODESYS Forge
talk
(Post)
habe a look at __new and __delete operators. have in mind that in this case u have a look at memory see https://help.codesys.com/api-content/2/codesys/3.5.15.0/en/_cds_operator_new/
Last updated: 2024-01-14
Post by smartcoco on Bit / Bool data types in function parameters
CODESYS Forge
talk
(Post)
Memory addressing is measured in bytes, with BOOL occupying one byte. BIT is quite unique as it occupies one bit. So, try not to use BIT in the program. You can use the Unpack function to solve your problem.
Last updated: 2024-01-18
Post by dkugler on Unable to load dynamic modules (Download failed: Application=Application)
CODESYS Forge
talk
(Post)
Maybe shared memory is an opinion for you to give it a try: https://content.helpme-codesys.com/en/CODESYS%20Examples/_ex_cds_shared_memory_communication.html
Last updated: 2024-02-16
Post by gurkan on OPCUA array max length?
CODESYS Forge
talk
(Post)
2000 works. When testing with UA Expert there is a timeout from the OPCUA Server when trying to subscribe to the variable CPU do not seems to be to affected. The memory(RAM) however is building up
Last updated: 2024-02-19
Post by john-robinson on Limiting Memory Access of an Array to Within its Bounds
CODESYS Forge
talk
(Post)
Thanks Tim! This was exactly the functionality we were looking for. We are already using implicit checks to check for divide by 0 errors, we will add implicit checking for array bounds.
Last updated: 2024-03-06
Post by hjohnson123 on PLC Memory consumption?
CODESYS Forge
talk
(Post)
Hi, How can you access the <root> of the Linux system? I'm struggling with this as the code above results in an invalid handle, as it cannot access '/'.</root> I am using Control for Raspberry Pi for context. Thanks.
Last updated: 2024-06-05
Post by viktorr on ShareMemory library documentation
CODESYS Forge
talk
(Post)
Hello, I was wondering if there was further documentation on the SharedMemory library in CodeSys outside of the code example provided, or maybe a way to access the source code of the shared memory implementation. Thank you in advance for any advice. - Viktor
Last updated: 2024-07-03
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
.