Asynchronous I/O in COM port

hai all,

a usermode question, but guru’s here can help me…

i am opening the COM port for asynchronuous I/O using the following stmt.

m_hPort =
CreateFile(m_szPortName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_FL
AG_OVERLAPPED,0);

and a manual reset event is created for Async i/o

if(!(m_hReadEvent = CreateEvent(0,TRUE,FALSE,0)))

and in another function, i am placing an asychronous read for 256 bytes from
the port, The problem i am facing is…

when the first byte comes to the port, WaitForSingleObject() returns and
again at WaitForSingleObject()it waits for the second byte. but even after
second byte is reached at the port the WaitForSingleObject() function is not
returnning and the program stucks.

memset(&m_OverlappedRead,0,sizeof(OVERLAPPED));
m_OverlappedRead.hEvent = m_hReadEvent;

if(::ReadFile(m_hPort,m_lpszReadBuffer,256,&dwBytesRead,&m_OverlappedRead))
ReadComplete(dwBytesRead);

do
{
DWORD dwReturnStatus =
WaitForSingleObject(m_hReadEvent,INFINITE);

switch(dwReturnStatus)
{
case WAIT_OBJECT_0:

if(!GetOverlappedResult(m_hPort,&m_OverlappedRead,&dwBytesRead,FALSE))
//Error

ResetEvent(m_OverlappedRead.hEvent);
nCompletionFlag = GENERIC_READ;
break;
default:

};
}
while(true);

am i doing right or missing something?

regards
Deepu.L.R

----- Original Message -----
From: “DEEPU L R”
To: “Windows System Software Devs Interest List”
Sent: Friday, April 30, 2004 1:06 PM
Subject: [ntdev] Asynchronous I/O in COM port

> hai all,
>
> a usermode question, but guru’s here can help me…
>
>
> i am opening the COM port for asynchronuous I/O using the following stmt.
>
> m_hPort =
>
CreateFile(m_szPortName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_FL
> AG_OVERLAPPED,0);
>
> and a manual reset event is created for Async i/o
>
> if(!(m_hReadEvent = CreateEvent(0,TRUE,FALSE,0)))
>
>
>
> and in another function, i am placing an asychronous read for 256 bytes
from
> the port, The problem i am facing is…
>
> when the first byte comes to the port, WaitForSingleObject() returns and
> again at WaitForSingleObject()it waits for the second byte. but even after
> second byte is reached at the port the WaitForSingleObject() function is
not
> returnning and the program stucks.
>
> memset(&m_OverlappedRead,0,sizeof(OVERLAPPED));
> m_OverlappedRead.hEvent = m_hReadEvent;
>
>
>
if(::ReadFile(m_hPort,m_lpszReadBuffer,256,&dwBytesRead,&m_OverlappedRead))
> ReadComplete(dwBytesRead);
>
> do
> {
> DWORD dwReturnStatus =
> WaitForSingleObject(m_hReadEvent,INFINITE);
>
> switch(dwReturnStatus)
> {
> case WAIT_OBJECT_0:
>
>
> if(!GetOverlappedResult(m_hPort,&m_OverlappedRead,&dwBytesRead,FALSE))
> //Error
>
> ResetEvent(m_OverlappedRead.hEvent);
> nCompletionFlag = GENERIC_READ;
> break;
> default:
>
> };
> }
> while(true);
>
> am i doing right or missing something?
>
>
> regards
> Deepu.L.R
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@calsoft.co.in
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Hi Da Deepumone,

U need to place read operation for the remaining bytes.

regs
sisi
----- Original Message -----
From: “DEEPU L R”
To: “Windows System Software Devs Interest List”
Sent: Friday, April 30, 2004 1:06 PM
Subject: [ntdev] Asynchronous I/O in COM port

