PORTS Forum
Ports and Interfaces => Serial Ports => Topic started by: Joe0x7F on February 08, 2012, 07:48:05 pm
-
Any ideas why DeviceIoControl() would be failing and GetLastError() returning 0x06 = Invalid Handel?
I was writing to the Serial (COMx:) Port fine just before the DeviceIoControl() call.
....
#include <windows.h>
#include <winioctl.h>
.....
#define IOCTL_SERIAL_PURGE CTL_CODE(FILE_DEVICE_SERIAL_PORT,19,METHOD_BUFFERED,FILE_ANY_ACCESS)
...
FILE *pFile;
DWORD flag1=PURGE_TXCLEAR;
DWORD nOutBufferSize=256;
DWORD BytesReturned=0;
struct _OVERLAPPED O1;
char OutBuffer[256]="";
....
pFile = CreateFile("COM4:",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
....
flag1=PURGE_TXCLEAR;
dwError=DeviceIoControl(pFile, IOCTL_SERIAL_PURGE, &flag1, sizeof(flag1), &OutBuffer, nOutBufferSize, &BytesReturned, &O1);
Thanks!
-----------
-
Did you try PurgeComm:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363428%28v=vs.85%29.aspx'
Jan
-
Thanks Jan!!!
Works like a champ!
-----