Announcement

Collapse
No announcement yet.

Regarding Getting A Device Reference

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regarding Getting A Device Reference

    The question about the best way to get a reference to a device was posed to me, and I thought I would post the answer here as an aid to script authors:
    Good question that a lot of people have, but there is a bit of a misconception. The hc/dc is not eliminated, it is simply no longer REQUIRED. The addressing of devices has actually been enhanced. There is now an Address field which may be populated with anything meaningful for the device. There is then the Code field, which is no longer a separate HC/DC but a single string field that is INTENDED to be used to hold a HC/DC.

    When you view a device which has both parts, it always shows as: Address-Code. If, for example, the address of a device is Unit1, and the code field is not used, then the address is just Unit1. If the code was set to Y55, then the address as displayed would be Unit1-Y55.

    Getting the reference to a device has the same capabilities and more now, but you have to look in the scripting SDK to see the new commands.
    hs.DeviceExistsAddress returns the device reference ID for a device that matches the given address - it will NOT look at the code field, and there is a parameter to indicate whether the search is case sensitive or not.
    hs.DeviceExistsCode returns the device reference ID for a device that matches the given code - it will NOT look at the address field. The search through the code is always case insensitive. The search assumes a HC/DC format so that it can find A01 even if the code given to find is A1. If the code field is not in that format then it will have to match exactly.
    hs.DeviceExistsAddressFull returns the device reference ID for a device that matches the given full address in Address-Code format. This procedure also has a CaseSensitive flag which may be used to force a match of the exact case of the Address-Code of the device.
    hs.GetDeviceRef returns the device reference ID for a device that matches the given address, same as hs.DeviceExistsAddress.
    hs.GetDeviceRefByName returns the device reference ID for a device given its name. The code will try parsing the name provided for the search against various combinations of the device name, location, and location2 to find a match. Device names or locations with spaces may provide difficulty in obtaining the proper unique device, so using one of the address-code matches should be done first.

    There are other related commands: hs.DeviceExistsRef, hs.GetDeviceParentRefByRef, hs.GetDeviceCode - see the scripting documentation for more information.

    Hope this helps!
    Regards,

    Rick Tinker (a.k.a. "Tink")
Working...
X