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