Ports
May 23, 2013, 10:03:08 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Welcome to the PORTS Forum. Please post your questions, answers, and comments relating to USB and other hardware interfaces in the appropriate forums below. - Jan
Pages: [1]
  Print  
Author Topic: DeviceIoControl(IOCTL_SERIAL_PURGE) Invalid Handle  (Read 1555 times)
Joe0x7F
Member
***
Posts: 12


« 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 » Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1629


WWW
« Reply #1 on: February 08, 2012, 11:39:29 pm »

Did you try PurgeComm:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363428%28v=vs.85%29.aspx'

Jan
Logged
Joe0x7F
Member
***
Posts: 12


« Reply #2 on: February 09, 2012, 11:04:55 am »

Thanks Jan!!!

Works like a champ!

-----
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!