Applies To:
  • CitectSCADA 1.00 1.01 1.10 1.11 1.20 2.00 2.01

Question: I have two Citects on a network and I need to control their access to a database device. I only want one Citect to access the database at the same time. Can I use semaphores for this control? 

Semaphores are used for access control in a single Citect. That it they will allow one Citect cicode task (thread) to access to the device while preventing access to the device from all other cicode tasks on the same computers. Note that semaphores are local to the computer, they do not stop cicode tasks in other Citects nodes from accessing the same device.

To have unique access to a database you should open the database device in exclusive mode. When you tell Citect to open the database in exclusive mode Citect will try to get exclusive access to the device. In this mode if another Citect or any other program has the database device open the DevOpen() function will fail. If no other Citect or application has the database open then the DevOpen will successfully open the device and also prevent any other Citect or application from opening the database. If other Citect tries to open the device in exclusive or non exclusive mode their call to DevOpen() will fail.

Because of this effect you can use a database device as a semaphore. For example you could define a device called SEM which you cicode must open to allow access to something else.

hDev = DevOpen("SEM", 1);
WHILE hDev = -1 DO
   hDev = DevOpen("SEM", 1);
! access something else which is global on the network
! close the sem device to allow other Citects back in