Codesys 浣跨敤鍏变韩鍐呭瓨 鎵撻氶氳-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 2213|鍥炲: 2

Codesys 浣跨敤鍏变韩鍐呭瓨 鎵撻氶氳

[澶嶅埗閾炬帴]
  • TA鐨勬瘡鏃ュ績鎯
    鎿︽睏
    2019-8-13 14:13
  • 绛惧埌澶╂暟: 32 澶

    [LV.5]甯镐綇灞呮皯I

    鍙戣〃浜 2020-8-7 16:30:36 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
    Codesys V3.5 骞冲彴   鎻愪緵浜嗗簱SysShm,鍏朵腑鍖呭惈浜嗗叡浜唴瀛樻搷浣滅殑鎺ュ彛鍑芥暟锛
    SysSharedMemoryClose;
    SysSharedMemoryCreate;
    SysSharedMemoryDelete;
    SysSharedMemoryGetPointer;
    SysSharedMemoryOpen2;
    SysSharedMemoryRead;
    SysSharedMemoryReadByte;
    SysSharedMemoryWrite;
    SysSharedMemoryWriteByte;

    涓庡叾杩涜鍏变韩鍐呭瓨閫氳鐨勫钩鍙癓inux,window;涓嬬殑缂栫▼Demo:
    Linux:
    [C] 绾枃鏈煡鐪 澶嶅埗浠g爜
    #include <stdio.h>[/font][/color][/align]
    #include <stdlib.h>
    #include <sys/mman.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <string.h>
     
    
    struct DataExchange {
        int i1;
        int i2;
    };
     
    
    int main(int argc, char **argv)
    
     
    
    {
    
        struct DataExchange *pRead, *pWrite;
    
        char sSharedMemReadName[100] = "_CODESYS_SharedMemoryTest_Write";
    
        char sSharedMemWriteName[100] = "_CODESYS_SharedMemoryTest_Read";
    
        int fdRead = shm_open(sSharedMemReadName, O_CREAT | O_RDWR, S_IRWXU | S_IRWXG);
    
        printf("Shared Memory Read: %s %d\n\n",sSharedMemReadName, fdRead);
    
        ftruncate(fdRead, sizeof(*pRead));
    
        pRead = mmap(0, sizeof(*pRead), PROT_READ | PROT_WRITE, MAP_SHARED, fdRead, 0);
    
        close(fdRead);
    
        int fdWrite = shm_open(sSharedMemWriteName, O_CREAT | O_RDWR, S_IRWXU | S_IRWXG);
    
        printf("Shared Memory Write: %s %d\n\n",sSharedMemWriteName, fdWrite);
    
        ftruncate(fdWrite, sizeof(*pWrite));
    
        pWrite = mmap(0, sizeof(*pWrite), PROT_READ | PROT_WRITE, MAP_SHARED, fdWrite, 0);
    
        close(fdWrite);
    
        do
    
            sleep(1);
    
            printf("pRead->i1: %d pRead->i2: %d pWrite->i1: %d pWrite->i2: %d\n",
    
             pRead->i1, pRead->i2, pWrite->i1, pWrite->i2);
    
            printf("Press 'Enter' to increment values or 'q' and then 'Enter' to quit\n");
    
            pWrite->i1++;
    
            pWrite->i2--;
    
        } while (getchar() != 'q');
    
        munmap(pRead, sizeof(*pRead));
    
        shm_unlink(sSharedMemReadName);
    
        munmap(pWrite, sizeof(*pWrite));
    
        shm_unlink(sSharedMemWriteName);
    
        exit(0);
    
    }


    鍦↙inux 涓嬬殑缂栫▼娉ㄦ剰 shm_open();鑻ヤ娇鐢ㄤ娇鏈夐棶棰橈紝鍙互鐢╫pen()鍑芥暟鏇夸唬銆
    Linux涓嬪叡浜唴瀛樼殑瀹炶川锛氭槸鍦/dev/shm/   鏂囦欢澶逛笅鍒涘缓鐩稿簲鏂囦欢锛岃矾寰勪负锛  /dev/shm/鏂囦欢鍚嶏紱
    Codesys鑻ヨ繍琛屼簬Linux涓嬪垯鏄湪璇ヨ矾寰勫垱寤哄叡浜枃浠躲


    Windows骞冲彴锛孋++/ C # 缂栫▼锛
    C++:
    OpenFileMapping();
    CreateFileMapping();
    MapViewOfFile();
    GetProcessWorkingSetSize(); //鏌ヨ杩涚▼鏈澶э紝鏈灏忓伐浣滈泦鍐呭瓨澶у皬
    SetProcessWorkingSetSize(); //璁惧畾杩涚▼鏈澶э紝鏈灏忓伐浣滈泦鍐呭瓨澶у皬锛屽湪杩涚▼鎸傝捣锛屾垨鏈灏忓寲鏃讹紝灏嗛儴鍒嗗唴瀛樹氦鎹㈠埌铏氭嫙鍐呭瓨銆
    VirtualLock();   //閿佸畾杩涚▼鐨勮櫄鎷熷湴鍧绌洪棿鐨勬寚瀹氬潡鍒扮墿鐞嗗唴瀛樸


    C#:
    [C++] 绾枃鏈煡鐪 澶嶅埗浠g爜
    using System;
    using System.IO.MemoryMappedFiles;
    using System.Runtime.InteropServices;
    using System.Threading;
    
    namespace SharedMemoryWin
    {
    
        // Example structure for data exchange
        internal struct DataExchange
        {
            internal Int32 i1;
            internal Int32 i2;
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                DataExchange dataExchangeRead, dataExchangeWrite;           
                dataExchangeWrite.i1 = 0;
                dataExchangeWrite.i2 = 0;
               
                Console.Out.WriteLine("Press 'q' to quit");
    
                int dataSIze = Marshal.SizeOf(typeof(DataExchange));
               
                // Open a mapped file with read access and one with write access.
                using (var mmfRead = MemoryMappedFile.CreateOrOpen("_CODESYS_SharedMemoryTest_Write", dataSIze))
                using (var mmfWrite = MemoryMappedFile.CreateOrOpen("_CODESYS_SharedMemoryTest_Read", dataSIze))
                {
                    bool quit = false;
                    while (!quit)
                    {
                        using (var accessorRead = mmfRead.CreateViewAccessor(0, dataSIze, MemoryMappedFileAccess.Read))
                        using (var accessorWrite = mmfWrite.CreateViewAccessor(0, dataSIze, MemoryMappedFileAccess.Write))
                        {
                            // Read the structure
                            accessorRead.Read(0, out dataExchangeRead);
                            // Write the structure
                            accessorWrite.Write(0, ref dataExchangeWrite);
    
                            // Display the values
                            Console.Out.Write("Read i1: {0} i2: {1}       Write i1: {2} i2: {3}\r",
                                                dataExchangeRead.i1,
                                                dataExchangeRead.i2,
                                                dataExchangeWrite.i1,
                                                dataExchangeWrite.i2);
    
                            // Wait a second
                            Thread.Sleep(1000);
    
                            // Increment sample values
                            dataExchangeWrite.i1++;
                            dataExchangeWrite.i2--;
    
                            // Check quit condition
                            if(Console.KeyAvailable)
                                if (Console.ReadKey().KeyChar == 'q')        
                                    quit = true;
                        }
                    }
                }
            }
        }
    }

    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

  • TA鐨勬瘡鏃ュ績鎯
    闅捐繃
    2020-10-19 10:23
  • 绛惧埌澶╂暟: 1 澶

    [LV.1]鍒濇潵涔嶅埌

    鍙戣〃浜 2020-9-3 16:44:40 | 鏄剧ず鍏ㄩ儴妤煎眰
    杩欑鏄笉鏄痗osesys鍜孋#鍙兘鍦ㄥ悓涓鍙扮數鑴戜笂
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
  • TA鐨勬瘡鏃ュ績鎯

    2023-8-4 14:45
  • 绛惧埌澶╂暟: 54 澶

    [LV.5]甯镐綇灞呮皯I

    鍙戣〃浜 2021-2-25 14:14:30 | 鏄剧ず鍏ㄩ儴妤煎眰
    RTE 鍙互鐢ㄥ悧
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

    鏈増绉垎瑙勫垯

    椤堕儴qrcode搴曢儴
    鍏虫敞閰峰痉缃戣闃呭彿锛岃幏鍙栨洿澶氳祫璁紒

    QQ|灏忛粦灞|鎵嬫満鐗|Archiver|閰峰痉璁哄潧 ( 鑻廔CP澶16065247鍙-1 )|缃戠珯鍦板浘

    GMT+8, 2024-11-24 01:22 , Processed in 0.173568 second(s), 65 queries .

    閰峰痉缃

    © 2001-2013 Hicodesys. 鎶鏈敮鎸 by 閰峰痉缃

    蹇熷洖澶 杩斿洖椤堕儴 杩斿洖鍒楄〃