diff --git a/network/serial_network/HAL/NATIVE/serial_network_hal.c b/network/serial_network/HAL/NATIVE/serial_network_hal.c index ccbb9be75..5976b2de4 100644 --- a/network/serial_network/HAL/NATIVE/serial_network_hal.c +++ b/network/serial_network/HAL/NATIVE/serial_network_hal.c @@ -206,11 +206,13 @@ void SerialHAL_Init(uint8_t *rx_buffer, uint32_t buffer_size) Sleep(2); #else serial_port = open(portname, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (serial_port < 0) + while (serial_port < 0) { printf("Error opening serial port\n"); printf("Error code: %d\n", errno); - LUOS_ASSERT(0); + printf("Please connect serial device\n"); + sleep(1); + serial_port = open(portname, O_RDWR | O_NOCTTY | O_NONBLOCK); } struct termios tty; memset(&tty, 0, sizeof(tty)); @@ -344,12 +346,16 @@ void SerialHAL_Send(uint8_t *data, uint16_t size) // Wait for the buffer to be empty usleep(1000); ioctl(serial_port, TIOCOUTQ, &bytes_in_buffer); - bytesWritten = write(serial_port, &data[bytesWritten], size - bytesWritten); + bytesWritten = write(serial_port, &data[totalBytesWritten], size - totalBytesWritten); if (bytesWritten < 0) { printf("Error writing to serial port\n"); close(serial_port); - LUOS_ASSERT(0); + bytesWritten = 0; + size = 0; + totalBytesWritten = 0; + ioctl(serial_port, TIOCOUTQ, &bytes_in_buffer); + break; } else {