# HG changeset patch # User jeandet # Date 2014-04-01 18:04:21 # Node ID 5dbc0917d8e7a384a990a42215d2770caa61a8e3 # Parent 8a61222fe7d90e7414a77c6f4be1730e459217c8 Added int rs232availablebytes(rs232port_t fd); in API. Only tested on Linux yet. diff --git a/src/RS232.h b/src/RS232.h --- a/src/RS232.h +++ b/src/RS232.h @@ -33,6 +33,7 @@ rs232extern int rs232close(rs232port_t f rs232extern int rs232setup(rs232port_t fd, int ChSize, int BaudeRate, rs232parity Parity, rs232stop NbStop); rs232extern int rs232write(rs232port_t fd,char *psWrite, int WriteBufferSize); rs232extern int rs232read(rs232port_t fd,char *psRead, int ReadBufferSize); +rs232extern int rs232availablebytes(rs232port_t fd); rs232extern int rs232setparity(rs232port_t fd, rs232parity Parity); rs232extern int rs232setnbstop(rs232port_t fd, rs232stop NbStop); rs232extern int rs232setcsize(rs232port_t fd, int ChSize); diff --git a/src/RS232_unix.c b/src/RS232_unix.c --- a/src/RS232_unix.c +++ b/src/RS232_unix.c @@ -425,6 +425,12 @@ int rs232write(rs232port_t fd,char *psWr } } +int rs232availablebytes(rs232port_t fd) +{ + int bytes; + ioctl(fd, FIONREAD, &bytes); + return bytes; +} int rs232read(rs232port_t fd,char *psReadHex, int ReadBufferSize) { diff --git a/src/RS232_win.c b/src/RS232_win.c --- a/src/RS232_win.c +++ b/src/RS232_win.c @@ -322,6 +322,13 @@ int rs232read(rs232port_t fd,char *psRea } +int rs232availablebytes(rs232port_t fd) +{ + DWORD dwErrorFlags; + COMSTAT ComStat; + ClearCommError(m_hIDComDev, &dwErrorFlags, &ComStat); + return((int)ComStat.cbInQue); +} int rs232saferead(rs232port_t fd,char* data,int count ) {