【问题标题】:TwinCAT 3 : Block stays busyTwinCAT 3:块保持忙碌
【发布时间】:2019-08-12 20:20:20
【问题描述】:

我想将一些数据保存到 .txt 文件中。我可以创建它,但我无法在其中写入文本,因为 FB 一直很忙。

    CASE counter OF
    1:
        fileOpen.sNetId := '';
        fileOpen.sPathName := 'C:\test\test.txt';
        fileOpen.nMode := FOPEN_MODEWRITE;
        fileOpen.bExecute := TRUE;
        fileOpen.tTimeout := T#200MS;

        fileOpen();

        counter := 2;
    2:
        IF NOT fileOpen.bBusy AND NOT fileOpen.bError THEN (* bBusy stays true*)
            counter := 3;
        END_IF
    3:
        fileOpen.bExecute := FALSE;
        fbPutFile(sNetId := '', hFile := fileOpen.hFile, sLine := 'FOO', bExecute := TRUE, tTimeout := INT_TO_TIME(200), bBusy =>, bError =>, nErrId =>);
     END_CASE

我进入了第 2 步,但我无法进入第 3 步。问题出在哪里?

【问题讨论】:

    标签: plc st twincat


    【解决方案1】:

    这是因为您已经停止调用打开文件的功能块。您在这里所做的是您在步骤 1 中调用 FB_FileOpen,但随后停止调用它。 bBusy 标志在第 1 步中变为高电平(真),但永远不能更改为其他任何值,因为您再也不会调用 FB。您还需要在第 2 步中调用它。请记住,bExecute 也是 ADS-command 的触发器,因此在步骤 2 中完成后,您可以在步骤 2 中将 bExecute-input 设置为 FALSE,并在您已经触发命令时继续前进。

    ...
    2:
        fileOpen(bExecute := false);
        IF NOT fileOpen.bBusy AND NOT fileOpen.bError THEN (* bBusy stays true*)
            counter := 3;
        END_IF
    ...
    

    还请记住,Beckhoffs FB_FileOpen 假定目录 C:\test 存在(虽然不是文件 test.txt,如果您使用 FOPEN_MODEWRITE 打开它,它将自动创建)。要创建所有必要的目录(如果它们不存在),请使用 TwinCATs FB_CreateDir。

    【讨论】:

    • 谢谢,就是这样!我必须关闭文件才能完成操作。
    猜你喜欢
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 2011-05-04
    • 2019-01-20
    • 2012-02-01
    • 2017-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多