duplicate virtual devices in modules
dnahman
Posts: 28
Hi there,
What happens if I have two different modules with the same device IDs defined within them.
eg Module 1:
DEFINE_DEVICE
mySocket = 00:07:01
myLogger = 34000:01:01
and Module 2:
DEFINE_DEVICE
mySocket2 = 00:07:01
myLogger2 = 34000:01:01
Do these devices end up colliding with each other? (These devices are needed for the internal functioning of the module, and are in addition to the devices passed in to the module definition from the parent program).
Thanks
David
What happens if I have two different modules with the same device IDs defined within them.
eg Module 1:
DEFINE_DEVICE
mySocket = 00:07:01
myLogger = 34000:01:01
and Module 2:
DEFINE_DEVICE
mySocket2 = 00:07:01
myLogger2 = 34000:01:01
Do these devices end up colliding with each other? (These devices are needed for the internal functioning of the module, and are in addition to the devices passed in to the module definition from the parent program).
Thanks
David
0
Comments
the device definitions for the sockets should be located in the main code and passed into the module, otherwise the definitions in your sample will collide (because of double usage of 0:7:1). The socket devices are something "global" and have to be unique.
If you need a virtual device only for internal use within a module, you can use the same device number multiple times (for example myLoggerx = 34000:01:01 in your sample). The scope of this definition is limited to the module and does not get in conflict with other modules or the main code.
As an alternative:
If you want to declare a virtual device only for use inside a module, you can use the following declaration: DYNAMIC_VIRTUAL_DEVICE is a key word. I am not sure if you can use it multiple times inside a module...
Regards, Harald
That's not what I would expect. I would expect that if I had:
in module x and
in module y that commands sent to the virtual in module x would trigger data events in module y. That channel changes in the module x virtual device would cause channel events in module y. Of course, the names assigned to the device will be limited to use in the modules in which they are defined.
I believe that that would be the case with real devices, I don't know why virtual devices would be different. Can one master have more than one virtual device 34000:1:0?
Virtual devices are allocated and stored in global memory, not the memory space of the module. So, you cannot have two separate virtual devices with the same dev:port:system address; they would both refer to the same memory space. It's identical to the way real devices are handled. You can have duplicate variables,calls, functions and timelines because they reside in the module's memory space and are tokenized by the module instance. ANy kind of device, real or virtual, is not.
This a a feature, not a drawback. It allows you to use a virtual device to communicate with the module. If device space was independent for the module, you couldn't do this; your send_commands and such would only act on the calling program and the module would never get them.
mySocket1 = 00:07:01
myLogger1 = 34000:01:01
mySocket2 = 00:08:01
myLogger2 = 34000:02:01
I was trying to wrap some code that I had formerly written as an include file into a module.
My original code expects to have my global logging device and my global console device already defined in the parent program. The module parameters would be for the actual physical device that is being controlled and its matching device.
I guess I'll untwist it all and write it as a traditional module.
Thanks
david
I have to correct the statement in my post earlier (3rd post in this thread). Virtual devices are a global thing, even if only defined inside a module and not included in the parameter list of the module.
Maybe I was tricked by the DYNAMIC_VIRTUAL_DEVICE keyword. This is the way to define a virtual device you only want to use inside your module. You can use the keyword multiple times in one module or in multiple modules. The keyword is resolved into a unique device number which is not used already.
Regards, Harald