summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2012-05-30 11:44:51 +0200
committerLennart Weller <lhw@ring0.de>2012-05-30 11:44:51 +0200
commit79727379cd4f561bd9c7dbe423805bf86223c276 (patch)
tree10f2ecc43e84c32330cc07517e1d754c666770bc
parent34ba5054315e3888003fc007956e67976aed08f5 (diff)
downloadserial-barcode-scanner-79727379cd4f561bd9c7dbe423805bf86223c276.tar.bz2
Revert "event based version"
Moved commit to branch for testing purposes This reverts commit 34ba5054315e3888003fc007956e67976aed08f5.
-rw-r--r--.gitignore1
-rw-r--r--device.vala46
-rw-r--r--main.vala10
3 files changed, 5 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
index 488ed8f..09f0840 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1 @@
barcode-scanner
-*.swp
diff --git a/device.vala b/device.vala
index db2857e..203e745 100644
--- a/device.vala
+++ b/device.vala
@@ -2,11 +2,8 @@ public class Device {
private Posix.termios newtio;
private Posix.termios restoretio;
public int fd=-1;
- IOChannel io_read;
public int byterate;
- public signal void received_barcode(string barcode);
-
public Device(string device, int rate, int bits, int stopbits) {
Posix.speed_t baudrate = Posix.B9600;
@@ -14,7 +11,7 @@ public class Device {
if(fd < 0) {
fd = -1;
- error("Could not open device!\n");
+ stderr.printf("Could not open device!\n");
}
Posix.tcflush(fd, Posix.TCIOFLUSH);
@@ -112,50 +109,11 @@ public class Device {
Posix.tcsetattr(fd, Posix.TCSANOW, newtio);
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");
- }
- }
- private bool device_read(IOChannel gio, IOCondition cond) {
- IOStatus ret;
- string msg;
- size_t len, term_char;
-
- if((cond & IOCondition.HUP) == IOCondition.HUP)
- stdout.printf("HUP. Do something");
-
- try {
- ret = gio.read_line(out msg, out len, out term_char);
- msg = msg[0:(long)term_char];
-
- if(msg.has_prefix("USER ") || msg.has_prefix("AMOUNT ")) {
- if(!check_code39_checksum(msg))
- received_barcode("SCANNER RETURNED INCORRECT DATA");
- else {/* remove checksum */
- msg = msg[0:-2];
- received_barcode(msg);
- }
- }
-
- }
- catch(IOChannelError e) {
- stderr.printf("IOChannel Error: %s", e.message);
- return false;
- }
- catch(ConvertError e) {
- stderr.printf("Convert Error: %s", e.message);
- return false;
- }
- return true;
}
-#if 0
private ssize_t read(void *buf, size_t count) {
return Posix.read(fd, buf, count);
}
-#endif
private ssize_t write(void *buf, size_t count) {
ssize_t size = Posix.write(fd, buf, count);
@@ -163,7 +121,6 @@ public class Device {
return size;
}
-#if 0
public string receive() {
char[] detected = {};
char buf[64];
@@ -201,7 +158,6 @@ public class Device {
}
}
}
-#endif
private bool check_code39_checksum(string data) {
int result = 0;
diff --git a/main.vala b/main.vala
index b570b23..bbe91d7 100644
--- a/main.vala
+++ b/main.vala
@@ -10,13 +10,11 @@ public static int main(string[] args) {
dev = new Device(args[1], 9600, 8, 1);
db = new Database("shop.db");
- dev.received_barcode.connect((data) => {
- if(interpret(data))
+ while(true) {
+ string message = dev.receive();
+ if(interpret((string) message))
dev.blink(10);
- });
-
- new MainLoop(null, false).run();
- return 0;
+ }
}
public static bool interpret(string data) {