Author Topic: DeviceIoControl(IOCTL_SERIAL_PURGE) Invalid Handle  (Read 20083 times)

Joe0x7F

  • Member
  • ***
  • Posts: 12
DeviceIoControl(IOCTL_SERIAL_PURGE) Invalid Handle
« 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!

-----------
« Last Edit: February 08, 2012, 07:56:37 pm by Joe0x7F »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research

Joe0x7F

  • Member
  • ***
  • Posts: 12
Re: DeviceIoControl(IOCTL_SERIAL_PURGE) Invalid Handle
« Reply #2 on: February 09, 2012, 11:04:55 am »
Thanks Jan!!!

Works like a champ!

-----