mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Add sp_drain() function.
This commit is contained in:
parent
ea34fba899
commit
69a3739ca0
@ -526,6 +526,14 @@ enum sp_return sp_write(struct sp_port *port, const void *buf, size_t count);
|
|||||||
*/
|
*/
|
||||||
enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers);
|
enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for buffered data to be transmitted.
|
||||||
|
*
|
||||||
|
* @return SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
|
||||||
|
* if an invalid port is passed.
|
||||||
|
*/
|
||||||
|
enum sp_return sp_drain(struct sp_port *port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @defgroup Errors Obtaining error information
|
* @defgroup Errors Obtaining error information
|
||||||
|
17
serialport.c
17
serialport.c
@ -535,6 +535,23 @@ enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers)
|
|||||||
return SP_OK;
|
return SP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum sp_return sp_drain(struct sp_port *port)
|
||||||
|
{
|
||||||
|
CHECK_PORT();
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
/* Returns non-zero upon success, 0 upon failure. */
|
||||||
|
if (FlushFileBuffers(port->hdl) == 0)
|
||||||
|
return SP_ERR_FAIL;
|
||||||
|
#else
|
||||||
|
/* Returns 0 upon success, -1 upon failure. */
|
||||||
|
if (tcdrain(port->fd) < 0)
|
||||||
|
return SP_ERR_FAIL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return SP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
CHECK_PORT();
|
CHECK_PORT();
|
||||||
|
Loading…
Reference in New Issue
Block a user