summaryrefslogtreecommitdiff
path: root/i/serialplot/serialplot_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'i/serialplot/serialplot_io.c')
-rw-r--r--i/serialplot/serialplot_io.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/i/serialplot/serialplot_io.c b/i/serialplot/serialplot_io.c
new file mode 100644
index 0000000..fa45433
--- /dev/null
+++ b/i/serialplot/serialplot_io.c
@@ -0,0 +1,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+"));
+}