bonjour
Gestion de la com en synchrone
HANDLE hPort=INVALID_HANDLE_VALUE;
DCB ParametrePort;
COMMTIMEOUTS time;
BOOL erreur;
DWORD dwWritten,dwRead;
unsigned char WrBuf,RdBuf;
CloseHandle(hPort);
hPort=CreateFile("com1", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL ,0);
GetCommState(hPort,&ParametrePort);
ParametrePort.DCBlength =sizeof(DCB);
ParametrePort.BaudRate = CBR_57600;
ParametrePort.fBinary=TRUE;
ParametrePort.fParity=0;
ParametrePort.Parity=NOPARITY;
ParametrePort.fOutxCtsFlow=FALSE;
ParametrePort.fOutxDsrFlow=0;
ParametrePort.fDtrControl=DTR_CONTROL_ENABLE;
ParametrePort.fDsrSensitivity=FALSE;
ParametrePort.fRtsControl=RTS_CONTROL_DISABLE;
ParametrePort.ByteSize=8;
ParametrePort.Parity=NOPARITY;
ParametrePort.StopBits=ONESTOPBIT;
ParametrePort.fAbortOnError=FALSE;
ParametrePort.fDummy2=FALSE;
ParametrePort.wReserved=FALSE;
ParametrePort.fErrorChar=FALSE;
ParametrePort.fNull=FALSE;
ParametrePort.ErrorChar=0;
ParametrePort.EofChar=0;
ParametrePort.EvtChar=0;
ParametrePort.XonLim=512;
ParametrePort.XoffLim=1024;
ParametrePort.fTXContinueOnXoff=FALSE;
ParametrePort.fOutX=FALSE;
ParametrePort.fInX=FALSE;
ParametrePort.XonChar=17;
ParametrePort.XoffChar=19;
SetCommState(hPort,&ParametrePort);
time.ReadIntervalTimeout=100;
time.ReadTotalTimeoutMultiplier=100;
time.ReadTotalTimeoutConstant=100;
time.WriteTotalTimeoutMultiplier=100;
time.WriteTotalTimeoutConstant=100;
SetCommTimeouts(hPort,&time);
SetupComm(hPort,2048,2048);
Lecture des infos sur le port serie avec fonction
BOOL ReadFile( HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped );
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/readfile.asp
pour ecriture dans fichier
CFile f;
CFileException e;
CString co;
co.Format("coucou");
if( f.Open( "c:\\monfichier.txt", CFile::modeCreate | CFile::modeWrite, &e ) )
{
f.Write(co,co.GetLength());
f.Close();
bon courage
TOCHE