About This Application switches from one thread to other automatically. It is a common misconception that you execute a SCADA system when you execute a PLC program. A PLC program contains a simple loop: PLC Program Loop However, in a SCADA system, there are several modules running simultaneously, and most of them can read and write data. Because a SCADA system modifies data (tag values) continuously during task execution, the preceding diagram is not applicable. IWS only has one process: Studio Manager.exe . When you execute a runtime project, the Studio Manager.exe process starts the Tags database and all of the runtime modules configured for the project.
You can specify which modules (such as Viewer and Driver ) will start during the runtime. Each process keeps a list of active threads for the operating system. Actually, each process activates and deactivates each thread during the runtime, according to the algorithm of each process. Also, when you create a thread you specify a priority value. The operating system continuously scans all currently active threads, and executes the threads according to their priority value — executing the higher-priority threads first. When threads with higher-priority values are active, the threads with lower-priority values are not executed at all.
If there is more than one thread with the same priority value, and there are no other threads with higher-priority values, the operating system keeps switching between the threads with the same priority. Note: All IWS threads are set to priority 7 , which is THREAD_PRIORITY_NORMAL . (Most programs contain this priority value.) Real-time program (such as SoftPLCs and Device Drivers) threads are assigned a higher-priority value ( THREAD_PRIORITY_HIGHEST ); however, these programs must provide a mechanism to keep them inactive for some period of time or the threads with normal priority would never be executed. IWS uses the UNICOMM.DLL library for serial drivers.
This library creates a THREAD_PRIORITY_HIGHEST thread that "sleeps" (remains inactive) until data arrives in the serial channel. When IWS detects new data in the serial channel, the THREAD_PRIORITY_HIGHEST thread "wakes up" (becomes active) and transfers the data from the operating system buffer to the thread buffer, where it can be read by the Driver. This thread is the only highest-priority thread created by IWS. If you allowed threads to remain active all the time, the CPU usage would be 100% all the time, which must be avoided for performance reasons. Every program provides a mechanism to prevent threads from staying active all the time.
IWS uses the following parameters to prevent threads from staying active continuously: • TimeSlice (from operating system): Causes the operating system to switch automatically between active threads with the same priority value. By default, the operating system executes each active thread for approximately 20ms and then switches to the next active thread. In other words, if there are multiple active threads with the same priority value waiting to be executed, the operating system will not execute any one active thread for more than 20ms. • TimeSlice (from IWS): Specifies how long each IWS thread can remain continuously active.
You use this parameter in addition to the operating system's TimeSlice parameter. You configure a TimeSlice value for each IWS thread (except the Background Task) and specify how long each thread InduSoft Web Studio Page 21