CODESYS寮鍙戞暀绋13-闀垮瓧绗︿覆澶勭悊-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 514|鍥炲: 0

CODESYS寮鍙戞暀绋13-闀垮瓧绗︿覆澶勭悊

[澶嶅埗閾炬帴]

璇ョ敤鎴蜂粠鏈鍒

鍙戣〃浜 2024-8-9 23:45:24 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
鎽樿锛氳繖鏄竴绡囧啓缁欐柊鎵嬬殑鍏充簬CODESYS寮鍙戠幆澧冪殑灏忕櫧鏁欑▼锛屼竴鐪嬪氨鎳......
鍦ㄤ互鍓嶇殑銆奀ODESYS寮鍙戞暀绋7-瀛楃涓插強鍏跺熀鏈搷浣溿嬫暀绋嬩腑锛屼粙缁嶄簡瀛楃涓插強鍏跺熀鏈搷浣滐紝鏈夋湅鍙嬬湅浜嗕互鍚庤寰椾笉杩囩樉锛屽笇鏈涙湁涓浜涘叧浜庡瓧绗︿覆鐨勬洿鍔犳繁鍏ョ殑浠嬬粛銆備粖澶╃殑鏁欑▼閲嶇偣缁欏ぇ瀹惰瑙d竴涓嬮暱瀛楃涓叉搷浣滅殑搴撳強鐩稿叧鍑芥暟锛岃繕鏈夐暱瀛楃涓诧紙闀垮害>255锛夊鐞嗙浉鍏崇殑涓浜涢獨鎿嶄綔锛屾瘮濡傝嚜宸卞啓鐨勫瓧绗︿覆闀垮害鍑芥暟銆佸瓧绗︿覆涓煡鎵惧瓧绗︾殑鍑芥暟绛夈
涓銆佸叧浜嶴TRING绫诲瀷鐨勮鏄
CODESYS鐨凷TRING瀛楃涓茬被鍨嬫湁鍑犵偣閲嶈鐨勮鍒欓渶瑕佺粰澶у浠嬬粛涓涓嬨
1.瀛楃涓插瓨鍌
瀛楃涓插疄闄呬笂鏄竴涓瓧绗︽暟缁勩傛瘮濡傚畾涔変竴涓瓧绗︿覆骞惰祴鍊笺
str   : STRING:=鈥機ODESYS鈥;
str瀹為檯涓婃槸涓涓暱搴︿负7鐨勫瓧绗︽暟缁勶紝鍙互浣跨敤鏁扮粍鐨勬柟寮忔潵璁块棶銆備篃灏辨槸璇达紝鍙互閫氳繃str[0]鏉ヨ幏寰楀瓧绗︿覆鐨勯瀛楃鈥機鈥欍傚湪瀹為檯瀛樺偍涓紝瀛楃鏄噰鐢ˋSCII鐮佺殑褰㈠紡鏉ヤ繚瀛樼殑銆傚湪鍒ゆ柇str[0]鏄惁涓哄瓧绗鏃讹紝闇瑕佽窡瀛楃C鐨凙SCII鐮佹潵杩涜姣旇緝锛屽嵆str[0]=16#43 鎴 str[0]=67 浼氳緭鍑篢RUE銆備絾鏄娇鐢╯tr[0]=鈥楥鈥欏垯浼氭姤缂栬瘧閿欒銆
鍦–ODESYS涓病鏈夊瓧绗﹀彉閲忥紝浣嗘槸鍙互鐢˙YTE鏉ュ畾涔夊瓧绗︼紝姣斿16#4A涓哄瓧姣岼銆
2.瀛楃涓插ぇ灏
鍦ㄥ畾涔夊瓧绗︿覆绫诲瀷鐨勫彉閲忔椂锛屽鏋滀笉鎸囧畾瀛楃涓茬殑闀垮害锛屽瓧绗︿覆鍙橀噺鍏佽鐨勬渶澶氬瓧绗︽暟涓80銆
str   : STRING:=鈥機ODESYS鈥; //姝ゆ椂str瀹為檯涓烘渶澶ч暱搴80涓瓧绗︾殑鏁扮粍str[0..79]
瀛楃涓插彉閲忓疄闄呴渶瑕佺殑鍐呭瓨涓哄瓧绗︿覆鐨勯暱搴﹀姞涓涓瓧鑺傦紝鍗充笂闈㈠畾涔夌殑str鍙橀噺鎵鍗犲瓨鍌ㄧ┖闂翠负81涓瓧鑺傦紙SIZEOF(str)=81锛夈
3.闀垮瓧绗︿覆
CODESYS鐜娌℃湁闄愬埗瀛楃涓插彉閲忕被鍨嬬殑闀垮害锛屽洜姝ら暱搴﹁秴杩255鐨勫瓧绗︿覆涔熸槸鍚堟硶鐨勶紙C璇█鐨勫瓧绗︿覆鏈澶ч暱搴︿负255锛夈備緥濡傚彲浠ュ畾涔変釜闀垮害涓1000瀛楄妭鐨勫瓧绗︿覆锛
str1 : STRING(1000);
闇瑕佹敞鎰忕殑鏄紝鍦ㄣ婂瓧绗︿覆鍙婂叾鍩烘湰鎿嶄綔銆嬩腑浠嬬粛鐨勫瓧绗︿覆澶勭悊鍑芥暟澶勭悊鐨勫瓧绗︽暟涓嶈兘瓒呰繃255锛屽嵆鍙兘瀵筍TRING(255)绫诲瀷鐨勫瓧绗︿覆杩涜鎿嶄綔銆傞暱搴﹁秴杩255瀛楃鐨勫瓧绗︿覆鍙互閫氳繃鏁扮粍璇诲彇鐨勬柟寮忓彇鍑烘潵鍗曠嫭澶勭悊銆
鍙楀瓧绗︽暟闄愬埗鐨勫瓧绗︿覆澶勭悊鍑芥暟涓昏鍖呮嫭锛欳ONCAT銆丏ELETE銆丗IND銆両NSERT銆丩EFT宸﹂夈丩EN銆丮ID銆丷EPLACE銆丷IGHT銆
娴嬭瘯绋嬪簭濡備笅锛
缁撴灉濡備笅鍥炬墍绀猴細
CODESYS寮鍙戞暀绋13-闀垮瓧绗︿覆澶勭悊-1.png


