Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2004

Tip: Looking for answers? Try searching our database.

signal RTS and port COM...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lamalice - 14 Oct 2004 09:37 GMT
hi,

i want send strings by a port COM and put the RTS signal to 1 before send,
and put it to 0 after send the last caractere. A extract of my code:

DWORD dwEvtMask;
char *bufferS = "toto";

hPort  = CreateFile
( "COM1", GENERIC_WRITE|GENERIC_READ,0, NULL, OPEN_EXISTING,        
FILE_FLAG_OVERLAPPED, );
         
SetCommMask(hPort, EV_TXEMPTY)
   
overloppedAttEnvoi.hEvent = CreateEvent(NULL, true, 0, NULL);
overloppedAttEnvoi.Internal = 0;
overloppedAttEnvoi.InternalHigh = 0;
overloppedAttEnvoi.Offset = 0;
overloppedAttEnvoi.OffsetHigh = 0;
   
overloppedEcri.hEvent = CreateEvent(NULL, false, 0, NULL);
overloppedEcri.Internal = 0;
overloppedEcri.InternalHigh = 0;
overloppedEcri.Offset = 0;
overloppedEcri.OffsetHigh = 0;   
   
EscapeCommFunction(hPort,SETRTS)
   
WriteFile(hPort, bufferS, nbCharAEcrire, &nbCharEcrit, &overloppedEcri)
   
WaitCommEvent(hPort, &dwEvtMask, &overloppedAttEnvoi)
iLastErr = GetLastError();
if (iLastErr != ERROR_IO_PENDING)
               printf ("Probleme! %i\n",iLastErr);
else
{
rap = WaitForSingleObject(overloppedAttEnvoi.hEvent, 1000);    
    switch (rap)
    {
    case WAIT_OBJECT_0:        
        if (!GetOverlappedResult(hPort, &overloppedAttEnvoi, &nbCharEcrit, false))
        {
        iLastErr = GetLastError();  
        if (iLastErr == ERROR_IO_INCOMPLETE)
           printf("%s %d","Operation incomplete",iLastErr);
        else
           printf ("Error : %x et rap : %d\n" , GetLastError(),rap);
        }
        else
        {
        ResetEvent(overloppedAttEnvoi.hEvent);
        EscapeCommFunction(hPort,CLRRTS)            }break;
                   default:
        printf ("Error : %x et rap : %d\n" , GetLastError(),rap);
        }
    }
   

Normaly i put RTS to 0 when the last caractere sent, but NO!
RTS down low at the midle of my string!!!

Help me please to resolve this problem

Thanks.
Jochen Kalmbach - 14 Oct 2004 09:54 GMT
> Normaly i put RTS to 0 when the last caractere sent, but NO!
> RTS down low at the midle of my string!!!
>
> Help me please to resolve this problem

There is no solution of your problem, if you want to do it by hand.

The problem is that the EV_TXEMPTY event is received, *before* the last
character has really left the seriel port!

EV_TXEMPTY is only a signal that your can not put some more data into the
serial-chip?s buffer!

The problem is that the documentation on this point is wrong:
<quote>
EV_TXEMPTY: The last character in the output buffer was sent.
</quote>

You can verify this by checking the serial-driver example in the DDK
(which is (almost) the same as the RTM version).

The only solution is to use the "RTS_CONTROL_TOGGLE" feature of the
serial-driver!
This does exactly what you want!

Signature

Greetings
 Jochen

  My blog about Win32 and .NET
  http://blog.kalmbachnet.de/

lamalice - 14 Oct 2004 12:39 GMT
> The only solution is to use the "RTS_CONTROL_TOGGLE" feature of the
> serial-driver!
> This does exactly what you want!

Yes, it's true for XP but not for WIN98 or 2000!!!

My problem is my program must run over multiple OS : WIN98 ==> XP.

I have a big problem....
Jochen Kalmbach - 14 Oct 2004 12:46 GMT
=?Utf-8?B?bGFtYWxpY2U=?= wrote:

> I have a big problem....

Yes.

Signature

Greetings
 Jochen

  My blog about Win32 and .NET
  http://blog.kalmbachnet.de/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.