twincat-如何查看贝克霍夫plc目录的内容

发布于 2025-01-28 04:46:47 字数 1168 浏览 1 评论 0原文

我正在尝试在PLC中执行文件管理。目前,NT_StartProcess的工作原理如下,但是在流程产生后,我将没有任何反馈。有没有办法检查PLC目录的内容?有什么方法可以从NT_StartProcess获得反馈?

// File Locations
sTargetFilePath := 'C:\LocalHistory\test.job';
sTargetDirectory := 'C:\\CustomerDir';
 
// Build Command String
sCommand := '/C ';                  // Special command indicating command string input
sCommand := CONCAT(sCommand, 'move ');      // Add move command
sCommand := CONCAT(sCommand, sTargetFilePath);  // Add target file
sCommand := CONCAT(sCommand, ' ');          // Required space for command 
sCommand := CONCAT(sCommand, sTargetDirectory); // Add target location
 
// Output -> ‘/C move C:\NET-DRIVE\NewOrders\Original.xml 'C:\NET-DRIVE\OldOrders’
 
 
 
Process(
    NETID := '',                    // Local System
    PATHSTR := 'C:\Windows\System32\cmd.exe',   // Path to local cmd executable
    COMNDLINE := sCommand,          // Comnmand to be executed
    ERR => bError,                   // Error Output
    ERRID => iErrorId                // Error Id Output
);
 
// Trigger Command
IF bTrigger THEN
    bTrigger := FALSE;
    Process(START:=TRUE);
    Process(START:=FALSE);
END_IF

I am trying to perform file management within the PLC. Currently, NT_StartProcess works as follows, but I will not have any feedback after the process has been spawned. Is there a way to check the contents of a directory from the PLC? Is there any way to get feedback from NT_StartProcess?

// File Locations
sTargetFilePath := 'C:\LocalHistory\test.job';
sTargetDirectory := 'C:\\CustomerDir';
 
// Build Command String
sCommand := '/C ';                  // Special command indicating command string input
sCommand := CONCAT(sCommand, 'move ');      // Add move command
sCommand := CONCAT(sCommand, sTargetFilePath);  // Add target file
sCommand := CONCAT(sCommand, ' ');          // Required space for command 
sCommand := CONCAT(sCommand, sTargetDirectory); // Add target location
 
// Output -> ‘/C move C:\NET-DRIVE\NewOrders\Original.xml 'C:\NET-DRIVE\OldOrders’
 
 
 
Process(
    NETID := '',                    // Local System
    PATHSTR := 'C:\Windows\System32\cmd.exe',   // Path to local cmd executable
    COMNDLINE := sCommand,          // Comnmand to be executed
    ERR => bError,                   // Error Output
    ERRID => iErrorId                // Error Id Output
);
 
// Trigger Command
IF bTrigger THEN
    bTrigger := FALSE;
    Process(START:=TRUE);
    Process(START:=FALSE);
END_IF

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2025-02-04 04:46:48

是的,有一种方法。您正在寻找的是这两个功能块:

,,,,您无法直接得到它。我一直在使用两个解决方法:

  1. 将结果写入文本文件,然后使用twincat打开此文件。
    在您的情况下,这将是这样的:
‘/C move C:\NET-DRIVE\NewOrders\Original.xml 'C:\NET-DRIVE\OldOrders && echo DONE > out.txt || echo FAIL > out.txt’

命令之后&&仅在先前的成功时才会执行。 ||之后的命令仅在以前失败时才能执行。

>操作员将上一个命令的输出写入文件

上面的示例应创建一个文件out.txt,并写入或fail内部。目前,我没有带有Twincat的PLC,但它在Windows CMD中起作用。

  1. 编写一个程序(例如在C#中),该程序需要完成需要完成的操作,然后通过广告连接到Twincat以将结果放入变量中

Yes, there is a way. What you are looking for are those two function blocks: FB_EnumFindFileList, FB_EnumFindFileEntry

As for feedback from NT_StartProcess, you can't get it directly. There are two workaround I've been using:

  1. Write the results to a text file, and open this file using TwinCAT.
    In your case it would be something like this:
‘/C move C:\NET-DRIVE\NewOrders\Original.xml 'C:\NET-DRIVE\OldOrders && echo DONE > out.txt || echo FAIL > out.txt’

Command after && will be executed only, if previous succeded. Command after || will be executed only if previous failed.

> operator writes output of previous command to a file

Example above should create a file out.txt and write DONE or FAIL inside. I don't have a PLC with TwinCAT with me at the moment, but it works in windows cmd.

  1. Write a program (In C# for example) that does what needs to be done and then connects to TwinCAT via ADS to put the result in variables
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文