signal RTS and port COM...

G

Guest

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.
 
J

Jochen Kalmbach

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!


--
Greetings
Jochen

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

Guest

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top