]> git.defcon.no Git - hm-trp-tool/blob - serial.c
I forgot, all source needs README and licensing
[hm-trp-tool] / serial.c
1 #include "serial.h"
2
3 int open_port ( char* device, int rate )
4 {
5 int f;
6 struct termios tio;
7
8 f = open ( device, O_RDWR | O_NOCTTY ); // Not using O_NDELAY, that caused ERR11: temp unavail.
9 if ( f < 0 )
10 {
11 return(-1);
12 }
13
14 tio.c_cflag = rate | CS8 | CLOCAL | CREAD;
15
16 // 8 bits, local mode, read enabled
17 tio.c_cflag |= CS8 | CLOCAL | CREAD;
18
19 // no flow-control,
20 tio.c_cflag &= ~CRTSCTS;
21
22 // no parity
23 tio.c_iflag = IGNPAR;
24
25 tio.c_oflag = 0;
26 tio.c_lflag = 0; // Non-canonical read, no other options.
27 tio.c_cc[VMIN] = 0; // Disable minimum characters for read
28 tio.c_cc[VTIME] = 5; // Wait for a max of 0.5 second
29
30 tcsetattr(f,TCSANOW,&tio); // Apply this now.
31
32 tcflush(f, TCIFLUSH); // the serial input buffer.
33
34 return f;
35 }