#include <string.h>
#include <stdio.h>
#include <termios.h>

int main(){
	struct termios sTermios;
	static char *device="/dev/ttyS0";
	static int  dev_fd = -1;
	dev_fd = open (device, 0);
	if (cfsetspeed(&sTermios, 38400)){
		printf("Konnte Baud-Rate nicht setzen\n");
		return -1;
	}
	sTermios.c_iflag = INPCK;
	sTermios.c_cflag = CLOCAL | CREAD | CSTOPB | PARENB | PARODD | CSIZE | CS8;
	if (tcsetattr (dev_fd, TCSANOW, &sTermios)){
		printf("Konnte Einstellungen nicht anwenden!\n");
		return -1;
	}
	unsigned int buffer=0;
	unsigned char c = 0;
	while(read(dev_fd, &buffer, 2)){
		printf("%10u ", buffer);
		if (++c % 4 == 0){
			printf("\n");
		}
		if (c % 16 == 0){
			printf("\n");
			c = 0;
		}
	}
	
	close (dev_fd);
	return 0;
}
