Hi,

I am running the serial communication program in window mobile 5 pocket pc.

the configuration setting is below:
DCB PortDCB;

PortDCB.BaudRate = 115200;
PortDCB.fBinary = TRUE;
PortDCB.fParity = TRUE;
PortDCB.fOutxCtsFlow = FALSE;
PortDCB.fOutxDsrFlow = FALSE;
PortDCB.fDtrControl = DTR_CONTROL_DISABLE;
PortDCB.fDsrSensitivity = FALSE;
PortDCB.fTXContinueOnXoff = TRUE;
PortDCB.fOutX = FALSE;
PortDCB.fInX = FALSE;
PortDCB.fErrorChar = FALSE;
PortDCB.fNull = FALSE;
PortDCB.fRtsControl = RTS_CONTROL_DISABLE;
PortDCB.ByteSize = ByteSize;
PortDCB.Parity = NOPARITY;
PortDCB.StopBits = ONESTOPBIT;
PortDCB.fAbortOnError = FALSE;

The timeout setting is :
COMMTIMEOUTS commTimeouts;

commTimeouts.ReadIntervalTimeout = MAXDWORD;
commTimeouts.ReadTotalTimeoutMultiplier = 0;
commTimeouts.ReadTotalTimeoutConstant = 0;
commTimeouts.WriteTotalTimeoutMultiplier = 10;
commTimeouts.WriteTotalTimeoutConstant = 100;

I call the writefile api as follow:
BYTE sendData = 65;
INT bytesWritten = 0;
if (!ClearCommError( portHandle, &lpErrors, &lpStat))
{
//clearcommerror failed
}

if( !(WriteFile( portHandle, &sendData,1,&bytesWritten,NULL)))
{
//error
}
else
{
//success
}

When I call the writeFile api, I got success statement but the value of
bytesWriteen is zero.

I tested in emulator and it works fine. The problem occurs in real target.

I don't really understand what happens with the WriteFile or configuration.

Can anyone help me?

Really thanks.

Re: serial communication writefile problem by Henryk

Henryk
Sat May 10 22:32:06 CDT 2008

I had somewhat similar problem in the past, but I do not remember if
bytesWritten was reported as zero. In my case adding FlushFileBuffers
after writing a single byte solved the problem.

Since you are not using control handshaking I am not certain you need
write timeouts. In my case they were set to zero.

Cheers,
Henryk Birecki

perlsu <perlsu@discussions.microsoft.com> wrote:

>
>Hi,
>
>I am running the serial communication program in window mobile 5 pocket pc.
>
>the configuration setting is below:
>DCB PortDCB;
>
>PortDCB.BaudRate = 115200;
>PortDCB.fBinary = TRUE;
>PortDCB.fParity = TRUE;
>PortDCB.fOutxCtsFlow = FALSE;
>PortDCB.fOutxDsrFlow = FALSE;
>PortDCB.fDtrControl = DTR_CONTROL_DISABLE;
>PortDCB.fDsrSensitivity = FALSE;
>PortDCB.fTXContinueOnXoff = TRUE;
>PortDCB.fOutX = FALSE;
>PortDCB.fInX = FALSE;
>PortDCB.fErrorChar = FALSE;
>PortDCB.fNull = FALSE;
>PortDCB.fRtsControl = RTS_CONTROL_DISABLE;
>PortDCB.ByteSize = ByteSize;
>PortDCB.Parity = NOPARITY;
>PortDCB.StopBits = ONESTOPBIT;
>PortDCB.fAbortOnError = FALSE;
>
>The timeout setting is :
>COMMTIMEOUTS commTimeouts;
>
>commTimeouts.ReadIntervalTimeout = MAXDWORD;
>commTimeouts.ReadTotalTimeoutMultiplier = 0;
>commTimeouts.ReadTotalTimeoutConstant = 0;
>commTimeouts.WriteTotalTimeoutMultiplier = 10;
>commTimeouts.WriteTotalTimeoutConstant = 100;
>
>I call the writefile api as follow:
>BYTE sendData = 65;
>INT bytesWritten = 0;
>if (!ClearCommError( portHandle, &lpErrors, &lpStat))
>{
>//clearcommerror failed
>}
>
>if( !(WriteFile( portHandle, &sendData,1,&bytesWritten,NULL)))
>{
>//error
>}
>else
>{
>//success
>}
>
>When I call the writeFile api, I got success statement but the value of
>bytesWriteen is zero.
>
>I tested in emulator and it works fine. The problem occurs in real target.
>
>I don't really understand what happens with the WriteFile or configuration.
>
>Can anyone help me?
>
>Really thanks.
>
>