简体   繁体   English

结构化文本与传统编程语言

[英]Structured Text Vs Traditional Programming Languages

I have started Programming Logic Controller (PLC) using Structured Text. 我已经开始使用结构化文本对Logic Controller(PLC)进行编程。 My Background is from IT or computer science. 我的背景是IT或计算机科学的。 So I am used to traditional Programming languages like Java, C# etc... I just realize that PLC requires a different Mind set. 因此,我习惯了Java,C#等传统编程语言……我只是意识到PLC需要不同的思维方式。 Understanding scan cycle... Can someone explain to me more clearer the following paragraph I read from 理解扫描周期...有人可以给我更多更清晰的解释下面的段落我看了

One important difference between ST and traditional programming languages is the nature of program flow control. ST与传统编程语言之间的一个重要区别是程序流控制的性质。 A ST program will be run from beginning to end many times each second. 一个ST程序将每秒从头到尾运行很多次。 A traditional program should not reach the end until it is completely finished. 传统程序要等到完全完成后才能结束。

A PLC program is different from what you already know in that it typically has a main task, which is executed cyclically, ie once per scan cycle. PLC程序与您已经知道的程序不同,它通常具有一个主要任务,该任务是周期性执行的,即每个扫描周期执行一次。 The main task then calls a list of subtasks or -programs and when this is done, the main task is run again. 然后,主任务调用子任务或-programs的列表,完成后,将再次运行主任务。

The scan cycle can be set to run at intervals, for example each 10ms. 可以将扫描周期设置为间隔运行,例如每10毫秒运行一次。 The PLC will then update the IO, run the program and then do nothing while waiting for the next trigger. 然后,PLC将更新IO,运行程序,然后在等待下一个触发器时不执行任何操作。 If you have a fixed scan time, you can use this to make very precisely synchronized programs, but it is important that your program (main task and its subtasks) always execute within this time. 如果您有固定的扫描时间,则可以使用它来制作非常精确的同步程序,但重要的是,程序(主任务及其子任务)必须始终在此时间内执行。

Some PLCs can be setup to run the scan cycles one after another, as fast as possible. 可以将某些PLC设置为尽可能快地一个接一个地运行扫描周期。 The scan time is then variable, but you still have to monitor the scan times to make sure the program is running fairly consistent cycle times. 扫描时间是可变的,但是您仍然必须监视扫描时间,以确保程序运行的周期时间相当一致。

One of the most important lessons I have learned in the transition from other languages to PLC language, is to keep the program flow as sequential as possible, since any loops and deviations influence the execution time which must always be less than the scan time. 在从其他语言到PLC语言的过渡中,我学到的最重要的教训之一是,要使程序流尽可能保持顺序,因为任何循环和偏差都会影响执行时间,执行时间必须始终小于扫描时间。

This means eg: during 1 sec your PLC program is executed 1sec/cycletime. 这表示例如:在1秒内,您的PLC程序以1秒/周期的时间执行。 So if you have a cycletime of eg 1ms, your program is executed 1000 times in a second. 因此,如果您的周期时间为例如1毫秒,则您的程序将在一秒钟内执行1000次。 Thats the main difference. 那就是主要区别。 It is deterministically. 它是确定性的。 This is what the paragraph means. 这就是本段的意思。 And it is not finished when it reaches the end. 到达终点时还没有完成。 it restarts with an updated process image. 它以更新的过程映像重新启动。

In, lets say, non-PLC programs (like on your pc) you have something like a 可以说,在非PLC程序(例如您的PC上)中,

 while(!_end)
 {
      /* your code */
 }

In principle, the PLC works similar to this. 原则上,PLC的工作与此类似。 But on your PC there is no need to execute programs cyclically in hard time frames like eg 500µs. 但是在您的PC上,无需在诸如500µs之类的困难时间内周期性地执行程序。 Most of the applications for your PC are ,lets call it, 'time uncritical'. 您的PC的大多数应用程序都是“时间紧迫”的称呼。 The big difference is, that the PLC runs the full program and before it starts the next run it refreshs its process image (writing outputs / reading inputs). 最大的区别在于,PLC运行完整的程序,在开始下一次运行之前,它将刷新其过程映像(写入输出/读取输入)。 The program execution is triggered by a so called 'task'. 程序执行由所谓的“任务”触发。 This task is responsible for keeping your control in realtime. 该任务负责使您的控制保持实时。 The process image, which I mentioned before, is the sum of all process values which are present for the PLC (like digital I/Os, motor driver values ,...). 我之前提到的过程映像是PLC存在的所有过程值的总和(例如数字I / O,电机驱动器值...)。 So you see, it is a kind of loop, but not the same like you know it from your c#/java-programs. 如此看来,这是一种循环,但与您从c#/ java-programs中了解到的循环不同。

(btw, i couldnt open your pdf) (顺便说一句,我无法打开您的pdf文件)

pboedker and ChrisKo answers are both good. pboedker和ChrisKo的答案都很好。 A couple of extra warnings are needed. 需要几个额外的警告。

A scan (or the scan time) can be shorter than your code's execution time. 扫描(或扫描时间)可以短于代码的执行时间。 In most PLC's there is a "watchdog" to detect this, and warn you that it is happening. 在大多数PLC中,都有一个“看门狗”来检测到此情况,并警告您它正在​​发生。 You often need to set this "watchdog" up, and set up a alarm/event handler for it. 您通常需要设置此“看门狗”,并为其设置警报/事件处理程序。

Know how your PLC executes I/O. 了解您的PLC如何执行I / O。 Some (Such as ControlLogix) are Asynchronous, I/O gets read into your controllers memory based on the RPI (request packet interval), and gets written out (same RPI) when you make a change to the I/O point with code. 有些(例如ControlLogix)是异步的,因此I / O会根据RPI(请求数据包间隔)读入控制器内存,并在您用代码更改I / O点时被写出(相同RPI)。 Others (Such as AutomationDirect's Productivity 2000 series) only write the outputs upon a COMPLETE scan of your code. 其他(例如AutomationDirect的Productivity 2000系列)仅在对代码进行完整扫描时才写入输出。 I'm sure you can picture the pro's and cons of each scenario, especially if your controller is not completing your code before restarting a scan. 我确定您可以了解每种情况的利弊,特别是如果控制器在重新启动扫描之前未完成代码时。

PLC's that allow you to have different scan rates for different pieces of code give you powerful tools for I/O and program flow management. PLC允许您对不同的代码段使用不同的扫描速率,从而为您提供强大的I / O和程序流管理工具。 Slow processes can be scanned slowly, allowing you more PLC time for other things. 缓慢的过程可以被缓慢地扫描,从而使您有更多的PLC时间进行其他操作。

I'm a PLC programmer. 我是一名PLC程序员。 and I want to use PC to control PLC, PLC as a dumb IO. 我想使用PC来控制PLC,将PLC作为愚蠢的IO。 PLC programming is always cycling and scanning.And each scan time is several mili-sec. PLC编程总是循环和扫描,每个扫描时间为几毫秒。 You can understand it as while statement which ChrisKo said. 您可以将其理解为ChrisKo所说的while陈述。

while(1=1)
{
    // code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM