Hi All,
The following the code snippet for my open
serial, close serial and write serial, it works
absolutely fine for some time and after 4 to 5 writes
it shows some old values , some values, I mean say very
wired data, can pls tell me where I am going wrong.I
have increased the size of the buffer too.I have done
SrmReceiveFlush and SrmSendFlush also.
pls go through the code below....................I more
thing when I comment out WinDrawChars() all Srm
functions doesn't seem to work.
Thanks n Regards
Akhil
-------------------------------------------------------
-----------------------
//OPEN PORT CODE
Err OpenSerial(void) {
Err error = 0;
UInt32 flags = 0;
UInt16 flagsSize = sizeof(flags);
// Open the serial port with an initial baud rate of
9600.
error = SrmOpen(serPortCradlePort, 57600,
&gPortID);
SrmSetReceiveBuffer(gPortID,bufP,2048);
/*ErrNonFatalDisplayIf(error == serErrBadPort,
"OpenSerial: serErrBadPort");*/
if(error == 0)
{
//n WinDrawChars("1Serial Port
Open.............",15,10,20);
}
switch (error) {
case errNone:
//n WinDrawChars("ae this is the
case.............",25,10,50);
break;
case serErrAlreadyOpen:
gDetectSerialPortError = 1;
// Clear the port in case garbage data is
hanging around.
SrmReceiveFlush(gPortID, 100);
SrmClose(gPortID);
//n WinDrawChars("Already
Open.............",15,50,50);
return error;
break;
default:
//n WinDrawChars("2Serial Port
Open.............",20,50,50);
return error;
break;
}
gConnected = true;
// Clear the port in case garbage data is hanging
around.
SrmSendFlush(gPortID);
SrmReceiveFlush(gPortID, 100);
// Set communications parameters to 8-N-1 with
hardware flow control.
flags = srmSettingsFlagBitsPerChar8 |
srmSettingsFlagStopBits1 |
srmSettingsFlagRTSAutoM;
error = SrmControl(gPortID, srmCtlSetFlags, &flags,
&flagsSize);
ErrNonFatalDisplayIf(error, "OpenSerial: port
config error");
return error;
}
//CLOSE PORT CODE
void CloseSerial(void) {
Err error;
UInt32 *numBytesP = 0;
error = SrmSendWait(gPortID);
ErrNonFatalDisplayIf(error == serErrBadPort,
"SrmClose: bad port");
if (error == serErrTimeOut)
WinDrawChars("Time out close.............",30,10,50);
// Clear the port in case garbage data is hanging
around.
SrmSendFlush(gPortID);
SrmReceiveFlush(gPortID,100);
SrmSendCheck(gPortID,numBytesP);
if(numBytesP == 0 )
WinDrawChars("All Sent",10,10,10);
else
WinDrawChars("All Not Sent",10,10,10);
SrmSetReceiveBuffer(gPortID,NULL,NULL);
SrmClose(gPortID);
gConnected = false;
}
//WRITE PORT CODE
void WriteSerial(void) {
UInt16 len1;
Err error;
Char *text = "nish";
Char lineFeed = chrLineFeed;
// Bail out if not connected.
if (gConnected == false) return;
// Send the contents of the outgoing field.
len1 = SrmSend(gPortID, text, StrLen(text),
&error);
if (error)
{
//WinDrawChars("char sent",11,10,70);
}
if(len1 == 4)
{
//WinDrawChars("4good char sent",11,10,90);
}
if(len1 == 5)
{
//WinDrawChars("5good char sent",11,10,90);
}
// Send a linefeed character.
SrmSend(gPortID, &lineFeed, 1, &error);
if (error)
WinDrawChars("line feed sent",11,10,80);
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/