diff --git a/contrib/win32/libnfc/buses/uart.c b/contrib/win32/libnfc/buses/uart.c index 2a68be0..f0bbe78 100644 --- a/contrib/win32/libnfc/buses/uart.c +++ b/contrib/win32/libnfc/buses/uart.c @@ -237,7 +237,7 @@ uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) } if (!dwTxLen) return NFC_EIO; - return 0; + return NFC_SUCCESS; } /** @@ -249,17 +249,21 @@ int uart_send_single(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) { (void) timeout; - int error = 0; + int ret; for (int i = 0; i < szTx; i++) { - error |= uart_send(sp, pbtTx+i, 1, timeout); + ret = uart_send(sp, pbtTx+i, 1, timeout); + + // if we didn't transmit byte, bail out + if (ret != NFC_SUCCESS) + return ret; + delay_ms(1); // ceil(1_000_000us / 115200baud) = 9us but no usleep on windows } - return error ? NFC_EIO : 0; + return NFC_SUCCESS; } - BOOL is_port_available(int nPort) { TCHAR szPort[15]; diff --git a/libnfc/buses/uart.c b/libnfc/buses/uart.c index 62f0f01..e4d34c0 100644 --- a/libnfc/buses/uart.c +++ b/libnfc/buses/uart.c @@ -384,26 +384,6 @@ select: return NFC_SUCCESS; } -/** - * @brief Send \a pbtTx content to UART one byte at a time - * - * @return 0 on success, otherwise a driver error is returned - */ -int -uart_send_single(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) -{ - (void) timeout; - int error = 0; - for (int i = 0; i < szTx; i++) - { - error |= uart_send(sp, pbtTx+i, 1, timeout); - usleep(9); - } - - - return error ? NFC_EIO : NFC_SUCCESS; -} - /** * @brief Send \a pbtTx content to UART * @@ -420,6 +400,30 @@ uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) return NFC_EIO; } +/** + * @brief Send \a pbtTx content to UART one byte at a time + * + * @return 0 on success, otherwise a driver error is returned + */ +int +uart_send_single(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout) +{ + (void) timeout; + int ret; + for (int i = 0; i < szTx; i++) + { + ret = uart_send(sp, pbtTx+i, 1, timeout); + + // if we didn't transmit byte, bail out + if (ret != NFC_SUCCESS) + return ret; + + usleep(9); // sleep for ceil(1_000_000us / 115200baud) = 9us + } + + return NFC_SUCCESS; +} + char ** uart_list_ports(void) {