Hi Rob,
I have also had similar problems using SrmWakeupHandler on OS5. The results were simply erratic and the device would soft reset at random without any warnings.It took me a lot of time and energy to find the reason for such an erratic [and annoying] behaviour. The APIs used for such a purpose are not documented by Palm and made my task even thougher. Try the following:-
1. When sending or receiving data from USB using SrmWakeupHandler, make sure GPRS is switched off. You may turn it on again just after the data transfer is over. For some strange reason, data transmission through GPRS interefers with USB data transfer.
 
2. Give some delay between sending and receiving data through USB. [2-3 seconds should be ok]
 
3. Make sure there are no USB managers running other than what Windows provides. Make sure to exit from them before starting USB data transfer.
 
4.WakeupHandlerProcPtr is the pointer to the call back function that is called when there is data available on the USB port. A simple snippet would be:-
error = SrmSetWakeupHandler(*portID,
                              (WakeupHandlerProcPtr)RecvDatahandler,
                              (UInt32)*portID);
where RecvDataHnadler fn. will be as shown:-
 
static void RecvDatahandler(UInt32 portID)
{
    Err    err = 0;
    UInt32 count;
    UInt16 counter = 0;
    UInt16 i = 0;
    UInt8* tempP;
    CommPacketType evtData={0,0,"\0"};
 UInt8  recvBufferP[MAX_DATA_LEN]="\0";  //#define MAX_DATA_LEN 64 
    Int16 y = 10;
    Char pBuff[3] = "\0";
    SysNotifyParamType dataNotify;
  
    SrmClearErr(portID); 
    
    MemMove (recvBufferP, 0, MAX_DATA_LEN);
       
    while (true) {          
    //clear line errors and flush the receive buffer before accepting data
    SrmClearErr(portID);
    SrmReceiveFlush(portID, 0);
   //read the data  
    err = SrmReceiveWindowOpen(portID, &tempP, &count);        
    
     if (err)
     {
       switch (err)
   {
   case serErrBadPort:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowOpen:This port doesn’t
                            exist","","");
   break;
   case serErrNotOpen:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowOpen:The port is not open","","");
   break;
   case serErrNotSupported:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowOpen:The port is not the foreground port","","");
   break;
   case serErrLineErr:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowOpen:The data in the queue contains line errors","","");
   break;
   case serErrNoDevicesAvail:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowOpen:No serial devices could be found","","");
   break;
   }   
         SrmClearErr(portID);
      }
        
     if (!count)
         break;
     counter = count;
 
  
  while (counter--)
  recvBufferP[i++] = *tempP++;
  
     //Let the New Serial Manager know that we're done with the data.
     err=SrmReceiveWindowClose(portID, count);
    switch (err)
   {
   case serErrBadPort:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowClose:This port doesn’t exist","","");
   break;
   case serErrNotOpen:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowClose:The port is not open","","");
   break;
   case serErrNotSupported:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowClose:The port is not the foreground port","","");
   break;
   case serErrNoDevicesAvail:
   FrmCustomAlert (DebugAlert, "SrmReceiveWindowClose:No serial devices could be found","","");
   break;
   }
    }
    //Reprime the wakeup handler
    err = SrmPrimeWakeupHandler(portID, 1);
    
 switch (err)
 {
 case serErrBadPort:
 FrmCustomAlert (DebugAlert, "SrmPrimeWakeupHandler:This port doesn’t exist","","");
 break;
 case serErrNotOpen:
 FrmCustomAlert (DebugAlert, "SrmPrimeWakeupHandler:The port is not open","","");
 break;
 case serErrNoDevicesAvail:
 FrmCustomAlert (DebugAlert, "SrmPrimeWakeupHandler:No serial devices could be found","","");
 break;
 }

    // Process the data   
    MemMove (&evtData, recvBufferP, MAX_DATA_LEN);
       
    dataNotify.notifyType = tuDataRecv;
    dataNotify.broadcaster = CREATOR_ID;
    dataNotify.notifyDetailsP = &evtData;
    dataNotify.userDataP = &evtData;
    dataNotify.handled = false;
    
    // Notify ourselves that a byte has arrived and take action then
 err=SysNotifyBroadcastDeferred (&dataNotify, sizeof(evtData));
 
 switch (err)
 {
   case memErrNotEnoughSpace:
   FrmCustomAlert (DebugAlert, "SysNotifyBroadcastDeferred:There is not enough memory to allocate a new notification entry in the queue","","");
   break;   
   case sysErrParamErr:
   FrmCustomAlert (DebugAlert, "SysNotifyBroadcastDeferred:paramSize is a negative number","","");
   break;   
   case sysNotifyErrQueueFull:
   FrmCustomAlert (DebugAlert, "SysNotifyBroadcastDeferred:The queue has reached its maximum number of entries","","");
   break;   
 } 
    return;
}
There would be a seperate set of code running on the desktop side to receive data sent from the device. This set of code uses APIS which are not documented by Palm anywhere.These are:-
USB_API LONG  PalmUsbGetDeviceFriendlyName  (PTCHAR  pDeviceName,
               PTCHAR  pFriendlyName);
