鍏变韩鍐呭瓨 - C#涓嶤oDeSys閫氳-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 4711|鍥炲: 4

鍏变韩鍐呭瓨 - C#涓嶤oDeSys閫氳

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

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

    鍙戣〃浜 2020-6-17 12:12:18 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
    娴嬭瘯鐜锛
    1銆丆ODESYS 3.5.13.0锛堟柊寤篊odesys_ShareMemory椤圭洰锛
    2銆丼haredMemoryCommunication.package锛圕odesysy鍏变韩鍐呭瓨搴擄級
    閾炬帴锛https://pan.baidu.com/s/1JM0RXUR8h1L5UE2pVhY4BQ
    鎻愬彇鐮侊細ql7w

    SharedMemoryCommunication.package (23.03 MB, 涓嬭浇娆℃暟: 62)

    3銆乂isual Studio2015锛堟柊寤篊#_ShareMemory椤圭洰锛
    涓銆佸叡浜唴瀛樻蹇
    1銆侀【鍚嶆濅箟锛屽叡浜唴瀛樺氨鏄缓绔嬩竴鍧椾緵鍗忎綔杩涚▼鍏变韩鐨勫唴瀛樺尯鍩燂紝澶氫釜杩涚▼鍙互閫忚繃姝ゅ叡浜尯鍩熻鍙栨垨鑰呭啓鍏ユ暟鎹潵浜ゆ崲淇℃伅锛
    2銆侀氫俊绀烘剰鍥撅細
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    浜屻丆oDeSys绋嬪簭
    1銆佹坊鍔犲簱鏂囦欢
    路 SysShm,3.5.8.0 (System)
    路 SysTypes2 Interfaces,3.5.4.0 (System)
    1锛夋墦寮搴撶鐞嗗櫒锛圠ibrary Manager锛,閫夋嫨鈥滄坊鍔犲簱锛圓dd Library锛夆,鐐光滈珮绾э紙Advanced...锛夆;
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    2锛夊湪鎼滅储妗嗭紙String for a fulltext search...锛変腑鍒嗗埆杈撳叆SysShm鍜孲ysTypes鎼滅储娣诲姞SysShm,3.5.8.0 鍜孲ysTypes2 Interfaces,3.5.4.0 ,
    閫変腑鎼滅储鍒扮殑搴擄紝鐐光淥K鈥濈‘璁ゆ坊鍔狅紝
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    娣诲姞瀹屾垚鍗冲彲鍦ㄥ簱绠$悊鍣紙Library Manager锛変腑鏌ョ湅鍒般
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    搴撴枃浠朵粙缁嶏細
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    2銆佸垱寤烘暟鎹粨鏋
    鍏变韩鍐呭瓨杩涜鏁版嵁鍏变韩浜や簰闇瑕侀氳繃鏁版嵁缁撴瀯鏉ヨ繘琛屻
    閫変腑搴旂敤锛圓pplication锛夊彸閿坊鍔犲璞★紙Add Object锛,閫夋嫨鈥淒UT鈥濓紝
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    鍒涘缓鏁版嵁缁撴瀯锛岃緭鍏ユ暟鎹粨鏋勫悕绉帮紝閫夋嫨绫诲瀷锛圱ype锛夛紝鐐光淎dd鈥
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    鏈緥鍒嗗埆鍒涘缓涓や釜鏁版嵁缁撴瀯锛孲tr_ParaFromHMI鍜孲tr_ParaToHMI
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    3銆佸垱寤篠hareMemory
    鏂板缓ST锛堢粨鏋勬枃鏈級绋嬪簭锛屽垱寤哄叡浜唴瀛樸
    绋嬪簭椤甸潰姒傝锛
    1锛夊0鏄庡彉閲忋佸叡浜唴瀛樺悕鍜屽姛鑳藉嚱鏁扮瓑


    • [C] 绾枃鏈煡鐪 澶嶅埗浠g爜
      PROGRAM ShareMemory
      VAR
              
              bStart: BOOL:= FALSE;
              ReadHandle: RTS_IEC_HANDLE:= RTS_INVALID_HANDLE;
              WriteHandle: RTS_IEC_HANDLE:= RTS_INVALID_HANDLE;
              szNameRead: STRING:= 'CODESYS_MEMORY_READ';                //澹版槑鍏变韩鍐呭瓨鐨勮鍙栧唴瀛樺悕绉
              szNameWrite: STRING:= 'CODESYS_MEMORY_WRITE';        //澹版槑鍏变韩鍐呭瓨鐨勫啓鍏ュ唴瀛樺悕绉
              ulPhysicalAddressRead: __UXINT:= 0;
              ulPhysicalAddressWrite: __UXINT:= 0;
              ulSizeRead: __UXINT:= 1024;
              ulSizeWrite: __UXINT:= 1024;
              ResultRead: ARRAY[0..2] OF RTS_IEC_RESULT;                //杩斿洖杩愯閿欒鐮
              ResultWrite: ARRAY[0..2] OF RTS_IEC_RESULT;
              
              SMRead: __UXINT;
              SMWrite: __UXINT;
              ulOffsetRead: __UXINT:= 0;
              ulOffsetWrite: __UXINT:= 0;
              
      END_VAR




    2锛夌▼搴忓叿浣撳疄鐜


    • [C] 绾枃鏈煡鐪 澶嶅埗浠g爜
      //Init Memory
      IF NOT bStart THEN
              ReadHandle:= SysSharedMemoryCreate(pszName:= szNameRead, ulPhysicalAddress:= ulPhysicalAddressRead, pulSize:= ADR(ulSizeRead), pResult:= ADR(ResultRead[0]));
              WriteHandle:= SysSharedMemoryCreate(pszName:= szNameWrite, ulPhysicalAddress:= ulPhysicalAddressWrite, pulSize:= ADR(ulSizeWrite), pResult:= ADR(ResultWrite[0]));
              IF RTS_INVALID_HANDLE <> ReadHandle AND RTS_INVALID_HANDLE <> WriteHandle THEN
                      bStart:= TRUE;
              END_IF
      END_IF
       
      //璇诲彇鏁版嵁
      IF RTS_INVALID_HANDLE <> ReadHandle THEN
              SMRead:= SysSharedMemoryRead(
              hShm:= ReadHandle,                                         //璇诲彇鍐呭瓨鐨勮澶囧彞鏌
              ulOffset:= ulOffsetRead,                        //璇诲彇鏁版嵁鐨勫亸绉诲湴鍧 
              pbyData:= ADR(GVL.GetPara),                 //鎸囧悜璇诲彇鏁版嵁鐨勭紦鍐插尯
              ulSize:= SIZEOF(Str_ParaFromHMI),         //璇诲彇鏁版嵁鐨勫瓧鑺傚ぇ灏        
              pResult:= ADR(ResultRead[1]));                //杩斿洖鎵ц鐨勯敊璇爜
      END_IF
       
      //鍐欏叆鏁版嵁
      IF RTS_INVALID_HANDLE <> WriteHandle THEN
              SMWrite:= SysSharedMemoryWrite(
              hShm:= WriteHandle,                                 //鍐欏叆鍐呭瓨鐨勮澶囧彞鏌
              ulOffset:= ulOffsetWrite,                         //鍐欏叆鏁版嵁鐨勫亸绉诲湴鍧
              pbyData:= ADR(GVL.SetPara),                 //鎸囧悜鍐欏叆鏁版嵁鐨勭紦鍐插尯
              ulSize:= SIZEOF(Str_ParaToHMI),         //鍐欏叆鏁版嵁鐨勫瓧鑺傚ぇ灏
              pResult:= ADR(ResultWrite[2]));                //杩斿洖鎵ц鐨勯敊璇爜
      END_IF





    涓夈丆#绋嬪簭
    1銆佸紩鐢ㄥ懡鍚嶇┖闂
    • [C] 绾枃鏈煡鐪 澶嶅埗浠g爜
      using System.IO.MemoryMappedFiles;      //寮曠敤鍏变韩鍐呭瓨鍛藉悕绌洪棿
      using System.Threading;                 
      using System.Runtime.InteropServices;





    2銆佸畾涔夋暟鎹粨鏋
    鏁版嵁缁撴瀯涓殑鍙橀噺鍚嶄笉涓瀹氶潪瑕佷笌Codesys鐨勬暟鎹粨鏋勫彉閲忓悕淇濇寔鐩稿悓锛堝缓璁畾涔変竴鑷达紝渚夸簬鏌ョ湅鍜岀鐞嗭級锛屼絾鏁版嵁缁撴瀯鍐呯殑鏁版嵁绫诲瀷鍜屾暟鎹绘暟蹇呴』淇濇寔涓鑷淬

    • [C] 绾枃鏈煡鐪 澶嶅埗浠g爜
          struct StrFromCodesys
          {
              internal bool bOut;
              internal int iOut;
              internal double fOut;
          }
          struct StrToCodesys
          {
              internal bool bIn;
              internal int iIn;
              internal double fIn;
          }
      




    3銆佸垱寤篠hareMemory
    1锛夊0鏄庡畾涔夊叡浜唴瀛樹娇鐢ㄧ殑API
    20200520165726312.png
    2锛夊叡浜唴瀛樺垵濮嬪寲锛屾敞鎰忔鏌appedFile鐨勫唴瀛樺悕涓嶤odesys鍐呭瓨鍚嶄竴鑷达紝杩欐牱鎵嶈兘纭繚璁块棶鍚屼竴鍧楀唴瀛樺湴鍧
    • [C] 绾枃鏈煡鐪 澶嶅埗浠g爜
       private void InitMemory()
              {
                  try
                  {
                      MMF_Write = MemoryMappedFile.CreateOrOpen("CODESYS_MEMORY_READ", 1024);        //鎵撳紑Codesys_Read鍐呭瓨鍖哄煙锛屾剰鎬濆氨鏄Codesys鐨勮鍙栧尯鍩熸槸C#鐨勫啓鍏ュ尯鍩
                      AccessorWrite = MMF_Write.CreateViewAccessor(0, Marshal.SizeOf(typeof(StrToCodesys)), MemoryMappedFileAccess.Write);
       
                      MMF_Read = MemoryMappedFile.CreateOrOpen("CODESYS_MEMORY_WRITE", 1024);        //鎵撳紑Codesys_Write鍐呭瓨鍖哄煙锛屾剰鎬濆氨鏄Codesys鐨勫啓鍏ュ尯鍩熸槸C#鐨勮鍙栧尯鍩
                      AccessorRead = MMF_Read.CreateViewAccessor(0, Marshal.SizeOf(typeof(StrFromCodesys)), MemoryMappedFileAccess.Read);
       
                  }
                  catch(Exception ex)
                  {
                      MessageBox.Show(ex.Message);
                  }
              }



    3锛夎鍙栨暟鎹
    • [C] 绾枃鏈煡鐪 澶嶅埗浠g爜
              private void ReadData()
              {
                  while(true)
                  {
                      try
                      {
                          Thread.Sleep(5);
                          AccessorRead.Read(0, out ParaFromCodesys);      //璇诲彇Codesys鐨勬暟鎹
                          Thread.Sleep(5);
                          if(ParaFromCodesys.bOut == true)
                              picbox_bRead.BackColor = Color.Red;
                          else
                              picbox_bRead.BackColor = Color.Gray;
       
                          textbox_iRead.Text = ParaFromCodesys.iOut.ToString("0");
                          textbox_fRead.Text = ParaFromCodesys.fOut.ToString("0.000");
       
                      }
                      catch(Exception ex)
                      {
                          MessageBox.Show(ex.Message);
                      }
                  }
              }




    4锛夊啓鍏ユ暟鎹




    • [C] 绾枃鏈煡鐪 澶嶅埗浠g爜
              private void btnWriteB(object sender, EventArgs e)
              {
                  ParaToCodesys.bIn = !ParaToCodesys.bIn;
                  AccessorWrite.Write(0, ref ParaToCodesys);
                  if(ParaToCodesys.bIn == true)
                  {
                      picbox_bWrite.BackColor = Color.Red;
                  }
                  else
                  {
                      picbox_bWrite.BackColor = Color.Gray;
                  }
              }
      



    鍥涖侀氫俊娴嬭瘯
    杩愯CoDeSys鍜孋#绋嬪簭锛岄氳繃璇诲彇鍜屽啓鍏ユ暟鎹祴璇曢氫俊缁撴灉
    1锛夐氫俊娴嬭瘯鍥剧墖
    watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM3ODQ2NjE3,size_16,color_FFFFFF,t_70.jpg
    2锛夐氫俊娴嬭瘯鍔ㄥ浘
    2020052017404935.gif

    +11
    涓嶈禐涓涓紵

    鏈杩戣皝璧炶繃

    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

    璇ョ敤鎴蜂粠鏈鍒

    鍙戣〃浜 2021-6-24 13:37:49 | 鏄剧ず鍏ㄩ儴妤煎眰
    璇烽棶缃戠洏閾炬帴澶辨晥浜嗭紝鍙互鍐嶅垎浜竴涓嬪悧
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒

    璇ョ敤鎴蜂粠鏈鍒

    鍙戣〃浜 2022-4-7 23:52:46 | 鏄剧ず鍏ㄩ儴妤煎眰

    璇烽棶缃戠洏閾炬帴澶辨晥浜嗭紝鍙互鍐嶅垎浜竴涓嬪悧
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒

    璇ョ敤鎴蜂粠鏈鍒

    鍙戣〃浜 2022-11-10 01:21:46 | 鏄剧ず鍏ㄩ儴妤煎眰
    鎴戝彧鎯抽棶锛岃繖涓繀椤昏姹俢odesys杩愯鍦╟#鎵鍦ㄧ殑涓绘満涓婂悧锛熷鏋滄槸缃戠嚎杩炴帴鐨刾lc鍙笉鍙互
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒

    璇ョ敤鎴蜂粠鏈鍒

    鍙戣〃浜 2024-7-23 14:14:51 | 鏄剧ず鍏ㄩ儴妤煎眰
    璇烽棶涓嬫眹宸滱C绯诲垪鎴栬呮澗涓婣M1绯诲垪鐨凜ODESYS骞冲彴PLC閮借兘杩欐牱鐢ㄥ悧
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

    鏈増绉垎瑙勫垯

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

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

    GMT+8, 2024-11-23 22:11 , Processed in 0.168108 second(s), 81 queries .

    閰峰痉缃

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

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