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
|
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
#include <string.h>
#include <math.h>
/*********************************************/
/* Déclaration des variables pour */
/* Ouverture de la communication USB */
/*********************************************/
DCB m_dcb;
BOOL port_ok;
COMMTIMEOUTS tmout={MAXWORD, 20,1,20}; // Mystère pour moi
char c;
HANDLE com;
int main(void)
{
printf("Lancement programme\n");
com = CreateFile( "com1", GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING, 0,NULL );
if (com==INVALID_HANDLE_VALUE)
printf("ERREUR COM1 inaccessible utiliser com1 en ligne de commande\n");
port_ok = SetupComm(com, 1024, 1024);
port_ok = GetCommState(com, &m_dcb);
m_dcb.BaudRate = 115200;
m_dcb.ByteSize = 8;
m_dcb.Parity = NOPARITY;
m_dcb.StopBits = ONESTOPBIT;
m_dcb.fAbortOnError = FALSE;
m_dcb.fBinary = TRUE ;
m_dcb.fParity = TRUE ;
m_dcb.fNull=TRUE;
port_ok = SetCommState(com, &m_dcb);
SetCommTimeouts (com,&tmout);
while(1)
{
ReadFile(com,&c,1,(LPDWORD) &nbr, NULL);
?????????????????????????????,
/*********************************************/
/* Test l'appui sur une touche clavier */
/* pour arrèt du programme */
/*********************************************/
if (kbhit())
{
caractere_recu = getch();
if (caractere_recu=='y')
{
return(0);
}
}
}
CloseHandle(com);
return(0);
} |
Partager