> hai all,
>
> a usermode question, but guru’s here can help me…
>
>
> i am opening the COM port for asynchronuous I/O using the following stmt.
>
> m_hPort =
>
CreateFile(m_szPortName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_FL
> AG_OVERLAPPED,0);
>
> and a manual reset event is created for Async i/o
>
> if(!(m_hReadEvent = CreateEvent(0,TRUE,FALSE,0)))
>
>
>
> and in another function, i am placing an asychronous read for 256 bytes
from
> the port, The problem i am facing is…
>
> when the first byte comes to the port, WaitForSingleObject() returns and
> again at WaitForSingleObject()it waits for the second byte. but even after
> second byte is reached at the port the WaitForSingleObject() function is
not
> returnning and the program stucks.
>
> memset(&m_OverlappedRead,0,sizeof(OVERLAPPED));
> m_OverlappedRead.hEvent = m_hReadEvent;
>
>
>
if(::ReadFile(m_hPort,m_lpszReadBuffer,256,&dwBytesRead,&m_OverlappedRead))
> ReadComplete(dwBytesRead);
>
> do
> {
> DWORD dwReturnStatus =
> WaitForSingleObject(m_hReadEvent,INFINITE);
>
> switch(dwReturnStatus)
> {
> case WAIT_OBJECT_0:
>
>
> if(!GetOverlappedResult(m_hPort,&m_OverlappedRead,&dwBytesRead,FALSE))
> //Error
>
> ResetEvent(m_OverlappedRead.hEvent);
> nCompletionFlag = GENERIC_READ;
> break;
> default:
>
> };
> }
> while(true);
>
> am i doing right or missing something?
>
>
> regards
> Deepu.L.R
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@calsoftinc.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Sisimoneee,

thank u da …i thought only a single read will do…

regards
Deepu.L.R

-----Original Message-----
From: Sisimon [mailto:xxxxx@calsoftinc.com]
Sent: Friday, April 30, 2004 1:49 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Asynchronous I/O in COM port

Hi Da Deepumone,

U need to place read operation for the remaining bytes.

regs
sisi
----- Original Message -----
From: “DEEPU L R”
To: “Windows System Software Devs Interest List”
Sent: Friday, April 30, 2004 1:06 PM
Subject: [ntdev] Asynchronous I/O in COM port

> hai all,
>
> a usermode question, but guru’s here can help me…
>
>
> i am opening the COM port for asynchronuous I/O using the following stmt.
>
> m_hPort =
>
CreateFile(m_szPortName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_FL
> AG_OVERLAPPED,0);
>
> and a manual reset event is created for Async i/o
>
> if(!(m_hReadEvent = CreateEvent(0,TRUE,FALSE,0)))
>
>
>
> and in another function, i am placing an asychronous read for 256 bytes
from
> the port, The problem i am facing is…
>
> when the first byte comes to the port, WaitForSingleObject() returns and
> again at WaitForSingleObject()it waits for the second byte. but even after
> second byte is reached at the port the WaitForSingleObject() function is
not
> returnning and the program stucks.
>
> memset(&m_OverlappedRead,0,sizeof(OVERLAPPED));
> m_OverlappedRead.hEvent = m_hReadEvent;
>
>
>
if(::ReadFile(m_hPort,m_lpszReadBuffer,256,&dwBytesRead,&m_OverlappedRead))
> ReadComplete(dwBytesRead);
>
> do
> {
> DWORD dwReturnStatus =
> WaitForSingleObject(m_hReadEvent,INFINITE);
>
> switch(dwReturnStatus)
> {
> case WAIT_OBJECT_0:
>
>
> if(!GetOverlappedResult(m_hPort,&m_OverlappedRead,&dwBytesRead,FALSE))
> //Error
>
> ResetEvent(m_OverlappedRead.hEvent);
> nCompletionFlag = GENERIC_READ;
> break;
> default:
>
> };
> }
> while(true);
>
> am i doing right or missing something?
>
>
> regards
> Deepu.L.R
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@calsoftinc.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@nestec.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

It sort of looks like you’re issuing a single read and expecting an I/O
completion for each byte in the read. Perhaps it’s just too late here
for me, but I think you’ll be wanting to reissue the read to get any
data not returned in the first read.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of JothiKumar
Sent: Friday, April 30, 2004 1:08 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Asynchronous I/O in COM port

