summaryrefslogtreecommitdiffstats
path: root/main.vala
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-04-28 18:59:33 +0200
committerSebastian Reichel <sre@ring0.de>2012-04-28 18:59:33 +0200
commit697d92d00cc020cadd00d2c67ac77f6109eeb16e (patch)
treec416d54d217b62aeb546c6286b1b4b4634d68fea /main.vala
downloadserial-barcode-scanner-697d92d00cc020cadd00d2c67ac77f6109eeb16e.tar.bz2
initial code import
Diffstat (limited to 'main.vala')
-rw-r--r--main.vala30
1 files changed, 30 insertions, 0 deletions
diff --git a/main.vala b/main.vala
new file mode 100644
index 0000000..bd71163
--- /dev/null
+++ b/main.vala
@@ -0,0 +1,30 @@
+public static int main(string[] args) {
+ if(args.length < 2) {
+ stderr.printf("%s <device>\n", args[0]);
+ return 1;
+ }
+
+ var s = new Serial(args[1], 19200, 7, 1);
+
+ char[] detected = {};
+
+ while(true) {
+ uint8 buf[64];
+ int size = (int) Posix.read(s.fd, buf, 64);
+
+ for(int i = 0; i < size; i++)
+ if(buf[i] != '\r' && buf[i] != '\n') {
+ detected += (char) buf[i];
+ } else {
+ if(detected.length > 0) {
+ detected += '\0';
+ interpret(detected);
+ }
+ detected = {};
+ }
+ }
+}
+
+public static void interpret(char[] data) {
+ stdout.printf("%s\n", (string) data);
+}