From: Martin Ling Date: Wed, 20 Nov 2013 18:11:17 +0000 (+0000) Subject: Add sp_start_break() and sp_end_break() functions. X-Git-Tag: libserialport-0.1.0~83 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=90cc3ee62b267ba5009fddd72f63b411ad466faa;p=libserialport.git Add sp_start_break() and sp_end_break() functions. --- diff --git a/libserialport.h.in b/libserialport.h.in index 79f315f..704ffed 100644 --- a/libserialport.h.in +++ b/libserialport.h.in @@ -534,6 +534,28 @@ enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers); */ enum sp_return sp_drain(struct sp_port *port); +/** + * @} + * @defgroup Signal Port signalling operations + * @{ + */ + +/** + * Put the port transmit line into the break state. + * + * @return SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG + * if an invalid port is passed. + */ +enum sp_return sp_start_break(struct sp_port *port); + +/** + * Take the port transmit line out of the break state. + * + * @return SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG + * if an invalid port is passed. + */ +enum sp_return sp_end_break(struct sp_port *port); + /** * @} * @defgroup Errors Obtaining error information diff --git a/serialport.c b/serialport.c index 6104f24..ab1baa7 100644 --- a/serialport.c +++ b/serialport.c @@ -1298,6 +1298,34 @@ enum sp_return sp_set_flowcontrol(struct sp_port *port, enum sp_flowcontrol flow return SP_OK; } +enum sp_return sp_start_break(struct sp_port *port) +{ + CHECK_PORT(); +#ifdef _WIN32 + if (SetCommBreak(port->hdl) == 0) + return SP_ERR_FAIL; +#else + if (ioctl(port->fd, TIOCSBRK, 1) < 0) + return SP_ERR_FAIL; +#endif + + return SP_OK; +} + +enum sp_return sp_end_break(struct sp_port *port) +{ + CHECK_PORT(); +#ifdef _WIN32 + if (ClearCommBreak(port->hdl) == 0) + return SP_ERR_FAIL; +#else + if (ioctl(port->fd, TIOCCBRK, 1) < 0) + return SP_ERR_FAIL; +#endif + + return SP_OK; +} + int sp_last_error_code(void) { #ifdef _WIN32