----- Original Message -----
From: “DEEPU L R”
To: “Windows System Software Devs Interest List”
Sent: Friday, April 30, 2004 1:06 PM
Subject: [ntdev] Asynchronous I/O in COM port

> hai all,
>
> a usermode question, but guru’s here can help me…
>
>
> i am opening the COM port for asynchronuous I/O using the following
stmt.
>
> m_hPort =
>
CreateFile(m_szPortName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FIL
E_FL
> AG_OVERLAPPED,0);
>
> and a manual reset event is created for Async i/o
>
> if(!(m_hReadEvent = CreateEvent(0,TRUE,FALSE,0)))
>
>
>
> and in another function, i am placing an asychronous read for 256
> bytes
from
> the port, The problem i am facing is…
>
> when the first byte comes to the port, WaitForSingleObject() returns
> and again at WaitForSingleObject()it waits for the second byte. but
> even after second byte is reached at the port the
> WaitForSingleObject() function is
not
> returnning and the program stucks.
>
> memset(&m_OverlappedRead,0,sizeof(OVERLAPPED));
> m_OverlappedRead.hEvent = m_hReadEvent;
>
>
>
if(::ReadFile(m_hPort,m_lpszReadBuffer,256,&dwBytesRead,&m_OverlappedRea
d))
> ReadComplete(dwBytesRead);
>
> do
> {
> DWORD dwReturnStatus =
> WaitForSingleObject(m_hReadEvent,INFINITE);
>
> switch(dwReturnStatus)
> {
> case WAIT_OBJECT_0:
>
>
> if(!GetOverlappedResult(m_hPort,&m_OverlappedRead,&dwBytesRead,FALSE))
> //Error
>
> ResetEvent(m_OverlappedRead.hEvent);
> nCompletionFlag = GENERIC_READ;
> break;
> default:
>
> };
> }
> while(true);
>
> am i doing right or missing something?
>
>
> regards
> Deepu.L.R
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@calsoft.co.in To
> unsubscribe send a blank email to xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Hi Da Deepu,

OK, u need to place read for remaining bytes. Also after placing read
operation u need to check the last error and confirm it is read pending.
Bcos if any other error happens during early read operation, no one there to
signal the event. U r thread MAY hang.

regs
sisi

----- Original Message -----
From: “DEEPU L R”
To: “Windows System Software Devs Interest List”
Sent: Friday, April 30, 2004 1:50 PM
Subject: RE: [ntdev] Asynchronous I/O in COM port

> Sisimoneee,
>
> thank u da …i thought only a single read will do…
>
> regards
> Deepu.L.R
>
> -----Original Message-----
> From: Sisimon [mailto:xxxxx@calsoftinc.com]
> Sent: Friday, April 30, 2004 1:49 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] Asynchronous I/O in COM port
>
>
> Hi Da Deepumone,
>
> U need to place read operation for the remaining bytes.
>
> regs
> sisi
> ----- Original Message -----
> From: “DEEPU L R”
> To: “Windows System Software Devs Interest List”
> Sent: Friday, April 30, 2004 1:06 PM
> Subject: [ntdev] Asynchronous I/O in COM port
>
>
> > hai all,
> >
> > a usermode question, but guru’s here can help me…
> >
> >
> > i am opening the COM port for asynchronuous I/O using the following
stmt.
> >
> > m_hPort =
> >
>
CreateFile(m_szPortName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_FL
> > AG_OVERLAPPED,0);
> >
> > and a manual reset event is created for Async i/o
> >
> > if(!(m_hReadEvent = CreateEvent(0,TRUE,FALSE,0)))
> >
> >
> >
> > and in another function, i am placing an asychronous read for 256 bytes
> from
> > the port, The problem i am facing is…
> >
> > when the first byte comes to the port, WaitForSingleObject() returns and
> > again at WaitForSingleObject()it waits for the second byte. but even
after
> > second byte is reached at the port the WaitForSingleObject() function is
> not
> > returnning and the program stucks.
> >
> > memset(&m_OverlappedRead,0,sizeof(OVERLAPPED));
> > m_OverlappedRead.hEvent = m_hReadEvent;
> >
> >
> >
>
if(::ReadFile(m_hPort,m_lpszReadBuffer,256,&dwBytesRead,&m_OverlappedRead))
> > ReadComplete(dwBytesRead);
> >
> > do
> > {
> > DWORD dwReturnStatus =
> > WaitForSingleObject(m_hReadEvent,INFINITE);
> >
> > switch(dwReturnStatus)
> > {
> > case WAIT_OBJECT_0:
> >
> >
> > if(!GetOverlappedResult(m_hPort,&m_OverlappedRead,&dwBytesRead,FALSE))
> > //Error
> >
> > ResetEvent(m_OverlappedRead.hEvent);
> > nCompletionFlag = GENERIC_READ;
> > break;
> > default:
> >
> > };
> > }
> > while(true);
> >
> > am i doing right or missing something?
> >
> >
> > regards
> > Deepu.L.R
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@calsoftinc.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@nestec.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@calsoftinc.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Hi

