From: Martin Ling Date: Thu, 14 Nov 2013 22:01:11 +0000 (+0000) Subject: Add functions for setting individual port parameters. X-Git-Tag: libserialport-0.1.0~119 X-Git-Url: https://sigrok.org/gitweb/?p=libserialport.git;a=commitdiff_plain;h=9069c2fbb2f4b9f07e1bf9729e61044c65e09027 Add functions for setting individual port parameters. --- diff --git a/libserialport.h.in b/libserialport.h.in index e410dad..f58530c 100644 --- a/libserialport.h.in +++ b/libserialport.h.in @@ -143,6 +143,15 @@ int sp_flush(struct sp_port *port); int sp_write(struct sp_port *port, const void *buf, size_t count); int sp_read(struct sp_port *port, void *buf, size_t count); int sp_set_config(struct sp_port *port, struct sp_port_config *config); +int sp_set_baudrate(struct sp_port *port, int baudrate); +int sp_set_bits(struct sp_port *port, int bits); +int sp_set_parity(struct sp_port *port, int parity); +int sp_set_stopbits(struct sp_port *port, int stopbits); +int sp_set_rts(struct sp_port *port, int rts); +int sp_set_cts(struct sp_port *port, int cts); +int sp_set_dtr(struct sp_port *port, int dtr); +int sp_set_dsr(struct sp_port *port, int dsr); +int sp_set_xon_xoff(struct sp_port *port, int xon_xoff); int sp_last_error_code(void); char *sp_last_error_message(void); void sp_free_error_message(char *message); diff --git a/serialport.c b/serialport.c index 418d48b..6a6e305 100644 --- a/serialport.c +++ b/serialport.c @@ -961,6 +961,24 @@ int sp_set_config(struct sp_port *port, struct sp_port_config *config) return SP_OK; } +#define CREATE_SETTER(x) int sp_set_##x(struct sp_port *port, int x) { \ + struct sp_port_data data; \ + TRY(start_config(port, &data)); \ + TRY(set_##x(&data, x)); \ + TRY(apply_config(port, &data)); \ + return SP_OK; \ +} + +CREATE_SETTER(baudrate) +CREATE_SETTER(bits) +CREATE_SETTER(parity) +CREATE_SETTER(stopbits) +CREATE_SETTER(rts) +CREATE_SETTER(cts) +CREATE_SETTER(dtr) +CREATE_SETTER(dsr) +CREATE_SETTER(xon_xoff) + int sp_last_error_code(void) { #ifdef _WIN32