濡備笂鍥句腑鎵绀猴紝 瀛楃涓茬被鍨嬪彉閲弒tr1鐨勯暱搴︿负3锛屾墍鍗犲唴瀛樼┖闂村ぇ灏忔槸81瀛楄妭銆
瀵逛簬闀垮瓧绗︿覆strLong锛屽叾瀹為檯闀垮害涓10000銆備娇鐢↙EN()鍑芥暟鑾峰彇鐨勯暱搴︿负255锛岃屼娇鐢ㄥ嚱鏁癝trLenA()鑾峰彇鐨勯暱搴︿负姝e父鐨10000锛屾墍鍗犲唴瀛樼┖闂村ぇ灏忎负10001瀛楄妭銆
4.鍏充簬闀垮瓧绗︿覆鏀寔鐨勬渶闀垮害
娴嬭瘯鍙戠幇锛岀紪璇戝櫒锛3.5.16锛夋敮鎸佺殑闀垮瓧绗︿覆鏈澶у昂瀵镐负4294967295锛屽嵆2^32-1銆傜敤浠跨湡杩愯娴嬭瘯浜嗕竴涓嬫垜鐢ㄧ殑杩欎釜鎺у埗鍣紙寰P4CM锛夛紝鍙戠幇鏈澶氬彧鑳芥敮鎸2147483647锛屽嵆2^31-1锛岃秴杩囪闀垮害缂栬瘧鑳介氳繃锛屼絾鏄笅杞借繍琛屾椂浼氭姤閿欙紝瑕佷箞鏄帶鍒跺櫒鍐呭瓨涓嶈冻锛岃涔堟槸搴曞眰鏁版嵁绫诲瀷鐨勯暱搴﹂檺鍒跺鑷寸殑銆
  1. 鈥婸ROGRAM main
  2. VAR
  3.        i             : INT;
  4.        str1 : STRING;
  5.        strLong   : STRING(10000);
  6.        t0           : INT;
  7.        t1           : UINT;
  8.        t2           : INT;
  9.        t3           : DINT;
  10.        t4           : UINT;
  11. END_VAR
  12. str1:='abc';
  13. FOR i:=0 TO 9999 DO
  14.        strLong[i]:=16#3C;
  15. END_FOR
  16. t0:=LEN(str1);
  17. t1:=SIZEOF(str1);
  18. t2:=LEN(strLong);
  19. t3:=StrLenA(ADR(strLong));
  20. t4:=SIZEOF(strLong);
