(COM LPT) Win32


         

FlushFileBuffers


, , , . . , PurgeComm :

BOOL FlushFileBuffers(

HANDLE hFile

);

/ .

#include <windows.h>

#include <string.h>

. . .

DCB dcb;

COMMTIMEOUTS ct;

HANDLE port;

DWORD bc;

char *buf_out="Test string";

char *buf_in;

. . .

dcb.DCBlength=sizeof(DCB);

BuildCommDCB("baud=9600 parity=N data=8 stop=1",&dcb);

dcb.fNull=TRUE;

ct.ReadIntervalTimeout=10;

ct.ReadTotalTimeoutMultiplier=ct.ReadTotalTimeoutConstant=0;

ct.WriteTotalTimeoutMultiplier=ct.WriteTotalTimeoutConstant=0;

port=CreateFile("COM2",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);

SetCommState(port,dcb);

SetCommTimeouts(port,&ct);

PurgeComm(port,PURGE_TXCLEAR|PURGE_RXCLEAR);

SetupComm(port,256,256);

. . .

buf_in=(char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,strlen(buf_out)+1);

WriteFile(port,buf_out,strlen(buf_out),&bc,NULL);

ReadFile(port,buf_in,strlen(buf_out),&bc,NULL);

HeapFree(GetProcessHeap(),0,buf_in);

CloseHandle(port);

. . .

COM2 TxD RxD, buf_in, ReadFile, , buf_out. , .