Re: Writing to Serial Port
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 03/01/05
- Next message: Leandro Delamare: "CListBox Selected item"
- Previous message: Joseph M. Newcomer: "Re: System-wide keyboard hook stops functioning problem !!!"
- In reply to: Øyvind Hansen: "Re: Writing to Serial Port"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 01 Mar 2005 13:10:45 -0500
Yes. The only reason to wait is to simplify the programming. If you are doing multiple
WriteFile operations, you need to have multiple OVERLAPPED structures, and perhaps even
multiple events. These days, since I no longer have to run on obsolete technologies like
MS-DOS (Win9x/Me), I use I/O Completion Ports to handle completion notifications. If you
don't care about completion notifications, you can even ignore GetOverlappedResult,
although if there is an error with the port you would then be in trouble.
As already pointed out, the offset value in a serial port has no meaning, so there is no
reason to update it, or even care about it.
joe
On Tue, 1 Mar 2005 17:47:25 +0100, "Øyvind Hansen" <oyvind@scantrol.no> wrote:
>In other words it is not necessary to Wait forSingleObject() when using
>ovelapped I/O.
>I can run WriteFile() and allow my program to run without waiting for the
>data being transmitted?
>
>Oyvind
>
>
>"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> skrev i melding
>news:eqG9gPmHFHA.3208@TK2MSFTNGP10.phx.gbl...
>> Oyvind Hansen wrote:
>> > For transm,itting data on a serialport i am opening the port for
>overlapped
>> > operation and I am using the WriteFile() function for writing to the
>port.
>> > This works well, however i found an example in "Visual C++ Bible" where
>the
>> > author is using WaitForSingleObject() before running
>GetOverlappedResult()
>> > and setting.offset of the OVERLAPPED structure. This will block the
>> > transmittdata function, and I can not really see a good reason for why
>doing
>> > that. Appreciate if someone could explain this...
>> >
>>
>> This is overlapped I/O. One reason for doing it is that it is necessary
>> to use overlapped I/O with a serial port if one wants full duplex (send
>> while receive) operation. Another (possible) reason for doing it is so
>> the code can do something else (such as read from socket or file) while
>> the WriteFile is in progress. It is not necessary to increment the
>> .Offset member.
>>
>> --
>> Scott McPhillips [VC++ MVP]
>>
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Leandro Delamare: "CListBox Selected item"
- Previous message: Joseph M. Newcomer: "Re: System-wide keyboard hook stops functioning problem !!!"
- In reply to: Øyvind Hansen: "Re: Writing to Serial Port"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|