澶嶅埗浠g爜
浜屻侀暱瀛楃涓茬殑澶勭悊
闀垮瓧绗︿覆锛堥暱搴>255锛夌殑澶勭悊鏈変袱绉嶆柟寮忥細涓绉嶆槸浣跨敤CODESYS鎻愪緵鐨勯暱瀛楃涓插嚱鏁板簱锛涗竴绉嶆槸鑷繁缂栫▼澶勭悊銆
1.浣跨敤闀垮瓧绗︿覆鍑芥暟搴StringUtils
瀵逛簬闀垮害瓒呰繃255涓瓧绗︾殑瀛楃涓诧紝CODESYS鎻愪緵浜嗙浉搴旂殑搴擄紝搴撳悕绉版槸StringUtils锛屽涓嬪浘鎵绀恒
CODESYS寮鍙戞暀绋13-闀垮瓧绗︿覆澶勭悊-2.png


涓昏鍖呭惈ANSI鍜孶nicode涓ょ绫诲瀷瀛楃涓茬殑澶勭悊鍑芥暟銆
鐞嗚涓婏紝鍙互澶勭悊鏈澶ч暱搴4294967295锛2^32-1锛夌殑瀛楃涓层
鍑芥暟鍔熻兘

CODESYS-ST

澶囨敞

闀垮害

StrLenA/StrLenW

浠呯粺璁″瓧绗︽暟锛屼笉鍖呭惈缁撴潫绗

瀛楃涓叉瘮杈

StrCmpA/StrCmpW銆丼trCaseCmpA/StrCaseCmpW銆丼trCaseCmpEndA銆丼trCaseCmpStartA

甯ase鐨勪笉鍖哄垎澶у皬鍐

瀛楃涓叉嫹璐

StrCpyA/StrCpyW

涓棿鍙栦綅

StrMidA/StrMidW

瀛楃涓茶繛鎺

StrConcatA/StrConcatW

绌哄瓧绗︿覆妫鏌

StrIsNullOrEmptyA/StrIsNullOrEmptyW

鍒犻櫎

StrDeleteA/StrDeleteW

鏇挎崲

StrReplaceA/StrReplaceW

鏌ユ壘

StrFindA/StrFindW銆丼trCaseFindA/StrCaseFindW

甯ase鐨勪笉鍖哄垎澶у皬鍐

绉婚櫎绌哄瓧绗

StrTrimA銆丼trTrimEndA銆丼trTrimStartA

锛燂紵锛

StrPadLeftA/StrPadLeftW銆丼trPadRightA/StrPadRightW

瀛楃鎴栧瓧绗︿覆鐨勫ぇ灏忓啓杞崲

StrToLowerA銆丼trtoUpperA銆丆harToUpper/WCharToUpper

