DevOpen, doesn´t open in shared mode?

Hi!

I have a device created, dBASE_DEV, that creates an DBF.

I then call this device from a number of functions primarily using DevOpen in mode 0. Defined as mode 0, not relying on default 0.
This works fine when one function at a time opens the device, does it's thing, and then closes it.

But when I then have a loop that opens the device and each 10seconds scans through it just reading what´s in it, not closing it while sleeping. That function crashes when an other function opens the device.

It sounds like mode 0, shared mode, wouldn´t cause this. But Iv´e also tried mode 16, read only. But I get the same result with it crashing.
If I debug I get the error for bad handle, so I guess that the mode isn't as shared as one would think..

Am I using the device wrong? Maybe it can´t be opened from more than one function at a time?

Parents
  • Hi Anders,

    A handle is unique within a Citect process (client, I/O server, trend server, etc.). So you cannot share the handle across different machines and processes. A good place to store the handle is a MODULE or GLOBAL cicode variable, or a Local Variable tag.

    To be able to use the device from multiple machines/processes you have to open it in shared mode (or read only mode).
    To prevent conflicts you should also make sure that only one machine/process is writing to the device at the same time.

    I always try to prevent multiple access to a device if I can. For example, if I want to write log entries to a device, I would create a centralized logging function that runs only on the active server (say, the active report server process). All other machines and server processes would call this function using RPC (see MsgRPC cicode function).
Reply
  • Hi Anders,

    A handle is unique within a Citect process (client, I/O server, trend server, etc.). So you cannot share the handle across different machines and processes. A good place to store the handle is a MODULE or GLOBAL cicode variable, or a Local Variable tag.

    To be able to use the device from multiple machines/processes you have to open it in shared mode (or read only mode).
    To prevent conflicts you should also make sure that only one machine/process is writing to the device at the same time.

    I always try to prevent multiple access to a device if I can. For example, if I want to write log entries to a device, I would create a centralized logging function that runs only on the active server (say, the active report server process). All other machines and server processes would call this function using RPC (see MsgRPC cicode function).
Children
No Data