鍦–odesys鐢⊿T璇█鍩轰簬閾捐〃瀹炵幇闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠...-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 1786|鍥炲: 1

鍦–odesys鐢⊿T璇█鍩轰簬閾捐〃瀹炵幇闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠...

[澶嶅埗閾炬帴]

璇ョ敤鎴蜂粠鏈鍒

鍙戣〃浜 2023-4-12 21:57:15 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
鍦–odesys鐢⊿T璇█鍩轰簬閾捐〃瀹炵幇闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-1.gif


涓銆 闃熷垪瀹氫箟

闃熷垪鏄竴绉嶅厛鍏ュ厛鍑(FIFO鈥斺攆irst in first out)绾挎ц〃,瀹冨彧鍏佽鍦ㄨ〃鐨勫墠绔紙front锛夎繘琛屽垹闄ゆ搷浣滐紝鑰屽湪琛ㄧ殑鍚庣锛坮ear锛夎繘琛屾彃鍏ユ搷浣溿

鍦–odesys鐢⊿T璇█鍩轰簬閾捐〃瀹炵幇闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-2.png


浜屻侀槦鍒楀疄鐜

瀹炵幇闃熷垪锛屾垜浠彲浠ヤ娇鐢ㄩ摼琛紝閾捐〃涓殑姣忎釜缁撶偣涓嶄粎鍖呭惈鍊硷紝杩樺寘鍚摼鎺ュ埌涓嬩竴涓粨鐐圭殑寮曠敤瀛楁銆傞氳繃杩欑鏂瑰紡锛屽崟閾捐〃灏嗘墍鏈夌粨鐐规寜椤哄簭缁勭粐璧锋潵銆傝摑鑹茬澶存樉绀哄崟涓摼鎺ュ垪琛ㄤ腑鐨勭粨鐐规槸濡備綍缁勫悎鍦ㄤ竴璧风殑

鍦–odesys鐢⊿T璇█鍩轰簬閾捐〃瀹炵幇闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-3.png

鐢ㄩ摼琛ㄥ疄鐜伴槦鍒楃浉瀵规暟缁勫疄鐜伴槦鍒楃殑浼樼偣鏄兘鑺傜害绌洪棿锛屾病鏈夋氮璐圭殑绌洪棿鑺傜偣銆
涓夈 闃熷垪璁捐

鎴戜滑鍒嗗埆閲囩敤c++鍜宑odesys涓璼t璇█杩涜瀹炵幇閾捐〃闃熷垪
(1) C++ 璇█瀹炵幇

鍔熻兘濡備笅

    Push(value) : 鍚戦槦鍒椾腑鎻掑叆涓涓厓绱狅紝鎴愬姛杩斿洖truepop():浠庨槦鍒椾腑鍒犻櫎涓涓厓绱狅紝鎴愬姛杩斿洖trueFront():浠庨槦鍒楀ご閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪鏄┖锛岃繑鍥瀎alseRear():浠庨槦鍒楀熬閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪涓虹┖锛岃繑鍥瀎alseEmpty(): 妫娴嬮槦鍒楁槸鍚︿负绌,涓虹┖杩斿洖trueSize():鑾峰緱闃熷垪鑺傜偣涓暟锛岃繑鍥炰釜鏁
  1. typedefint DataElement;//鐢ㄦ埛鑷畾涔夌殑鏁版嵁typedefstruct QueueElement//闃熷垪鍏冪礌{
  2.     DataElement  mdata;//鐢ㄦ埛鑷畾涔夌殑鏁版嵁
  3.     QueueElement* next;//鎸囧悜涓嬩竴涓妭鐐箎QueueElement;//閫氳繃閾捐〃瀹炵幇闃熷垪classListCircleQueue{public:ListCircleQueue(){};~ListCircleQueue(){};private:
  4.     QueueElement* pHead =0;//
  5.     QueueElement* pTail =0;//闃熷熬鎸囬拡public:boolpush(DataElement _data){// 鐢宠涓涓粨鐐圭┖闂
  6.         QueueElement* pTemp =(QueueElement*)malloc(sizeof(QueueElement));
  7.          pTemp->mdata = _data;// 鐢宠涓涓粨鐐圭┖闂
  8.          pTemp->next =0;// 缁撶偣鐨刵ext璁句负NULLif(Empty())// 鍒ゆ柇闃熷ご鍜岄槦灏炬槸鍚︿负绌猴紝鐢ㄤ簬绗竴娆″叆闃焮
  9.              pHead = pTemp;// 鍒ゆ柇闃熷ご鍜岄槦灏炬槸鍚︿负绌猴紝鐢ㄤ簬绗竴娆″叆闃
  10.              pTail = pTemp;}else{
  11.           pTail->next = pTemp;// 璁﹑Temp鎴愪负褰撳墠灏鹃儴鐨勪笅涓缁
  12.            pTail = pTemp;// 灏鹃儴鎸囬拡鎸囧悜pTemp}returntrue;}boolpop(){if(Empty())returnfalse;if(pHead->next ==0)// 鍒ゆ柇闃熷垪鏄惁灏1涓,濡傛灉鍙湁涓涓 锛岀Щ闄ゅ悗闃熷垪涓虹┖ {
  13.             pHead =0;
  14.             pTail =0;}else{
  15.           QueueElement* pTemp = pHead;
  16.           pHead = pHead->next;//绉诲姩澶撮儴鎸囬拡delete(pTemp);//娓呴櫎绉婚櫎鐨勫唴瀛樼┖鍓峿returntrue;};boolFront(DataElement &_data){if(pHead !=0){
  17.           _data = pHead->mdata;//杩斿洖澶撮儴鏁版嵁returntrue;}elsereturnfalse;}boolRear(DataElement& _data){if(pTail !=0){
  18.            _data = pTail->mdata;//杩斿洖灏鹃儴鏁版嵁returntrue;}elsereturnfalse;}//杩斿洖鑺傜偣涓暟intSize(){int iSize  =0;
  19.          QueueElement* pTemp = pHead;while(pTemp !=0){
  20.              iSize = iSize +1;
  21.              pTemp = pTemp->next;}return iSize;}//鍒ゆ柇闃熷垪鏄惁涓虹┖boolEmpty(){if((pHead ==0)&&(pTail ==0))returntrue;elsereturnfalse;}}
