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() { _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); // 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() { try { _apm.MessageLog("Executing " + diagnosticName); ClearIncomingPacketQueue(); // find a non-existing network number in the whole attached BACnet internetwork by examining our internal router table that // has been built up during device discovery phase int useThisNetworkNumber = 9; for (int i = 0xfffe; i > 1; i--) { if (_apm.internalRouterInfo.FindRoutingTableEntry(i) == null) { // we have not seen or used this network number yet useThisNetworkNumber = i; break; } } // BACnetUtil.SendReadProperty(_apm, _bnm, deviceNode.device, deviceNode.device.deviceObjectID, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE); BACnetPacket pkt = new BACnetPacket(_apm); // pkt.EncodeBVLL(new DADR(deviceNode.device.adr), BACnetEnums.BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_UNICAST_NPDU); pkt.EncodeNPCI(new DADR(devicTreeNode.device.adr), new ADR((ushort)useThisNetworkNumber, (uint)3), BACnetLibrary.BACnetPacket.MESSAGE_TYPE.APPLICATION); // todonow, put these next steps into functions // build confirmed request header // http://www.bacnetwiki.com/wiki/index.php?title=BACnet-Confirmed-Request-PDU pkt.buffer[pkt.optr++] = (Byte)BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST; pkt.buffer[pkt.optr++] = 0x05; // max segs, max resp. todo pkt.buffer[pkt.optr++] = _apm.invokeID++; // sequence number may come next, dep on flags. todo pkt.buffer[pkt.optr++] = (byte)BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY; // context encoding // http://www.bacnetwiki.com/wiki/index.php?title=Read_Property devicTreeNode.device.deviceObjectID.Encode(pkt.buffer, ref pkt.optr); BACnetUtil.EncodeContextTag(pkt.buffer, ref pkt.optr, 1, (int)BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE); BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); BACnetPacket respPkt = waitForPacket(5000); } 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(); }
private void buttonWhoIsLongMAC_Click(object sender, EventArgs e) { // BTL Implementation Guide, Section 2.9 - be prepared to accept a MAC address up to 18 bytes long. Here is the test. I have not found any device that passes this yet. BACnetPacket pkt = new BACnetPacket(_apm); pkt.EncodeBVLL(BACnetEnums.BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_BROADCAST_NPDU); pkt.EncodeNPCI(new DADR(BACnetPacket.ADDRESS_TYPE.GLOBAL_BROADCAST), new ADR(3333, "0102030405060708"), BACnetLibrary.BACnetPacket.MESSAGE_TYPE.APPLICATION); pkt.EncodeAPDUheader(BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS); BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr); }
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(); }