TC2中自動(dòng)更換PLC運(yùn)行程序并重啟_第1頁(yè)
TC2中自動(dòng)更換PLC運(yùn)行程序并重啟_第2頁(yè)
TC2中自動(dòng)更換PLC運(yùn)行程序并重啟_第3頁(yè)
TC2中自動(dòng)更換PLC運(yùn)行程序并重啟_第4頁(yè)
TC2中自動(dòng)更換PLC運(yùn)行程序并重啟_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第6頁(yè)TC2中自動(dòng)更換PLC運(yùn)行程序并重啟TC2中自動(dòng)更換PLC運(yùn)行程序并重啟作者:夏璐杰職務(wù):華東區(qū)技術(shù)工程師郵箱:lj.xia@日期:2021-08-09摘要:為了方便客戶(hù)升級(jí)TC2中的PLC程序,可以借助功能塊“FB_CopeFileToFile”實(shí)現(xiàn)程序更換。附件:序號(hào)文件名備注歷史版本:2021-08-09夏璐杰TC2中自動(dòng)更換PLC運(yùn)行程序并重啟免責(zé)聲明:我們已對(duì)本文檔描述的內(nèi)容做測(cè)試。但是差錯(cuò)在所難免,無(wú)法保證絕對(duì)正確并完全滿(mǎn)足您的使用需求。本文檔的內(nèi)容可能隨時(shí)更新,如有改動(dòng),恕不事先通知,也歡迎您提出改進(jìn)建議。參考信息:目錄1. 軟硬件版本 21.1. 倍福Beckhoff 21.1.1. 控制器硬件 21.1.2. 控制軟件 22. TC2中Boot文件夾介紹 23. FB_CopeFileToFile功能塊介紹 33.1. FB_CopeFileToFile功能塊用法 33.2. 功能塊FB_FileCopy源代碼 44. 測(cè)試程序介紹 44.1. 硬件環(huán)境 44.2. 軟件環(huán)境 45. 附錄 81.1 功能塊FB_CopeFileToFile源代碼 14

