diff options
-rw-r--r-- | device.vala | 20 |
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 ")) { |