Hi Roland,
> > When I'm using my own application, sometimes I'm able to
> retreive the
> > messages but
> > mostly I get random behaviour like timeouts, fatal exceptions
> > or the Palm
> > just hangs.
>
> which compiler do you use (mw or gnu)? can you debug the
> application using
> pose? i have no problems in debugging serial port
> communication software
> with pose - just make sure that you use a adapter which
> crosses rxd and txd
> lines.
>
I'm using GNU Win32 for Palm version 0.5.0, i'm not familiar
with pose, my debugging till now is limited to popping up
message boxes to see what is happening. I'm using palm IIIx.
> without your source its difficult to say. i have no problems
> with the serial
> port of the palm (III).
>
My source is simply based on the example which comes with the
above mentioned compiler. I've ported the classes we use for
the same app under WinCE as good as posible (replacing calls
to libc with calls to string manager etc and relpacing Windows
serial communication with Palm serial manager) and added calls
to these classes to the PilotMain function from the example. All
is done before the start of the event loop.
--------
Open Serial Communication
--------
if (cmd == sysAppLaunchCmdNormalLaunch) {
kidForm = kidForm1;
FrmGotoForm(kidForm);
Err error;
UInt m_uiRefno;
SerSettingsType settings;
error = SysLibFind("Serial Library",&m_uiRefno);
if (error != 0) {
FrmCustomAlert(kidAlertError,"Mobile","Cannot find Serial
Library","");
} else {
error = SerOpen(m_uiRefno,0,9600L);
if (error != 0) {
FrmCustomAlert(kidAlertError,"Mobile","Cannot open
com port","");
} else {
SerGetSettings(m_uiRefno, &settings);
settings.flags = serSettingsFlagBitsPerChar8 |
serSettingsFlagStopBits1 |
serSettingsFlagXonXoffM;
SerSetSettings(m_uiRefno, &settings);
}
}
--------
Send Data
--------
String Data = "atz\r"; // Our own string class
int TimeOut = 5000; // Timeout in miliseconds
char pData[500];
unsigned long DataSize, dwWritten;
for( int x = 0; x < Data.Len(); x++ ) {
*(pData + x) = (char)Data[x];
}
DataSize = Data.Len();
SerSendFlush(m_uiRefno);
SerReceiveFlush( m_uiRefno, 0 );
ULong size = SerSend(m_uiRefno, pData, DataSize, &error);
if (error != 0) {
String ErrorStr;
ErrorStr.Printf("Cannot write error %d in SerSend",error);
FrmCustomAlert(kidAlertError,"Mobile",ErrorStr.ptr(),"");
} else {
error = SerSendWait(m_uiRefno,
TimeOut*sysTicksPerSecond/1000);
if (error != 0) {
String ErrorStr;
ErrorStr.Printf(TEXT("Cannot write error %d in
SerSendWait"),error);
FrmCustomAlert(kidAlertError,"Mobile",ErrorStr.ptr(),"");
}
}
--------
Receive Data
--------
unsigned long dwRead;
char pData[500];
dwRead = SerReceive(m_uiRefno, pData, 1, 100, &error);
if (error != 0) {
Boolean ctsOn, dsrOn;
Word status = SerGetStatus(m_uiRefno, &ctsOn, &dsrOn);
char buffer[256];
StrPrintF(buffer, "error = %x, status = %x", error, status);
FrmCustomAlert(kidAlertError,"SerReceive",buffer,"");
} else {
pData[dwRead] = 0;
}
--------
The loop to receive the complete response is on a higher level. the received
string is checked for all posible responses after each new character
received with a total timeout of 5000 ticks (difference between
GetTickCount()
at start and current).
Thanx for your help!
Sander