[prev in list] [next in list] [prev in thread] [next in thread]
List: mandrake-confirme
Subject: Re: [Confirme] =?iso-8859-15?q?acc=E8s=20port?= =?iso-8859-15?q?=20s=E9rie?=
From: dt <daniel.tartavel () free ! fr>
Date: 2004-02-29 17:32:03
Message-ID: 200402291732.08625.daniel.tartavel () free ! fr
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Le Jeudi 19 Février 2004 20:11, cc a écrit :
> savez-vous comment accéder à un port série en lecture et écriture (en C
> ou en pascal de préférence) ?
> peut-on simplement utiliser le /dev/ttysn ?
> le but : envoyer une commande à un modem et récupérer le résultat.
si cela peut servir
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAQiIYjtvATHfO/FwRAtvJAJ0YdrPHOL4iu/jdv7Ea3FCQ8fZmagCdHZoA
UnWQqFEakTvJTIggomzKNhs=
=5YJh
-----END PGP SIGNATURE-----
["init_modem.cpp" (text/x-c++src)]
/***************************************************************************
init_modem.cpp - description
-------------------
begin : mar jan 20 2004
copyright : (C) 2004 by DTux
email : DTux@free.fr
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdlib.h>
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <time.h> //date and time
#include <ctype.h>
#include "olitec.h" /* classes declarations */
char initstring[]={"AT&F&K3E0#CLS=8\r"}; //+VCID=1 &F&K3E0#CLS=8+FCLASS=0
extern struct termios oldio;
int open_port(void)
{
int fd; /* File descriptor for the port */
struct termios options;
printf("opening modem port\n");
fd = open("/dev/modem", O_RDWR | O_NOCTTY | O_NDELAY); // | O_NDELAY); // | O_SYNC);
if (fd == -1)
{
// Could not open the port.
perror("open_port: Unable to open /dev/modem - ");
}
else
//fcntl(fd, F_SETFL, 0);
// Get the current options for the port...
tcgetattr(fd, &oldio);
bzero(&options, sizeof(options));
// * Set the baud rates to 115200...
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
// set raw input, 1 second timeout
options.c_cflag |= (CS8 | CLOCAL | CREAD | CRTSCTS); // | HUPCL);
//options.c_cflag &= ~(PARENB | PARODD | CSTOPB );
options.c_iflag = (IGNBRK | IGNPAR); // | ISTRIP);
options.c_lflag = 0; //ICANON ; //| ECHO | ECHOE | ISIG);
options.c_oflag = 0; //OPOST;
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 10;
/*options.c_cc[VINTR] = 0; // Ctrl-c
options.c_cc[VQUIT] = 0; // Ctrl-\
options.c_cc[VERASE] = 0; // del
options.c_cc[VKILL] = 0; // @
options.c_cc[VEOF] = 4; // Ctrl-d
options.c_cc[VSWTC] = 0; // '\0'
options.c_cc[VSTART] = 0; // Ctrl-q
options.c_cc[VSTOP] = 0; // Ctrl-s
options.c_cc[VSUSP] = 0; // Ctrl-z
options.c_cc[VEOL] = 0; // '\0'
options.c_cc[VREPRINT] = 0; //Ctrl-r
options.c_cc[VDISCARD] = 0; // Ctrl-u
options.c_cc[VWERASE] = 0; // Ctrl-w
options.c_cc[VLNEXT] = 0; // Ctrl-v
options.c_cc[VEOL2] = 0; // '\0'
*/
tcflush(fd, TCIFLUSH);
// * Set the new options for the port...
tcsetattr(fd, TCSANOW, &options);
return (fd);
}
/* O - 0 = MODEM ok, -1 = MODEM bad */
int init_modem(int fd) /* I - Serial port file */
{
unsigned char buffer[255]; /* Input buffer */
unsigned char *bufptr; /* Current char in buffer */
int nbytes; /* Number of bytes read */
int tries; /* Number of tries so far */
int nb;
int len;
printf("Initializing modem\n");
for (tries = 0; tries < 3; tries ++)
{
/* send an AT command followed by a CR */
//if (write(fd, "ATZ\r",4) < 4)
// continue;
//sleep(2);
len=strlen(initstring);
nb=write(fd, initstring, len); //&FE0&K3B0
if (nb==-1) continue;
sleep(1);
/* read characters into our string buffer until we get a CR or NL */
bufptr = buffer;
//fcntl(fd, F_SETFL, FNDELAY);
nbytes = read_modem(fd, bufptr, 255);
//nbytes=read(fd,bufptr,sizeof(buffer));
//fcntl(fd, F_SETFL, 0);
/* null terminate the string and see if we got an OK response */
//*bufptr = '\0';
//read(fd,buffer,255);
printf("%d %d %s\n",nbytes,fd,buffer);
if (strstr((char *)buffer, "OK") != 0) return (-1);
}
return (0);
}
["message.footer" (text/plain)]
=========================================
Vous souhaitez acquerir votre Pack ou des Services MandrakeSoft?
Rendez-vous sur "http://www.mandrakestore.com".
Foire Aux Questions de la liste : http://mdk.mondelinux.org
Rejoignez le club mandrake : http://www.mandrakeclub.com
=========================================
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic