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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <termios.h>
#include <time.h>
#include <locale.h>
#include <string.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
using namespace std;
int SignalRecu;
void rien()
{
SignalRecu=1;
}
int main(int argc, char* argv[])
{
setlocale( LC_NUMERIC, "" );
struct termios oldtio,newtio;
int taille, lg;
char DemandeSerial[6];
int fd;
unsigned char Serial[20];
fd = open ("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY );
if (fd < 0)
{
printf ("Erreur ouverture port\n");
exit (EXIT_FAILURE);
}
else
{
printf ("Ouverture COM reussie\n");
}
tcgetattr(fd,&oldtio);
newtio.c_cflag = B230400 | CS8 | CREAD;
//newtio.c_lflag = ECHO;
newtio.c_oflag = OFDEL;
newtio.c_lflag = CSTOPB ;
newtio.c_cc[VMIN] = 1;
newtio.c_cc[VTIME] = 0;
newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag = 0;
tcsetattr(fd,TCSANOW,&newtio);
SignalRecu = 0;
while(SignalRecu==0)
{
DemandeSerial[0]='A';
DemandeSerial[1]='T';
DemandeSerial[2]='+';
DemandeSerial[3]='G';
DemandeSerial[4]='S';
DemandeSerial[5]='N';
lg = write (fd, DemandeSerial, 6);
if (lg < 0 )
{
printf ("Erreur ecriture port\n");
printf("%d\n",lg);
}
else
{
printf ("Demande Serial reussie\n");
}
taille = read(fd, Serial, sizeof(&Serial));
if (taille<0)
{
printf ("Erreur Lecture Serial IMEI\n");
//exit (EXIT_FAILURE);
}
else
{
int i = 0;
for (Serial[i]; i < sizeof(Serial); i++)
{
printf ("%d\n", Serial[i]);
SignalRecu=1;
}
//printf ("\r\n");
}
}
if(close(fd) < 0)
{
printf("probleme a la fermeture\r\n");
}
return (EXIT_SUCCESS);
} |
Partager