Applies To: |
|
Summary: |
Question: I have configured a button up and down command and it appears if I press the button down and up very quickly sometimes the up command executes before the down command. |
Solution: |
Due to the design of Citect it is possible
for the button up command to execute before the button down
command. This is because Citect is a fully multhreaded and
premptive system.
When you press a button or keyboard command, Citect will start the command you have attached to that button or keyboard command. Note that Citect will start the command, Citect does not wait for the command to finish. As Citect is premptive and multhreaded that command will execute in parallel with all other commands as well as Citects operation. So while the command is executing you can start new commands. If the new command is very small it is possible for the second command to complete before the first command has completed (or even started). This is not normally a problem for very simple commands, as cicode is very fast (see Q1409). So the command will complete before you have time to type the next keyboard command or press the next button. However when you have commands on the button down and up command, it is possible to press the button down and release the button very quickly (say less than 100ms). Therefor you have a much greater chance of seeing this effect with button commands. For very simple commands which don't read any data from the PLC this is not a problem as cicode is so fast it is very unlikely to occur. For example commands such as: PLC_TAG = 1; OR SP123 = ####; OR PageDisplay("menu"); These types of cicode commands will be started immediately and will run to completion as they are very simple cicode. However a command such as: PLC_TAG = NOT PLC_TAG; OR Toggle(PLC_TAG); OR SP123 = SP124 + 10; all require data to be read from the PLC before they can start executing. See Q1075 for a description on how this happens. So if the button down command contained one of these commands and the up command contains a simpiler command. Then it is quite possible for the up command to execute before the down command if you press the button very quickly. In this case very quickly depends on how fast the PLC response is, with slow PLCs it could be several seconds. You may work around this problem by putting a SleepMS(<some small time>); as the first part of the button up command or if there is some way you can check if the down command has completed before starting the up command. See also Q1858 for how a button up command can be aborted. |
Keywords: |
Related Links
Attachments