mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Make sp_flush take an option for what to flush.
This commit is contained in:
parent
a036341bdf
commit
fd8fd11a4e
@ -109,6 +109,16 @@ enum sp_mode {
|
|||||||
SP_MODE_NONBLOCK = 4,
|
SP_MODE_NONBLOCK = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Buffer selection. */
|
||||||
|
enum sp_buffer {
|
||||||
|
/** Input buffer. */
|
||||||
|
SP_BUF_INPUT = 1,
|
||||||
|
/** Output buffer. */
|
||||||
|
SP_BUF_OUTPUT = 2,
|
||||||
|
/** Both buffers. */
|
||||||
|
SP_BUF_BOTH = 3,
|
||||||
|
};
|
||||||
|
|
||||||
/** Parity settings. */
|
/** Parity settings. */
|
||||||
enum sp_parity {
|
enum sp_parity {
|
||||||
/** Special value to indicate setting should be left alone. */
|
/** Special value to indicate setting should be left alone. */
|
||||||
@ -506,12 +516,14 @@ enum sp_return sp_read(struct sp_port *port, void *buf, size_t count);
|
|||||||
enum sp_return sp_write(struct sp_port *port, const void *buf, size_t count);
|
enum sp_return sp_write(struct sp_port *port, const void *buf, size_t count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush serial port buffers.
|
* Flush serial port buffers. Data in the selected buffer(s) is discarded.
|
||||||
|
*
|
||||||
|
* @param buffers Which buffer(s) to flush.
|
||||||
*
|
*
|
||||||
* @return SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
|
* @return SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
|
||||||
* if an invalid port is passed.
|
* if an invalid port is passed.
|
||||||
*/
|
*/
|
||||||
enum sp_return sp_flush(struct sp_port *port);
|
enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
20
serialport.c
20
serialport.c
@ -505,17 +505,31 @@ enum sp_return sp_close(struct sp_port *port)
|
|||||||
return SP_OK;
|
return SP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum sp_return sp_flush(struct sp_port *port)
|
enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers)
|
||||||
{
|
{
|
||||||
CHECK_PORT();
|
CHECK_PORT();
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
DWORD flags = 0;
|
||||||
|
if (buffers & SP_BUF_INPUT)
|
||||||
|
flags |= PURGE_RXCLEAR;
|
||||||
|
if (buffers & SP_BUF_OUTPUT)
|
||||||
|
flags |= PURGE_TXCLEAR;
|
||||||
|
|
||||||
/* Returns non-zero upon success, 0 upon failure. */
|
/* Returns non-zero upon success, 0 upon failure. */
|
||||||
if (PurgeComm(port->hdl, PURGE_RXCLEAR | PURGE_TXCLEAR) == 0)
|
if (PurgeComm(port->hdl, flags) == 0)
|
||||||
return SP_ERR_FAIL;
|
return SP_ERR_FAIL;
|
||||||
#else
|
#else
|
||||||
|
int flags = 0;
|
||||||
|
if (buffers & SP_BUF_BOTH)
|
||||||
|
flags = TCIOFLUSH;
|
||||||
|
else if (buffers & SP_BUF_INPUT)
|
||||||
|
flags = TCIFLUSH;
|
||||||
|
if (buffers & SP_BUF_OUTPUT)
|
||||||
|
flags = TCOFLUSH;
|
||||||
|
|
||||||
/* Returns 0 upon success, -1 upon failure. */
|
/* Returns 0 upon success, -1 upon failure. */
|
||||||
if (tcflush(port->fd, TCIOFLUSH) < 0)
|
if (tcflush(port->fd, flags) < 0)
|
||||||
return SP_ERR_FAIL;
|
return SP_ERR_FAIL;
|
||||||
#endif
|
#endif
|
||||||
return SP_OK;
|
return SP_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user