Set correctly the timeout values using setcommtimeout(…).
Adjusting them you will be able to read even the whole data or byte byte or
any other combination.
You should not use a manual reset event, OS takes care of that.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

thank u all for the hint…

-----Original Message-----
From: Peter Wieland [mailto:xxxxx@windows.microsoft.com]
Sent: Friday, April 30, 2004 2:24 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Asynchronous I/O in COM port

It sort of looks like you’re issuing a single read and expecting an I/O
completion for each byte in the read. Perhaps it’s just too late here
for me, but I think you’ll be wanting to reissue the read to get any
data not returned in the first read.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of JothiKumar
Sent: Friday, April 30, 2004 1:08 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Asynchronous I/O in COM port

----- Original Message -----
From: “DEEPU L R”
To: “Windows System Software Devs Interest List”
Sent: Friday, April 30, 2004 1:06 PM
Subject: [ntdev] Asynchronous I/O in COM port

> hai all,
>
> a usermode question, but guru’s here can help me…
>
>
> i am opening the COM port for asynchronuous I/O using the following
stmt.
>
> m_hPort =
>
CreateFile(m_szPortName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FIL
E_FL
> AG_OVERLAPPED,0);
>
> and a manual reset event is created for Async i/o
>
> if(!(m_hReadEvent = CreateEvent(0,TRUE,FALSE,0)))
>
>
>
> and in another function, i am placing an asychronous read for 256
> bytes
from
> the port, The problem i am facing is…
>
> when the first byte comes to the port, WaitForSingleObject() returns
> and again at WaitForSingleObject()it waits for the second byte. but
> even after second byte is reached at the port the
> WaitForSingleObject() function is
not
> returnning and the program stucks.
>
> memset(&m_OverlappedRead,0,sizeof(OVERLAPPED));
> m_OverlappedRead.hEvent = m_hReadEvent;
>
>
>
if(::ReadFile(m_hPort,m_lpszReadBuffer,256,&dwBytesRead,&m_OverlappedRea
d))
> ReadComplete(dwBytesRead);
>
> do
> {
> DWORD dwReturnStatus =
> WaitForSingleObject(m_hReadEvent,INFINITE);
>
> switch(dwReturnStatus)
> {
> case WAIT_OBJECT_0:
>
>
> if(!GetOverlappedResult(m_hPort,&m_OverlappedRead,&dwBytesRead,FALSE))
> //Error
>
> ResetEvent(m_OverlappedRead.hEvent);
> nCompletionFlag = GENERIC_READ;
> break;
> default:
>
> };
> }
> while(true);
>
> am i doing right or missing something?
>
>
> regards
> Deepu.L.R
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@calsoft.co.in To
> unsubscribe send a blank email to xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@nestec.net
To unsubscribe send a blank email to xxxxx@lists.osr.com