我正在开发一个代码来获取 twincat 中的文本文件。我正在使用块功能:
FB_FileOpen
FB_FileGets
FB_FileClose
我以网站https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclibsystem/html/tcplclibsys_fileio_example.htm&id=5958930695166849062上的示例为基础
当程序运行时,我的 FB_GetLabelFile 运行到第 3 步,然后不前进
我想知道我在哪里犯了错误。我在下面附上代码:
FUNCTION_BLOCK FB_GetLabelFile
VAR_INPUT
bExecute : BOOL ;
hFile : UINT ;
sNetId : STRING ;
sFileName : STRING := 'src\version.txt';
tTimeout : TIME := T#5S;
END_VAR
VAR_OUTPUT
bBusy : BOOL ;
bError : BOOL ; (* TRUE => Error, FALSE => No error *)
nErrId : UDINT; (* Error code *)
sResult : STRING ;
tRisingEdge : R_TRIG;
END_VAR
VAR
fbFileOpen : FB_FileOpen;
fbFileClose : FB_FileClose;
fbFileGet : FB_FileGets;
hSrcFile : UINT;
nState : INT ;
END_VAR
tRisingEdge(CLK:=bExecute);
CASE nState OF
0:
IF tRisingEdge.Q THEN
bBusy := TRUE;
bError := FALSE;
nErrId := 0;
nState := 1;
sResult := '';
hSrcFile:= 0;
END_IF
1:
fbFileOpen.bExecute := FALSE;
fbFileOpen.sNetId := sNetID;
fbFileOpen.sPathName := sFileName;
fbFileOpen.nMode := FOPEN_MODEREAD OR FOPEN_MODETEXT;
fbFileOpen.ePath := PATH_GENERIC;
fbFileOpen.tTimeout := tTimeout;
nState := nState + 1;
2:
fbFileOpen.bExecute := FALSE;
IF NOT fbFileOpen.bBusy THEN
IF fbFileOpen.bError THEN
nErrId := fbFileOpen.nErrId;
bError := TRUE;
nState := 10;
ELSE
hSrcFile := fbFileOpen.hFile;
nState := nState + 1;
END_IF
END_IF
3:
sResult := '';
fbFileGet.bExecute := FALSE;
fbFileGet.sNetId := sNetID;
fbFileGet.hFile := hSrcFile;
fbFileGet.bExecute := TRUE;
fbFileGet.tTimeout := tTimeOut;
nState := nState + 1;
4:
fbFileGet.bExecute := FALSE;
IF NOT fbFileGet.bBusy THEN
IF fbFileGet.bError THEN
nErrId := fbFileGet.nErrId;
bError := TRUE;
nState := 10;
ELSE
sResult := fbFileGet.sLine;
nState := nState + 1;
END_IF
END_IF
5:
fbFileClose.bExecute := FALSE;
fbFileClose.sNetId := sNetID;
fbFileClose.hFile := hSrcFile;
fbFileClose.bExecute := TRUE;
fbFileClose.tTimeout := tTimeOut;
nState := nState + 1;
6:
fbFileClose.bExecute := FALSE;
IF NOT fbFileClose.bBusy THEN
IF fbFileClose.bError THEN
nErrId := fbFileClose.nErrId;
bError := TRUE;
END_IF
nState := 10;
hSrcFile := 0;
END_IF
10:
IF hSrcFile <> 0 THEN
nState := 5;
ELSE
nState := 0;
bBusy := FALSE;
END_IF
END_CASE
非常感谢!非常感谢您的帮助