From: Uwe Hermann Date: Tue, 17 Dec 2013 16:46:24 +0000 (+0100) Subject: serial.c: Show both error code and error message. X-Git-Tag: libsigrok-0.3.0~428 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=cb7b165b3dc073c49729173132a37203e9d98838;p=libsigrok.git serial.c: Show both error code and error message. This is helpful in many cases, e.g. when trying to identify which of the 16000 system error codes from http://msdn.microsoft.com/en-us/library/ms681381%28VS.85%29.aspx has been encountered (which is not trivial if you only have an, e.g. German, string message alone). --- diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 9727ce8a..0d26b464 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -77,7 +77,8 @@ SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags) return SR_ERR_ARG; case SP_ERR_FAIL: error = sp_last_error_message(); - sr_err("Error opening port: %s.", error); + sr_err("Error opening port (%d): %s.", + sp_last_error_code(), error); sp_free_error_message(error); return SR_ERR; } @@ -120,7 +121,8 @@ SR_PRIV int serial_close(struct sr_serial_dev_inst *serial) return SR_ERR_ARG; case SP_ERR_FAIL: error = sp_last_error_message(); - sr_err("Error closing port: %s.", error); + sr_err("Error closing port (%d): %s.", + sp_last_error_code(), error); sp_free_error_message(error); return SR_ERR; } @@ -163,7 +165,8 @@ SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial) return SR_ERR_ARG; case SP_ERR_FAIL: error = sp_last_error_message(); - sr_err("Error flushing port: %s.", error); + sr_err("Error flushing port (%d): %s.", + sp_last_error_code(), error); sp_free_error_message(error); return SR_ERR; } @@ -207,7 +210,7 @@ SR_PRIV int serial_write(struct sr_serial_dev_inst *serial, return SR_ERR_ARG; case SP_ERR_FAIL: error = sp_last_error_message(); - sr_err("Write error: %s.", error); + sr_err("Write error (%d): %s.", sp_last_error_code(), error); sp_free_error_message(error); return SR_ERR; } @@ -253,7 +256,7 @@ SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf, return SR_ERR_ARG; case SP_ERR_FAIL: error = sp_last_error_message(); - sr_err("Read error: %s.", error); + sr_err("Read error (%d): %s.", sp_last_error_code(), error); sp_free_error_message(error); return SR_ERR; } @@ -332,7 +335,8 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, return SR_ERR_ARG; case SP_ERR_FAIL: error = sp_last_error_message(); - sr_err("Error setting serial port parameters: %s.", error); + sr_err("Error setting serial port parameters (%d): %s.", + sp_last_error_code(), error); sp_free_error_message(error); return SR_ERR; }