public override void Execute() { _apm.MessageLog("Executing " + diagnosticName); bool foundFlag = false; try { BACnetPacket resp; BACnetPacket pkt = new BACnetPacket(this._apm); pkt.EncodeNPCI(new DADR(), BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); pkt.EncodeContextTag(0, (int)devicTreeNode.device.deviceObjectID.objectInstance); pkt.EncodeContextTag(1, (int)devicTreeNode.device.deviceObjectID.objectInstance); BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); // wait for _our_ device to respond do { try { // We expect to timeout resp = waitForPacket(5000, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM); if (resp.srcDevice.deviceObjectID.Equals(devicTreeNode.device.deviceObjectID)) { foundFlag = true; } else { Sleep(5000); ClearIncomingPacketQueue(); MarkDiagnosticFailed(); return; } } catch (TimeoutException) { // remember we expect to time out if (foundFlag == true) { MarkDiagnosticSuccess(); return; } else { MarkDiagnosticFailed(); return; } } }while (true); } catch (Exception ex) { // other types of exception... _apm.MessagePanic(ex.ToString()); return; } }
public override void Execute() { try { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(_apm, BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); pkt.dAdr = new DADR(this.device.adr); pkt.EncodeNPCI(pkt.dAdr, BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); // Encode the rest of the packet according to http://www.bacnetwiki.com/wiki/index.php?title=Read_Property pkt.EncodeContextTag(0, this.device.deviceObjectID); pkt.EncodeContextTag(1, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE); pkt.EncodeContextTag(1, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_IDENTIFIER); BACnetUtil.SendOffPacket(this._apm, this._bnm, pkt, pkt.buffer, pkt.optr); BACnetPacket respPkt = waitForPacket(5000); // Since we made a deliberate mistake with our request, we expect a reject PDU. Make sure we get it if (respPkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_REJECT) { if (respPkt.pduRejectReason == BACnetEnums.BACNET_BACNET_REJECT_REASON.REJECT_REASON_TOO_MANY_ARGUMENTS || respPkt.pduRejectReason == BACnetEnums.BACNET_BACNET_REJECT_REASON.REJECT_REASON_INVALID_TAG) { MarkDiagnosticSuccess(); return; } else { MarkDiagnosticFailed("Reject PDU OK, but reason not OK"); return; } } else { MarkDiagnosticFailed("Reject PDU expected"); return; } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; //BACnetLibrary.Panic(ex.ToString()); //return; } }
public override void Execute() { try { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(_apm, BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); pkt.dAdr = new DADR(this.device.adr); pkt.EncodeNPCI(pkt.dAdr, BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); // Encode the rest of the packet according to http://www.bacnetwiki.com/wiki/index.php?title=Read_Property pkt.EncodeContextTag(0, this.device.deviceObjectID); pkt.EncodeContextTag(1, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE); // Now, by definition, there can only be one device instance. Try and read the 3rd. If the device responds with anything but an error, it fails pkt.EncodeContextTag(2, 3); BACnetUtil.SendOffPacket(this._apm, this._bnm, pkt, pkt.buffer, pkt.optr); BACnetPacket respPkt = waitForPacket(5000); // Since we made a deliberate mistake with our request, we expect a reject PDU. Make sure we get it if (respPkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_ERROR) { if (respPkt.errorClass == (int)BACnetEnums.BACNET_ERROR_CLASS.ERROR_CLASS_PROPERTY && respPkt.errorCode == (int)BACnetEnums.BACNET_ERROR_CODE.ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY) { MarkDiagnosticSuccess(); return; } else { MarkDiagnosticFailed("Error PDU OK, but error class or error code not OK"); return; } } else { MarkDiagnosticFailed("Error PDU expected"); return; } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; } }
public override void Execute() { _apm.MessageLog("Executing " + diagnosticName); try { BACnetPacket resp; BACnetPacket pkt = new BACnetPacket(this._apm); pkt.EncodeNPCI(new DADR(), BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); pkt.EncodeContextTag(0, 0); pkt.EncodeContextTag(1, BACnetEnums.BACNET_MAX_INSTANCE); BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); // wait for _our_ device to respond do { resp = waitForPacket(5000, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM); if (resp.srcDevice.deviceObjectID.Equals(devicTreeNode.device.deviceObjectID)) { Sleep(5000); ClearIncomingPacketQueue(); MarkDiagnosticSuccess(); return; } }while (true); } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... _apm.MessagePanic(ex.ToString()); return; } }
public override void Execute() { _apm.MessageLog("Executing " + diagnosticName); try { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(this._apm); pkt.EncodeNPCI(new DADR(), BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); pkt.EncodeContextTag(0, (int)devicTreeNode.device.deviceObjectID.objectInstance); // Ha! Notice we did not encode the second part of the who-is. Devices should not respond. BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); // wait for _our_ device to respond while (true) { try { // We expect to timeout waitForPacket(5000, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM); ClearIncomingPacketQueue(); MarkDiagnosticFailed("There should be NO response from the device"); return; } catch (TimeoutException) { // remember we expect to time out MarkDiagnosticSuccess(); return; } } } catch (Exception ex) { // other types of exception... _apm.MessagePanic(ex.ToString()); return; } }
public override void Execute() { try { List <BACnetEnums.BACNET_PROPERTY_ID> propList = new List <BACnetEnums.BACNET_PROPERTY_ID>(new BACnetEnums.BACNET_PROPERTY_ID[] { BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_IDENTIFIER, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_NAME, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE, BACnetEnums.BACNET_PROPERTY_ID.PROP_SYSTEM_STATUS, BACnetEnums.BACNET_PROPERTY_ID.PROP_VENDOR_NAME, BACnetEnums.BACNET_PROPERTY_ID.PROP_VENDOR_IDENTIFIER, BACnetEnums.BACNET_PROPERTY_ID.PROP_MODEL_NAME, BACnetEnums.BACNET_PROPERTY_ID.PROP_FIRMWARE_REVISION, BACnetEnums.BACNET_PROPERTY_ID.PROP_APPLICATION_SOFTWARE_VERSION, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_VERSION, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_REVISION, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_SERVICES_SUPPORTED, BACnetEnums.BACNET_PROPERTY_ID.PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_LIST, BACnetEnums.BACNET_PROPERTY_ID.PROP_MAX_APDU_LENGTH_ACCEPTED, BACnetEnums.BACNET_PROPERTY_ID.PROP_SEGMENTATION_SUPPORTED, BACnetEnums.BACNET_PROPERTY_ID.PROP_APDU_TIMEOUT, BACnetEnums.BACNET_PROPERTY_ID.PROP_NUMBER_OF_APDU_RETRIES, // todo, only mstp BACnetEnums.BACNET_PROPERTY_ID.PROP_MAX_MASTER, // todo, only mstp BACnetEnums.BACNET_PROPERTY_ID.PROP_MAX_INFO_FRAMES, BACnetEnums.BACNET_PROPERTY_ID.PROP_DEVICE_ADDRESS_BINDING, BACnetEnums.BACNET_PROPERTY_ID.PROP_DATABASE_REVISION }); foreach (BACnetEnums.BACNET_PROPERTY_ID pid in propList) { ClearIncomingPacketQueue(); BACnetPacket pkt = new BACnetPacket(_apm, BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); pkt.dAdr = new DADR(this.device.adr); pkt.EncodeNPCI(pkt.dAdr, BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY); // Encode the rest of the packet according to http://www.bacnetwiki.com/wiki/index.php?title=Read_Property pkt.EncodeContextTag(0, this.device.deviceObjectID); pkt.EncodeContextTag(1, pid); BACnetUtil.SendOffPacket(this._apm, this._bnm, pkt, pkt.buffer, pkt.optr); BACnetPacket respPkt = waitForPacket(5000); // Since we made a deliberate mistake with our request, we expect a reject PDU. Make sure we get it if (respPkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_COMPLEX_ACK) { if (respPkt.confirmedServiceChoice == BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY) { // so far, so good, continue if (respPkt.invokeID + 1 != _apm.invokeID) { MarkDiagnosticFailed("Bad Invoke ID in the response"); return; } if (respPkt.propertyID != pid) { MarkDiagnosticFailed("Bad Property in the response"); return; } } else { MarkDiagnosticFailed("Did not receive a response to the confirmed read property"); return; } } else { MarkDiagnosticFailed("Expected a Complex ACK response"); return; } } } catch (TimeoutException) { // todo-put a wrapper around execute and catch all executions in a common area.. MarkDiagnosticFailed("Timeout"); return; } catch (Exception ex) { // other types of exception... throw ex; } MarkDiagnosticSuccess(); }