Home AMX User Forum NetLinx Studio

duplicate virtual devices in modules

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

Comments

  • NMarkRobertsNMarkRoberts Posts: 455
    Without answering your question cos I'm not sure, one of the reasons I always pass all devices through the module header is to clarify this and ensure that there is never a conflict in the code or in my mind.
  • David,
    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:
    DEFINE_DEVICE
    vdvLocalUse = DYNAMIC_VIRTUAL_DEVICE
    
    DYNAMIC_VIRTUAL_DEVICE is a key word. I am not sure if you can use it multiple times inside a module...

    Regards, Harald
  • HedbergHedberg Posts: 671

    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.

    Regards, Harald


    That's not what I would expect. I would expect that if I had:
    //Modle X Code
    
    define device
    
    myLoggerx = 34000:1:1
    

    in module x and
    //Module Y code
    
    define_device
    
    myLoggerry = 34000:1:1
    
    

    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?
  • DHawthorneDHawthorne Posts: 4,584
    Hedberg wrote:
    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.
  • GSLogicGSLogic Posts: 562
    dnahman wrote:
    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
    Why don't you just change the device IDs?
    mySocket1 = 00:07:01
    myLogger1 = 34000:01:01

    mySocket2 = 00:08:01
    myLogger2 = 34000:02:01
  • dnahmandnahman Posts: 28
    Thanks for the replies.

    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
  • HedbergHedberg Posts: 671
    I wouldn't think it would be too hard to fix it. Define the virtual device(or devices) in the parent code and pass them in the module call. In the module all you have to do is take out the discreet virtual device definitions.
  • Hedberg wrote:
    I wouldn't think it would be too hard to fix it. Define the virtual device(or devices) in the parent code and pass them in the module call. In the module all you have to do is take out the discreet virtual device definitions.
    I can only agree to the last recommendation posted.

    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
Sign In or Register to comment.