summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2012-06-05 22:02:04 +0200
committerLennart Weller <lhw@ring0.de>2012-06-06 09:59:39 +0200
commit27b1dce0c3b9e604409a614339e2bc3e1eef467d (patch)
tree09a4bc72ab34bbd9093593452e0d13fa5361f807
parent11310c037ee90e879ae9c0d1d69a2200030cd085 (diff)
downloadserial-barcode-scanner-27b1dce0c3b9e604409a614339e2bc3e1eef467d.tar.bz2
more error checking
-rw-r--r--device.vala20
1 files changed, 16 insertions, 4 deletions
diff --git a/device.vala b/device.vala
index 92c7022..32af831 100644
--- a/device.vala
+++ b/device.vala
@@ -113,9 +113,16 @@ public class Device {
this.byterate = rate/bits;
- io_read = new IOChannel.unix_new(fd);
- if(!(io_read.add_watch(IOCondition.IN | IOCondition.HUP, device_read) != 0)) {
- error("Could not bind IOChannel");
+ try {
+ io_read = new IOChannel.unix_new(fd);
+ io_read.set_line_term("\r\n", 2);
+ if(io_read.set_encoding("") != IOStatus.NORMAL)
+ error("Failed to set encoding");
+ if(!(io_read.add_watch(IOCondition.IN | IOCondition.HUP, device_read) != 0)) {
+ error("Could not bind IOChannel");
+ }
+ } catch(IOChannelError e) {
+ error("IOChannel: %s", e.message);
}
}
private bool device_read(IOChannel gio, IOCondition cond) {
@@ -127,7 +134,12 @@ public class Device {
stdout.printf("HUP. Do something");
try {
- ret = gio.read_line(out msg, out len, out term_char);
+ stdout.printf("trying to read message\n");
+ if((ret = gio.read_line(out msg, out len, out term_char)) != IOStatus.NORMAL) {
+ received_barcode("SCANNER RETURNED INCORRET DATA");
+ return false;
+ }
+ stdout.printf("read message\n");
msg = msg[0:(long)term_char];
if(msg.has_prefix("USER ") || msg.has_prefix("AMOUNT ")) {