//娉ㄦ剰锛氫互涓婂嚱鏁扮殑瀛楃涓茬被鍨嬭緭鍏ュ潎涓篜OINTER TO BYTE锛屽嵆鎸囧悜瀛楄妭鐨勬寚閽堛
浠ヤ笅str鍧囦负STRING绫诲瀷鍙橀噺銆
锛1锛塁harToUpper(ch)
灏嗗瓧绗h杞崲涓哄ぇ鍐欏瓧绗︺
绀轰緥锛歝h:=CharToUpper('s'); //缁撴灉涓'S'
锛2锛塖trCmpA(ADR(str1),ADR(str2))銆丼trCaseCmpA()
姣旇緝瀛楃涓瞫tr1鍜宻tr2銆俿tr1鍜宻tr2鐩哥瓑鏃惰繑鍥0锛宻tr1灏忎簬str2鏃惰繑鍥-1锛宻tr1澶т簬str2鏃惰繑鍥1锛宻tr1鎴杝tr2涓洪潪娉曞瓧绗︿覆锛堝绌烘寚閽堬級鏃惰繑鍥-2銆
杩欓噷鐨勫ぇ浜庡拰灏忎簬寮濮嬫垜涔熶笉鏄庣櫧鏄粈涔堟剰鎬濓紝娴嬭瘯浜嗕竴涓嬪彂鐜版槸鏍规嵁瀛楃涓茬殑ASCII鐮佹潵鍖哄垎鐨勩傚皬浜庢剰鎬濆氨鏄痵tr1鐨凙SCII鐮佸煎皬浜巗tr2鐨凙SCII鐮,鍗斥檃鈥欏拰鈥榖鈥欐瘮杈冧細杩斿洖-1锛岃屸楢鈥欏拰鈥榓鈥欐瘮杈冧細杩斿洖1銆傝屽瓧绗︿覆鐨勬瘮杈冨氨姣旇緝榄斿够浜嗭紝涓嶅お娓呮杩斿洖缁撴灉鐨勮鍒欐槸浠涔堬紝渚嬪鈥榓鈥欏拰鈥榓b鈥欐瘮杈冧細杩斿洖-1锛岃屸榖cd鈥欏拰鈥榓b鈥欐瘮杈冧細杩斿洖1銆傚浜庡瓧绗︽瘮杈冭繕鏈夌偣鐢ㄩ旓紝浣嗘槸瀵逛簬瀛楃涓叉瘮杈冩湁浣曠敤澶勶紝瀹炲湪鏄病鎯冲嚭鏉~鈽
娉ㄦ剰锛歋trCmpA姣旇緝鏃跺尯鍒嗗ぇ灏忓啓锛孲trCaseCmpA姣旇緝鏃朵笉鍖哄垎澶у皬鍐欍
绀轰緥锛歜Flag:=StrCmpA(ADR(str1),ADR(str2));
锛3锛塖trFindA(ADR(str1),ADR(str2),uiStart)銆丼trCaseFindA
鍦ㄥ瓧绗︿覆str1涓煡鎵炬寚瀹氱殑瀛楃涓瞫tr2銆傛壘鍒板瓧绗︿覆str2浼氳繑鍥炲瓧绗︿覆鐨勯浣嶇疆锛屾湭鎵惧埌杩斿洖0锛岀粰瀹氱┖瀛楃涓蹭細杩斿洖-1銆
娉ㄦ剰锛氳繖閲岀殑str1鍜宻tr2鏈澶氬彧鑳戒负STRING(255)銆
绀轰緥锛歴tr1:=鈥橝BCD鈥;    str2:=鈥機D鈥;
pos:=StrFindA(ADR(str1), ADR(str2), 1); //pos=3
锛4锛塖trConcatA(ADR(str1),ADR(str2),iBuffSize)
灏嗗瓧绗︿覆str1杩炴帴鍒皊tr2鍚庨潰锛岄氬父鏄皢str2鍔犲埌str1鍚庨潰銆傚鏋渋BuffSize澶у皬涓嶅鎴栬呯粰瀹氱殑瀛楃涓蹭负NULL鏃讹紝灏嗕笉杩涜杩炴帴骞惰繑鍥濬ALSE銆
娉ㄦ剰锛歩BuffSize鐨勫煎繀椤绘瘮澶т簬绛変簬LEN(str1)+LEN(str2)+1锛屽惁鍒欏瓧绗︿覆杩炴帴浼氬け璐ャ
绀轰緥锛歴tr1:=鈥橝BCD鈥;    str2:=鈥機D鈥;
flag:=StrFindA(ADR(str1), ADR(str2), 7); //str2=鈥機DABCD鈥,flag=TRUE
flag:=StrFindA(ADR(str1), ADR(str2), 7); //str2=鈥機D鈥,flag=FALSE
锛5锛塖trCpyA(pBuf,iBuffSize,ADR(str))
瀛楃涓叉嫹璐濓紝鍗充粠瀛楃涓瞫tr涓嫹璐漣BuffSize涓瓧鑺傚埌缂撳啿鍖簆Buf銆傛嫹璐濆畬鎴愬悗浼氳繑鍥炴嫹璐濈殑瀛楃鏁帮紝璇ユ暟鎹寘鍚粨鏉熺鈥橽0鈥欐垨鈥淺0鈥濄
娉ㄦ剰锛歱Buf涓嶈兘涓篘ULL銆傚彟澶杋BuffSize鏄寘鍚粨鏉熺鐨勪釜鏁帮紝鍗12琛ㄧず瀹為檯鍙兘鎷疯礉11涓瓧绗︺
绀轰緥锛歴tr1:=鈥欌;      str2:=鈥機DEFG鈥;
num:=StrCpyA(ADR(str1),3,ADR(str2)); //str1=鈥機D鈥
锛6锛塖trDeleteA(ADR(str),iLen,iPos)
浠庡瓧绗︿覆str涓殑iPos寮濮嬪垹闄ら暱搴︿负iLen鐨勫瓧绗︺俰Pos=1涓轰粠绗竴涓瓧绗﹀紑濮嬨
绀轰緥锛歴tr:=鈥橝BCD鈥
StrDeleteA(ADR(str),2,1); //str=鈥機D鈥
锛7锛塖trIsNullOrEmptyA(ADR(str))
鍒ゆ柇瀛楃涓瞫tr鏄惁涓篘ULL鎴栫┖銆
锛8锛塖trLenA(ADR(str))
鑾峰彇瀛楃涓瞫tr闀垮害銆傝鍑芥暟鏄氳繃瀵绘壘瀛楃涓蹭腑鐨勭粨鏉熷瓧绗︹橽0鈥欐潵瀹炵幇鐨勩傚鏋渟tr涓篘ULL鏃朵細杩斿洖-1銆
锛9锛塖trMid(ADR(str),iBuffSize,iLen,iPos,ADR(strDest),uiResBufsize)
鑾峰彇瀛楃涓瞫tr涓粠iPos寮濮嬮暱搴︿负iLen鐨勫瓧绗︺俰Pos=1涓轰粠绗竴涓瓧绗﹀紑濮嬨
锛10锛塖trPadLeftA(ch,ADR(str1),ADR(str2),iBuffSize)銆丼trPadRightA
灏嗗瓧绗︿覆str1浠庡乏渚у紑濮嬪~鍏呬负鎸囧畾瀛楃ch锛屽~鍏呬釜鏁癷BuffSize-LEN(str1)锛岀粨鏋滄斁鍦ㄥ瓧绗︿覆str2涓紝骞惰繑鍥濼RUE銆傚綋iBuffSize灏忎簬str1鐨勫瓧绗︿釜鏁版椂锛屼笉杩涜濉厖骞惰繑鍥濬ALSE銆
绀轰緥锛歴tr1:=鈥榓b鈥
flag:=StrPadLeftA(16#41,ADR(str1),ADR(str2),7); //str2=鈥橝AAAAab鈥
锛11锛塖trReplaceA(ADR(str),iBuffSize,ADR(str2),iLenIn,iLenToRe,iLenToReWith,iPos)
灏嗗瓧绗︿覆涓粠iPos寮濮嬮暱搴︿负iLen鐨勫瓧绗︽浛鎹负str2銆俰Pos=1涓轰粠绗竴涓瓧绗﹀紑濮嬨
娉ㄦ剰锛氳繖閲岀殑str1鍜宻tr2鏈澶氬彧鑳戒负STRING(255)銆
绀轰緥锛歴tr1:=鈥檃b鈥; str2:=鈥2鈥;
StrReplaceA(ADR(str1),7,ADR(str2),2,2,2,1); //str1=鈥2b鈥
鍐欏埌杩欓噷蹇嶄笉浣忓悙妲戒竴涓婥ODESYS鐨勫府鍔╂枃妗g湡鐨勬槸鍨冨溇锛屼腑闂磋繖鍑犱釜闀垮害鍙傛暟鏍规湰鐪嬩笉鎳傛槸浠涔堟剰鎬濃︹樄锛屽ぇ瀹剁湡瑕佺敤鐨勮瘽鑷繁鍘绘祴璇曪紝鎴戝疄鍦ㄦ槸鍙楀浜唦~
锛12锛塖trToLowerA銆丼trToUpperA
瀛楃涓蹭腑瀛楃鐨勫ぇ灏忓啓杞崲銆
绀轰緥锛歴tr:=鈥檃bcd鈥;
StrToUpperA(ADR(str));    //str=鈥橝BCD鈥
锛13锛塖trTrimA(ADR(str))銆丼trTrimEndA銆丼trTrimStartA
绉婚櫎瀛楃涓蹭腑鐨勭┖鐧藉瓧绗︼紝绌虹櫧瀛楃鎸嘇SCII鐮佷负9銆10銆13銆32鐨勫瓧绗︺
鍚庨潰涓や釜鍑芥暟涓轰粎绉婚櫎缁撳熬鎴栧紑澶寸殑绌虹櫧瀛楃銆
绀轰緥锛歴tr:=鈥  abcd  鈥;
StrTrimA(ADR(str));          //str=鈥檃bcd鈥
瀵逛簬UNICODE瀛楃涓茬殑鐩稿叧澶勭悊鍑芥暟鐢ㄦ硶鍩烘湰绫讳技锛岃繖閲屽氨涓嶄竴涓鍒椾妇浜嗭紙涓昏鏄垜鎳掔梾鐘簡~~
CODESYS寮鍙戞暀绋13-闀垮瓧绗︿覆澶勭悊-3.png
CODESYS寮鍙戞暀绋13-闀垮瓧绗︿覆澶勭悊-4.png
+10
涓嶈禐涓涓紵
鎵撹祻榧撳姳涓涓嬶紒
鍥炲

浣跨敤閬撳叿 涓炬姤

鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

鏈増绉垎瑙勫垯

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

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

GMT+8, 2024-11-23 19:57 , Processed in 0.176276 second(s), 61 queries .

閰峰痉缃

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

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