From 78ebac8e6f08fba865a521733ae2803028ad2e0f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Oct 2017 11:35:34 +0200 Subject: [PATCH] chg: more debug... --- uart/uart_posix.c | 9 +++------ uart/uart_win32.c | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/uart/uart_posix.c b/uart/uart_posix.c index a608006e1..cb13aaf4a 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -125,9 +125,6 @@ serial_port uart_open(const char* pcPortName) } void uart_close(const serial_port sp) { -// if (sp == INVALID_SERIAL_PORT) return; -// if (sp == CLAIMED_SERIAL_PORT) return; - serial_port_unix* spu = (serial_port_unix*)sp; tcflush(spu->fd, TCIOFLUSH); tcsetattr(spu->fd, TCSANOW, &(spu->tiOld)); @@ -221,13 +218,13 @@ bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen) // Write error if (res < 0) { - printf("UART:: write error\n"); + printf("UART:: write error (%d)\n", res); return false; } // Write time-out if (res == 0) { - printf("UART:: write time-out\n"); + printf("UART:: write time-out (%d)\n", res); return false; } @@ -236,7 +233,7 @@ bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen) // Stop if the OS has some troubles sending the data if (res <= 0) { - printf("UART:: os troubles\n"); + printf("UART:: os troubles (%d)\n", res); return false; } diff --git a/uart/uart_win32.c b/uart/uart_win32.c index 955e6c3a7..521a3895c 100644 --- a/uart/uart_win32.c +++ b/uart/uart_win32.c @@ -111,25 +111,24 @@ serial_port uart_open(const char* pcPortName) { } void uart_close(const serial_port sp) { -// if (!sp) return; -// if (sp == INVALID_SERIAL_PORT) return; -// if (sp == CLAIMED_SERIAL_PORT) return; if (((serial_port_windows*)sp)->hPort != INVALID_HANDLE_VALUE ) CloseHandle(((serial_port_windows*)sp)->hPort); free(sp); } -bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t pszMaxRxLen, size_t* pszRxLen) { - ReadFile(((serial_port_windows*)sp)->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL); - return (*pszRxLen != 0); +bool uart_receive(const serial_port sp, byte_t* p_rx, size_t pszMaxRxLen, size_t* p_rxlen) { + ReadFile(((serial_port_windows*)sp)->hPort, p_rx, pszMaxRxLen, (LPDWORD)p_rxlen, NULL); + return (*p_rxlen != 0); } -bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen) { - DWORD dwTxLen = 0; - if ( !WriteFile(((serial_port_windows*)sp)->hPort, pbtTx, szTxLen, &dwTxLen, NULL) ) { +bool uart_send(const serial_port sp, const byte_t* p_tx, const size_t len) { + DWORD txlen = 0; + bool res = WriteFile(((serial_port_windows*)sp)->hPort, p_tx, len, &txlen, NULL); + if ( !res ) return false; - } - return (dwTxLen != 0); + + printf("TX %u\n", txlen); + return (txlen != 0); } bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {