Change port at run time

logantvlogantv ProgrammerPosts: 10

I'm 99.99% sure the answer is just going to be "you can't do that because it's in the compiler", but is it possible to change a define_device port number programmaticaly? I want to be able to dev_info the controller and set the dvRelay port based on the reply.

My workaround would be to define all of the options and then switch/case the commands later, unless anyone has a better idea. Thanks in advance.

Comments

  • sentry07sentry07 Junior Member Posts: 64

    You don't have to define devices in the DEFINE_DEVICE section. You can define them in the DEFINE_CONSTANT and DEFINE_VARIABLE sections as well. The variable type is DEV. For example:

    DEFINE_VARIABLE
    DEV dvRelays = 5001:21:0

    And then later you can define that variable with the standard D:P:S and it will work just like an object defined in the DEFINE_DEVICE section. JUST BE AWARE that if you do something like this and have a DATA_EVENT or BUTTON_EVENT or any type of event that uses a device variable and you change it, you MUST call REBUILD_EVENT, otherwise the event table will still be using the old device DPS. This isn't really a problem with relays, but just wanted you to know.

  • logantvlogantv Programmer Posts: 10

    Awesome, thanks!!

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 471
    edited August 28

    Just be aware that there are some required internal processes enabled with DEFINE_DEVICE that don't exist within the DEFINE_CONSTANT or DEFINE_VARIABLE sections. Not so much an issue with real NetLinx devices connected locally but something to watch out for with master to master real devices and any virtual device.

    This is only pertinent to devices referenced as event parameters (ie, the device in a channel event), where the event tables mentioned above are affected. For controlled devices, as long as the address can be resolved locally or across a master to master connection the d:p:s can be referenced in any manner (constant, variable, literal, hybrid).

Sign In or Register to comment.