澶嶅埗浠g爜
绀轰緥濡備笅

鍦–odesys鐢⊿T璇█鍩轰簬閾捐〃瀹炵幇闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-4.jpg


(2) Codesys 瀹炵幇


    缂栫▼杞欢锛 Codesys V3.5 SP17杩愯璁惧锛歅C鐢佃剳缂栫▼璇█锛 ST ST 鎺屾彙濡備綍鍒涘缓鍔ㄦ佹暟缁New鐨勪娇鐢紱浠ュ強鎸囬拡鐨勭伒娲讳娇鐢
瀹氫箟缁撴瀯浣
  1. //闃熷垪鎿嶄綔鐨勬暟鎹
  2. TYPE ListQueueElement :
  3. STRUCT
  4.         mData : BaseElement;
  5.         pNext : POINTER TO ListQueueElement;
  6. END_STRUCT
  7. END_TYPE
澶嶅埗浠g爜
鍏朵腑 BaseElement 鏄竴涓埆鍚嶏紝鍏跺畾涔夊涓嬶紝杩欓噷BaseElement 鏄敤鎴疯嚜瀹氫箟鏁版嵁(姣斿缁撴瀯浣)锛岄噰鐢ㄥ埆鍚嶆槸鏂逛究鏇挎崲銆
  1. TYPE BaseElement : INT; END_TYPE
澶嶅埗浠g爜
瀹氫箟鍔熻兘鍧楋紙FUNCTION_BLOCK锛夛細 ListQueue锛屽疄鐜板涓嬪嚱鏁

    Push(value) : 鍚戦槦鍒椾腑鎻掑叆涓涓厓绱狅紝鎴愬姛杩斿洖truepop():浠庨槦鍒椾腑鍒犻櫎涓涓厓绱狅紝鎴愬姛杩斿洖trueFront():浠庨槦鍒楀ご閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪鏄┖锛岃繑鍥瀎alseRear():浠庨槦鍒楀熬閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪涓虹┖锛岃繑鍥瀎alseEmpty(): 妫娴嬮槦鍒楁槸鍚︿负绌,涓虹┖杩斿洖trueSize():鑾峰緱闃熷垪鑺傜偣涓暟锛岃繑鍥炰釜鏁
绀轰緥濡備笅
  1. PROGRAM PLC_PRG
  2. VAR        
  3.         t : ListQueue;
  4. END_VAR

  5. VAR
  6.         bInit :BOOL:= FALSE;
  7.         isize : INT;
  8.         ivar1: ARRAY[0..10] OF BaseElement;
  9. END_VAR
澶嶅埗浠g爜
  1. IF bInit = FALSE THEN
  2.         
  3. bInit := TRUE;

  4. t.Push(11);//鍏ラ槦 锛岃繑鍥濼RUE
  5. t.Push(22);//鍏ラ槦 锛岃繑鍥濼RUE
  6. t.Push(33);//鍏ラ槦 锛岃繑鍥濼RUE
  7. isize := t.Size();//杩斿洖3
  8. t.Front(_data =>ivar1[0]);//杩斿洖11
  9. t.Pop();//浠庡惊鐜槦鍒椾腑鍒犻櫎涓涓厓绱狅紝鎴愬姛杩斿洖true
  10. t.Front(_data =>ivar1[1]);//杩斿洖22

  11. END_IF
澶嶅埗浠g爜
鍦–odesys鐢⊿T璇█鍩轰簬閾捐〃瀹炵幇闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-5.jpg


鍥涖 Codesys浠g爜涓嬭浇
娓稿锛屽鏋滄偍瑕佹煡鐪嬫湰甯栭殣钘忓唴瀹硅鍥炲

+11
涓嶈禐涓涓紵

鏈杩戣皝璧炶繃

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

浣跨敤閬撳叿 涓炬姤

璇ョ敤鎴蜂粠鏈鍒

鍙戣〃浜 2023-9-27 15:08:38 | 鏄剧ず鍏ㄩ儴妤煎眰
璋㈣阿璋㈣阿  璋㈣阿璋㈣阿璋㈣阿
+10
涓嶈禐涓涓紵
鎵撹祻榧撳姳涓涓嬶紒
鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

鏈増绉垎瑙勫垯

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

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

GMT+8, 2024-11-23 19:42 , Processed in 0.158323 second(s), 66 queries .

閰峰痉缃

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

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