summaryrefslogtreecommitdiff
path: root/i/serialplot/serialplot_io.c
blob: fa454337c85f16dab1864544d8928302a6d0f65a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "serialplot_io.h"

int
init_serial(char *cvalue)
{
	int fd_ttyS;
	struct termios newtio;
	if ( (fd_ttyS=open(cvalue,O_RDWR )) < 0 ) {
		perror("serial port couldn't be open");
		exit(-1);
	}	

	tcgetattr(fd_ttyS,&oldconf); /* sauvegarde de la configuration courante */
	bzero(&newtio, sizeof(newtio)); /* on initialise la structure � z�ro */
	/*
	 * ICRNL convertie CR en NL en entr�e sauf si IGNCR est indiqu�
	 * Valide la v�rification de parit� en entr�
	*/
	newtio.c_iflag = ICRNL | INPCK ;
	/*
	 * BAUDRATE  115200 Baud
	 * CS8 Longeur des caract�res
	 * CLOCAL Ignore les signaux de controle du modem
	 * CREAD Valider la reception
	 * PARENB Valider le codage de parti� en sortie et la v�rification
	 * de parit� en entr�e
	*/	
	newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD | PARENB ;
	/*
	 * Traitement des caract�res de sortie, ici aucun.
	*/
	newtio.c_oflag = 0;
	/*
	 * Mode canonique (permet l'utilisation des caract�res speciaux)
	*/
	newtio.c_lflag = ICANON;
	tcflush(fd_ttyS, TCIFLUSH);
	tcsetattr(fd_ttyS,TCSANOW,&newtio);
	return fd_ttyS;
}

void
close_serial(int fd)
{	
	tcsetattr(fd,TCSANOW,&oldconf);
	close(fd);
}

int
write_serial(int fd,char *command)
{
	return fputs(command,fdopen(fd,"r+"));	
}