USB_API ULONG  PalmUsbGetAttachedDevices   (ULONG*  pDeviceCount,
               PTCHAR  pBuffer,
               ULONG*  pBufferSize);
 
USB_API HDEVNOTIFY PalmUsbRegisterDeviceInterface  (HWND  windowHandle);
USB_API VOID  PalmUsbUnRegisterDeviceInterface (HDEVNOTIFY notifyHandle);
 
USB_API BOOL  PalmUsbIsPalmOSDeviceNotification (ULONG  eventData,
               ULONG  creatorID,
               PTCHAR  pDeviceName,
               GUID*  pDeviceGUID);
 
USB_API HANDLE  PalmUsbOpenPort      (PTCHAR  pDeviceName,
               ULONG  creatorID);
 
USB_API BOOL  PalmUsbClosePort     (HANDLE  deviceHandle);
 
USB_API ULONG  PalmUsbReceiveBytes     (HANDLE  deviceHandle,
               LPVOID  pReceiveBuffer,
               ULONG  bytesToReceive,
               ULONG*  pBytesReceived);
 
USB_API ULONG  PalmUsbSendBytes     (HANDLE  deviceHandle,
               LPCVOID pSendBuffer,
               ULONG  bytesToSend,
               ULONG*  pBytesSent);
 
USB_API ULONG  PalmUsbSetTimeouts     (HANDLE   deviceHandle,
               USB_TIMEOUTS* timeouts);
 
USB_API ULONG  PalmUsbGetTimeouts     (HANDLE   deviceHandle,USB_TIMEOUTS* timeouts)
I hope it helps ur cause.
 
All the best!
--Subra

John Sutton <[EMAIL PROTECTED]> wrote:
Rob,
You don't say what device you're using, but if it's OS5, then that is most likely your problem.
We've had erratic results using SrmSetWakeupHandler on OS5 devices, we were not able to solve these, and had to rewrite the product to use the Alarm Manager callback routines instead.
Regards
John Sutton


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: 02 August 2005 01:07
To: Palm Developer Forum
Subject: trouble with serial communcation -- SrmSetWakeupHandler

I am attempting my first Palm app so be gentle. Basically I am  using the serial interface to receive and display data.   I am attempting to use SrmSetWakeupHandler but it's not going so well.  When I run on the device itself everything is good until I actually try to shove data to the Palm.  I get a fatal error and it hangs.  I have a feeling that my callback function isn't getting called properly.  When I set the callback to NULL then the fatal goes away, but ofcourse nothing happens :)  I put in a test FrmAlert in my callback to check if it's even making it there and it never shows up.  Any thoughts?  I have 2 specific questions;
 
1) does anybody have a good working example of using SrmSetWakeupHandler and how to set the callback function(not the ones from palm dev, I have already read through that one)?  It might just be a simple C coding error on my side.  When I compile, Codewarrior gives me an error that my WakeupHandlerProcPtr variable isn't initialized before use.
 
2) Is there a way to use the emulator to debug these sort of problems?  I don't really have a good way to control and drive the serial stream into the PC for the emulator to use.  Currently I am using DockLight to generate the rs232 patterns from my PC to my Palm device for testing.  I can't figure out a way to use DockLight to drive patterns to the emulator without doing a loop around serial connection on my PC.  I was hoping there is an easy way to drive phoney bits to the serial manager directly in sofware.
 
Thanks for any and all help.
-Rob
--
For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ --
For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/


Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE!
http://in.mail.yahoo.com -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to