軟硬件版本倍福Beckhoff控制器硬件CX8090EL2008EL2004控制軟件筆記本和控制器都是基于TwinCAT2.11Build2307版本TC2中Boot文件夾介紹在倍??刂破髦校琓winCAT2的項(xiàng)目文件總是位于“harddisk:\TwinCAT\Boot”或“C:\TwinCAT\Boot”中,所以對(duì)于某些控制器無(wú)法啟動(dòng)的情況,可以通過(guò)清空boot文件夾來(lái)實(shí)現(xiàn)TwinCAT項(xiàng)目恢復(fù)出廠(chǎng)設(shè)置,以使控制器恢復(fù)至正常狀態(tài)。對(duì)于TwinCAT2的控制器,其Boot文件夾中的內(nèi)容一般如下其中TCPLC_P_1.wbp為引導(dǎo)程序Bootproject,其為每次TwinCATPLCControl中執(zhí)行CreateBootProject的時(shí)候生成。因此,對(duì)于同一套控制器及其外圍設(shè)備,如果客戶(hù)想進(jìn)行程序升級(jí),可以通過(guò)更換TCPLC_P_1.wbp來(lái)實(shí)現(xiàn)。FB_CopeFileToFile功能塊介紹FB_CopeFileToFile功能塊用法本文檔封裝了一個(gè)自定義功能塊“FB_CopeFileToFile”,其功能是把文件夾1中的內(nèi)容復(fù)制至文件夾2中。為了實(shí)現(xiàn)TCPLC_P_1.wbp的更換升級(jí),則可以把新程序TCPLC_P_1.wbp放置在harddisk:\TwinCAT\Boot_1LED2s文件中,則當(dāng)bExecute為true時(shí),會(huì)覆蓋掉harddisk:\TwinCAT\Boot中舊的TCPLC_P_1.wbp。功能塊FB_FileCopy源代碼FUNCTION_BLOCKFB_FileCopyVAR_INPUT srcNetId :T_AmsNetId; (*TwinCATnetworkaddressofthesourcefile*) srcFileName :T_MaxString; (*sourcefilepathandname*) destNetId :T_AmsNetId; (*TwinCATnetworkaddressofthedestinationfile*) destFileName :T_MaxString;(*destinationfilepathandname*) bExecute :BOOL; (*risingedgestartfbexecution*) tAdsTimeOut :TIME; (*adstimeout*) bLogActive : BOOL:=FALSE;END_VARVAR_OUTPUT bBusy :BOOL; bError :BOOL; nErrId :UDINT;END_VARVAR fbFileOpen :FB_FileOpen; fbFileClose :FB_FileClose; fbFileRead :FB_FileRead; fbFileWrite :FB_FileWrite; hSrcFile :UINT :=0;(*filehandleofthesourcefile*) hDestFile :UINT :=0;(*filehandleofthedestinationfile*) Step :DWORD; RisingEdge :R_TRIG; buffRead :ARRAY[1..30000]OFBYTE;(*buffer*) cbReadLength :UDINT:=0; cbWriteActLength: UDINT:=0; cnRWCounter: UDINT:=0; OnceMore: BOOL; cnRetryCounter: UDINT;END_VARVARCONSTANT FileIsEmpty: INT:=16#1234;END_VARRisingEdge(CLK:=bExecute);IFRisingEdge.QTHEN IFNOTbBusyTHEN bBusy:=TRUE; bError:=FALSE; nErrId:=0; Step:=1; cbReadLength:=0; hSrcFile:=0; hDestFile:=0; cnRWCounter:=0; cnRetryCounter:=0; END_IFEND_IFCASEStepOF 0: (*donothing*) ; 1: (*opensourcefile*) OnceMore:=FALSE; cnRWCounter:=0; fbFileOpen(bExecute:=FALSE); fbFileOpen( sNetId:=srcNetId, sPathName:=srcFileName, nMode:=FOPEN_MODEREADORFOPEN_MODEBINARY, ePath:=PATH_GENERIC, tTimeout:=tAdsTimeout, bExecute:=TRUE); IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='opensourcefile,step%d',dintArg:=Step);END_IF Step:=Step+1; 2: fbFileOpen(bExecute:=FALSE); IF(NOTfbFileOpen.bBusy)THEN IF(fbFileOpen.bError)THEN nErrId:=fbFileOpen.nErrId; bError:=TRUE; Step:=50; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:=CONCAT(CONCAT(srcFileName,destFileName),'FileOpenError,ErrorId%d'),dintArg:=nErrId);END_IF ELSE hSrcFile:=fbFileOpen.hFile; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='getsourcefilehandle,step%d',dintArg:=Step);END_IF Step:=Step+1; END_IF END_IF 3: (*opendestinationfile*) fbFileOpen(bExecute:=FALSE); fbFileOpen( sNetId:=destNetId, sPathName:=destFileName, nMode:=FOPEN_MODEWRITEORFOPEN_MODEBINARY, ePath:=PATH_GENERIC, tTimeout:=tAdsTimeout, bExecute:=TRUE); IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='opendestinationfile,step%d',dintArg:=Step);END_IF Step:=Step+1; 4: fbFileOpen(bExecute:=FALSE); IF(NOTfbFileOpen.bBusy)THEN IF(fbFileOpen.bError)THEN nErrId:=fbFileOpen.nErrId; bError:=TRUE; Step:=50; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:=CONCAT(CONCAT(srcFileName,destFileName),'FileOpenError,ErrorId%d'),dintArg:=nErrId);END_IF ELSE hDestFile:=fbFileOpen.hFile; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='getdestinationfilehandle,step%d',dintArg:=Step);END_IF Step:=Step+1; END_IF END_IF 5: (*readdatafromsourcefile*) cbReadLength:=0; fbFileRead(bExecute:=FALSE); fbFileRead( sNetId:=SrcNetId, hFile:=hSrcFile, pReadBuff:=ADR(buffRead), cbReadLen:=SIZEOF(buffRead), bExecute:=TRUE, tTimeout:=tAdsTimeOut); IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='readdatafromsourcefile,step%d',dintArg:=Step);END_IF Step:=Step+1; 6: fbFileRead(bExecute:=FALSE); IF(NOTfbFileRead.bBusy)THEN (*//fbFileRead.bEOF;*) IF(fbFileRead.bError)THEN nErrId:=fbFileRead.nErrId; bError:=TRUE; Step:=50; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:=CONCAT(CONCAT(srcFileName,destFileName),'FileReadError,ErrorId%d'),dintArg:=nErrId);END_IF ELSE IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='getReadSize,step%d',dintArg:=Step);END_IF cbReadLength:=fbFileRead.cbRead; Step:=Step+1; END_IF END_IF 7: (*writedatatodestinationfile*) fbFileWrite(bExecute:=FALSE); fbFileWrite( sNetId:=DestNetId, hFile:=hDestFile, pWriteBuff:=ADR(buffRead), cbWriteLen:=cbReadLength, bExecute:=TRUE, tTimeout:=tAdsTimeOut); IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='writedatatodestinationfile,step%d',dintArg:=Step);END_IF Step:=Step+1; cnRWCounter:=cnRWCounter+1; 8: fbFileWrite(bExecute:=FALSE); IF(NOTfbFileWrite.bBusy)THEN cbWriteActLength:=fbFileWrite.cbWrite; IF(fbFileWrite.bError)THEN nErrId:=fbFileWrite.nErrId; bError:=TRUE; Step:=50; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:=CONCAT(CONCAT(srcFileName,destFileName),'FileWriteError,ErrorId%d'),dintArg:=nErrId);END_IF ELSIF(cnRWCounter=1)AND(cbWriteActLength=0)THEN IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_ERROR,msgFmtStr:=CONCAT(CONCAT(CONCAT(CONCAT('Read:',UDINT_TO_STRING(cbReadLength)),'write:'),UDINT_TO_STRING(cbWriteActLength)),'_step%d'),dintArg:=Step);END_IF OnceMore:=TRUE; cnRetryCounter:=cnRetryCounter+1; IFcnRetryCounter>10THEN bError:=TRUE; OnceMore:=FALSE; nErrId:=FileIsEmpty; END_IF Step:=50;(*repeatreading*) ELSE IFfbFileRead.bEOFTHEN(*CheckiftheEOFflagistset*) Step:=50; (*cleanup:closethedestinationandsourcefiles*) IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='CheckiftheEOFflagistset,step%d',dintArg:=Step);END_IF ELSE Step:=5;(*repeatreading*) IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='repeatreading,step%d',dintArg:=Step);END_IF END_IF END_IF END_IF 30: (*closethedestinationfile*) fbFileClose(bExecute:=FALSE); fbFileClose( sNetId:=destNetId, hFile:=hDestFile, bExecute:=TRUE, tTimeout:=tAdsTimeOut); IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='closethedestinationfile,step%d',dintArg:=Step);END_IF Step:=Step+1; 31: fbFileClose(bExecute:=FALSE); IF(NOTfbFileClose.bBusy)THEN IF(fbFileClose.bError)THEN nErrId:=fbFileClose.nErrId; bError:=TRUE; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:=CONCAT(CONCAT(srcFileName,destFileName),'FileCloseError,ErrorId%d'),dintArg:=nErrId);END_IF END_IF Step:=50; hDestFile:=0; END_IF 40:(*closesourcefile*) fbFileClose(bExecute:=FALSE); fbFileClose( sNetId:=srcNetId, hFile:=hSrcFile, bExecute:=TRUE, tTimeout:=tAdsTimeOut); IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='closesourcefile,step%d',dintArg:=Step);END_IF Step:=Step+1; 41: fbFileClose(bExecute:=FALSE); IF(NOTfbFileClose.bBusy)THEN IF(fbFileClose.bError)THEN nErrId:=fbFileClose.nErrId; bError:=TRUE; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:=CONCAT(CONCAT(srcFileName,destFileName),'FileCloseError,ErrorId%d'),dintArg:=nErrId);END_IF END_IF Step:=50; hSrcFile:=0; END_IF 50:(*errororready=>cleanup*) IF(hDestFile<>0)THEN Step:=30;(*closethedestinationfile*) ELSIF(hSrcFile<>0)THEN Step:=40;(*closethesourcefile*) ELSE IFOnceMoreTHEN Step:=1; IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='OnceMore!,step%d',dintArg:=Step);END_IF ELSE Step:=0; (*ready*) IFbLogActiveTHENADSLOGDINT(msgCtrlMask:=ADSLOG_MSGTYPE_LOG,msgFmtStr:='Done!,step%d',dintArg:=Step);END_IF bBusy:=FALSE; END_IF END_IFEND_CASE功能塊FB_CopeFileToFile源代碼FUNCTION_BLOCKFB_CopeFileToFileVAR_INPUT bExecute: BOOL; sSourcePathName: STRING:='HardDisk\TwinCAT\Boot_4LED1s'; sDestinationPathName: STRING:='HardDisk\TwinCAT\boot'; bLogActive: BOOL:=FALSE;END_VARVAR_OUTPUT bBusy: BOOL; bError: BOOL; bDone: BOOL;END_VARVAR nState: INT; fbCreateDir: FB_CreateDir; bOldExecute: BOOL; nCount: INT; nCount2: INT; fileList: ARRAY[1..cnMaxNoOfFiles]OFST_FindFileEntry; fbFindFileList: FB_EnumFindFileList; fbCopyFiles: FB_FileCopy; TonDelay: TON;END_VARVARCONSTANT cnMaxNoOfFiles:INT:=50;END_VARCASEnStateOF0: IFbExecuteANDNOTbBusyTHEN IFNOTbOldExecuteTHEN bBusy:=TRUE; bError:=FALSE; bDone:=FALSE; nState:=30; nCount:=1; nCount2:=1; END_IF END_IF30: (*Updatefilelist *) IFnCount<=cnMaxNoOfFilesTHEN fbFindFileList ( sNetID:='', sPathName:=CONCAT(sSourcePathName,'\*.*'), eCmd:=eEnumCmd_First, pFindList:=ADR(fileList), cbFindList:=SIZEOF(fileList), tTimeout:=t#10s, bExecute:=TRUE ); IFfbFindFileList.bExecuteANDNOTfbFindFileList.bBusyTHEN fbFindFileList(bExecute:=FALSE); fbCopyFiles(srcNetId:='',destNetId:='', tAdsTimeOut:=t#10s); nCount2:=1; nState:=40; END_IF IFfbFindFileList.bErrorTHEN nState:=0; fbFindFileList(bExecute:=FALSE); bBusy:=FALSE; bError:=TRUE; END_IF END_IF40: (*copyeachfilefromsourcetodestinationfolder *) IFfileList[nCount2].sFileName<>''THEN fbCopyFiles.srcFileName:=CONCAT(CONCAT(sSourcePathName,'\'),fileList[nCount2].sFileName); fbCopyFiles.destFileName:=CONCAT(CONCAT(sDestinationPathName,'\'),fileList[nCount2].sFileName); fbCopyFiles(bExecute:=TR

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論