diff --git a/bacnet-stack/demo/readpropm/main.c b/bacnet-stack/demo/readpropm/main.c index 82c2e016..f23a0538 100644 --- a/bacnet-stack/demo/readpropm/main.c +++ b/bacnet-stack/demo/readpropm/main.c @@ -315,22 +315,17 @@ int main( /* increment timer - exit if timed out */ current_seconds = time(NULL); - /* returns 0 bytes on timeout */ - pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); - - /* process */ - if (pdu_len) { - npdu_handler(&src, &Rx_Buf[0], pdu_len); - } /* at least one second has passed */ if (current_seconds != last_seconds) tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + if(!found){ + found = + address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); + } if (found) { if (invoke_id == 0) { invoke_id = @@ -355,6 +350,15 @@ int main( break; } } + + /* returns 0 bytes on timeout */ + pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); + + /* process */ + if (pdu_len) { + npdu_handler(&src, &Rx_Buf[0], pdu_len); + } + /* keep track of time for next check */ last_seconds = current_seconds; } diff --git a/bacnet-stack/demo/writeprop/main.c b/bacnet-stack/demo/writeprop/main.c index 5312bf13..2cce4616 100644 --- a/bacnet-stack/demo/writeprop/main.c +++ b/bacnet-stack/demo/writeprop/main.c @@ -428,22 +428,17 @@ int main(int argc, char *argv[]) { /* increment timer - exit if timed out */ current_seconds = time(NULL); - /* returns 0 bytes on timeout */ - pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); - - /* process */ - if (pdu_len) { - npdu_handler(&src, &Rx_Buf[0], pdu_len); - } /* at least one second has passed */ if (current_seconds != last_seconds) tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + if(!found){ + found = + address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); + } if (found) { if (invoke_id == 0) { invoke_id = @@ -470,6 +465,15 @@ int main(int argc, char *argv[]) { break; } } + + /* returns 0 bytes on timeout */ + pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); + + /* process */ + if (pdu_len) { + npdu_handler(&src, &Rx_Buf[0], pdu_len); + } + /* keep track of time for next check */ last_seconds = current_seconds; }