[PATCH 2/4] Cochran: Added check to ensure high baud rate setting worked.

John Van Ostrand john at vanostrand.com
Wed Nov 19 12:11:39 PST 2014


---
 src/cochran_commander.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/cochran_commander.c b/src/cochran_commander.c
index fdcac67..fdb1390 100644
--- a/src/cochran_commander.c
+++ b/src/cochran_commander.c
@@ -61,6 +61,7 @@ cochran_packet (cochran_device_t *device, const unsigned char command[],
 	dc_device_t *abstract = (dc_device_t *) device;
 	unsigned int bytes_read = 0, n, read_size;
 	unsigned int ptr;
+	int rc;
 
 	if (device_is_cancelled (abstract))
 		return DC_STATUS_CANCELLED;
@@ -80,10 +81,21 @@ cochran_packet (cochran_device_t *device, const unsigned char command[],
 
 		// Weird but I only get the right result when I do it twice
 		// Rates are odd, like 825600 for the EMC, 115200 for commander
-		serial_configure(device->port, device->data.conf.high_baud, 8,
+		rc = serial_configure(device->port, device->data.conf.high_baud, 8,
 						SERIAL_PARITY_NONE, 2, SERIAL_FLOWCONTROL_NONE);
-		serial_configure(device->port, device->data.conf.high_baud, 8,
+		if (rc == -1) {
+			ERROR (abstract->context, "Failed to set the high baud rate.");
+			free (device);
+			return DC_STATUS_IO;
+		}
+
+		rc = serial_configure(device->port, device->data.conf.high_baud, 8,
 						SERIAL_PARITY_NONE, 2, SERIAL_FLOWCONTROL_NONE);
+		if (rc == -1) {
+			ERROR (abstract->context, "Failed to set the high baud rate.");
+			free (device);
+			return DC_STATUS_IO;
+		}
 	}
 
 	// Receive the answer from the device.
-- 
1.8.3.1



More information about the devel mailing list