/// <summary> /// Sends a message to the device with the given /// DeviceId in order to try to identify it, and /// if successful, returns a DeviceBase object. /// The derived type of the returned object varies /// depending on the Device category discovered /// during the identification process. /// </summary> /// <param name="dottedHexId">Example: new DeviceId("12.34.56")</param> /// <returns>null if unsuccessful - check plm.Exception</returns> public bool TryConnectToDevice(DeviceId deviceId, out DeviceBase device) { if(deviceId == null) throw new ArgumentNullException("deviceId"); DeviceBase result = null; if (this.deviceCache.ContainsKey(deviceId)) { result = this.deviceCache[deviceId]; } else { this.plm.exceptionHandler(() => { byte[] responseAck = this.plm.sendStandardLengthMessageAndWait4Response( deviceId, Constants.MSG_FLAGS_DIRECT, 0x10, 0x00); byte[] responseIdRequest = this.plm.waitForStandardMessageFrom(deviceId); result = DeviceFactory.BuildDevice(this.plm, responseIdRequest); }); if (result != null) { this.deviceCache.Add(deviceId, result); } } device = result; return result != null; }
/// <summary> /// Sends a message to the device with the given /// DeviceId in order to try to identify it, and /// if successful, returns a DeviceBase object. /// The derived type of the returned object varies /// depending on the Device category discovered /// during the identification process. /// </summary> /// <param name="dottedHexId">Example: "12.34.56"</param> /// <returns>null if unsuccessful - check plm.Exception</returns> public bool TryConnectToDevice(string dottedHexId, out DeviceBase device) { var peerId = new DeviceId(dottedHexId); return TryConnectToDevice(peerId, out device); }