1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

Use negative values in sp_port_config to retain existing settings.

This commit is contained in:
Martin Ling 2013-11-14 19:45:42 +00:00
parent d1202734fb
commit a46f0960a2

View File

@ -745,12 +745,10 @@ static int set_flowcontrol(struct sp_port_data *data, int flowcontrol)
static int set_rts(struct sp_port_data *data, int rts) static int set_rts(struct sp_port_data *data, int rts)
{ {
#ifdef _WIN32 #ifdef _WIN32
if (rts != -1) {
if (rts) if (rts)
data->dcb.fRtsControl = RTS_CONTROL_ENABLE; data->dcb.fRtsControl = RTS_CONTROL_ENABLE;
else else
data->dcb.fRtsControl = RTS_CONTROL_DISABLE; data->dcb.fRtsControl = RTS_CONTROL_DISABLE;
}
#else #else
data->rts = rts; data->rts = rts;
#endif #endif
@ -760,12 +758,10 @@ static int set_rts(struct sp_port_data *data, int rts)
static int set_dtr(struct sp_port_data *data, int dtr) static int set_dtr(struct sp_port_data *data, int dtr)
{ {
#ifdef _WIN32 #ifdef _WIN32
if (dtr != -1) {
if (dtr) if (dtr)
data->dcb.fDtrControl = DTR_CONTROL_ENABLE; data->dcb.fDtrControl = DTR_CONTROL_ENABLE;
else else
data->dcb.fDtrControl = DTR_CONTROL_DISABLE; data->dcb.fDtrControl = DTR_CONTROL_DISABLE;
}
#else #else
data->dtr = dtr; data->dtr = dtr;
#endif #endif
@ -820,19 +816,20 @@ static int apply_config(struct sp_port *port, struct sp_port_data *data)
} }
#define TRY(x) do { int ret = x; if (ret != SP_OK) return ret; } while (0) #define TRY(x) do { int ret = x; if (ret != SP_OK) return ret; } while (0)
#define TRY_SET(x) do { if (config->x >= 0) TRY(set_##x(&data, config->x)); } while (0)
int sp_set_config(struct sp_port *port, struct sp_port_config *config) int sp_set_config(struct sp_port *port, struct sp_port_config *config)
{ {
struct sp_port_data data; struct sp_port_data data;
TRY(start_config(port, &data)); TRY(start_config(port, &data));
TRY(set_baudrate(&data, config->baudrate)); TRY_SET(baudrate);
TRY(set_bits(&data, config->bits)); TRY_SET(bits);
TRY(set_parity(&data, config->parity)); TRY_SET(parity);
TRY(set_stopbits(&data, config->stopbits)); TRY_SET(stopbits);
TRY(set_flowcontrol(&data, config->flowcontrol)); TRY_SET(flowcontrol);
TRY(set_rts(&data, config->rts)); TRY_SET(rts);
TRY(set_dtr(&data, config->dtr)); TRY_SET(dtr);
TRY(apply_config(port, &data)); TRY(apply_config(port, &data));
return SP_OK; return SP_OK;