1bedea334195b8728780e4245d56fb5905469647
1 /* Simple program to load paper tape over serial port. Does that twice and compares. */
12 struct termios orgstate
;
13 struct termios workstate
;
15 #define PORT_FILE "/dev/ttyS0"
16 #define BUFFER_SIZE 1000000
19 int sp
, ep
, count
, portfd
;
21 void sighandler(int sig
){
25 // fprintf(stderr,"%i %i\n", sp, ep);
27 while(buffer
[sp
]==0) sp
++;
28 while(buffer
[ep
]==0) ep
--;
31 write(1,buffer
+sp
,ep
-sp
+1);
33 fprintf(stderr
,"Eingelesen: %i\n",ep
-sp
+1);
34 tcsetattr(portfd
, TCSANOW
, &orgstate
);
39 int main (int argc
, char ** argv
){
41 portfd
=open(PORT_FILE
, O_RDWR
);
42 tcgetattr(portfd
, &orgstate
);
43 tcgetattr(portfd
, &workstate
);
44 cfmakeraw(&workstate
);
45 // workstate.c_oflag=0;
46 workstate
.c_cflag
|=CS8
+CREAD
+CLOCAL
+CRTSCTS
+CSTOPB
;
47 // workstate.c_lflag=0;
48 cfsetspeed(&workstate
, B4800
);
49 tcsetattr(portfd
, TCSANOW
, &workstate
);
52 signal(SIGINT
, sighandler
);
53 buffer
=(char *) malloc(BUFFER_SIZE
);
54 fprintf(stderr
, "Warte auf Daten. Einspielen und dann CTRL-C drücken.\n");
57 int erg
=read(portfd
, buffer
+count
, 1);
58 if (erg
>0) count
+=erg
;