Home AMX User Forum NetLinx Studio

Virtuals - Purpose

In going through what AMX describes as the purpose of a virtual and what I've been reading on the boards, it sounds like the programmer community uses them in different ways that AMX may have initially intended them. The majority of posts that I've seen around virtuals seem to center around two main uses:

1) To assign a single virtual to an array of touchpanels to keep all touchpanels in sync, although it sounds like this may not be a good solution as it creates a lot network traffic as your TP count goes higher? I see a lot of commentary around using arrays instead of a single virtual.

2) Communication back and forth between your main program code and module code. It appears that using a combination of SEND_COMMAND and SEND_STRING, the virtual creates a doorway in and out of the module which can be useful for status, debugging, testing...and just keeping design more modular.

I haven't seen a lot of discussion around the positives of doing device combining which makes me wonder if I should just avoid it.

I'm sure there are other benefits around virtuals that I'm missing so I wanted to open it up for discussion.

Thanks!
Matthew

Comments

  • Thomas HayesThomas Hayes Posts: 1,164
    One thing I was told by AMX was that a virtual device will never drop off line, so if a hard device goes down the system is less likely to hang (this depends on how the code is written) than if you have a device that is not really there.
  • DHawthorneDHawthorne Posts: 4,584
    I use them in two ways: (1) as an interface for a module to communicate to the main program, or for one master to talk to others; (2) as an alias for a device used in a different mode. For an example of number 2, if I have a CD player that will also plays 5-channel discs, I'll create a virtual source for the 5-channel mode. Since it is physically the same device, I want all my feedback to still reflect it is in an entirely different mode without having to set and track flags. I use the real device for standard CD mode, and the virtual for 5-channel, and then use a wrapper for IR functions that has button presses on the virtual talk to the same device. It sound a lot more cumbersome than it is, and I find it a convenient way of doing it.

    I avoid combining real devices to a virtual whenever I can; I'll use arrays for that.
  • I'm in a situation where I'm moving the module UI's that I've written off of a main master where the real device is connected and placing them on the individual masters where their touchpanels reside. In other words, the theater room has it's own master and touchpanel, as does the family room, and several other rooms. Since the UI for this particular module is processor intensive, it makes more sense to have them on different masters rather than on one master and handling lots of requests from 2 dozen+ TPs. All of the UI modules on different masters can do their processing then send their commands to control the real device by communicating with the virtual on the main processor. The virtual only has to queue up all of the commands and send them to the real device in an orderly fashion and can do this without fear of crashing the device or losing packets. Using a virtual device makes this real simple to do.

    Like Dave, I also use virtual devices for passing information to different masters and to/from modules. In a simple way, I can have a module turn channels on and off on a virtual device then have the main program or another master check if a channel is turned on/off easily before executing something.

    --John
  • Thanks guys for the great responses. To John's point, I've seen some code where there are some standard constants setup for channels such as DEBUGGING, BUSY, ONLINE...so in this scenario, I imagine when the device is busy, the developer will flag the virtual to be BUSY and then the main program can look at the virtual and see this channel on?

    Or do I totally misunderstand?

    Cheers,
    Matthew
  • DHawthorneDHawthorne Posts: 4,584
    You can use channels in lieu of variable flags, and levels in lieu of integer variables. But you can also use SEND_COMMAND to instruct the module/remote master to perform a function, and SEND_STRING for text based feedback.
  • Alrighty...with that, I think I'm ready to dive back in and play with some virtuals. Thanks for the clarification everyone!

    Cheers,
    Matthew
  • a_riot42a_riot42 Posts: 1,624
    I think of virtual devices as structures that contain channels, levels and buttons that I can manipulate to reflect the state of some machine. I never have found a compelling reason to use combines so I avoid them, as I do most other non-regular programming mechanisms like devchans, wait_untils, create_buffers, etc. Now if they would just include associative arrays, I would be happier.
    Paul
  • Thanks, Paul. I think that's pretty much what I've decided to use them for. I am not using any device combining on my current project. Not to say I'll never use it as I know some programmers are using them.

    Cheers,
    Matthew
Sign In or Register to comment.