Hi,

I have tried following all the information I could find to get a "Hello,
World" sent between 2 Palm devices over a raw serial Ir (SIR) connection. So
far without success.

It should be so simple just change 2 lines of code from tyour normal serial
Manager gode and it should work. Then I have tried to disable IrDa receive
while sending, and to do cleanup after line errors. I have checked on all
errrocodes and settings I could find in the serial manager, but I have still
not found the settings which will get data through.

The code in this posting is working if I choose the IrComm port when opening
the serial port, but not when using the serPortIrPort. Old Palm III devices
seems to support the serPortIrPort too, but I need color.

The code is the starter.c code with just AppEventLoop and AppStart changed +
some extra globals.
It looks like a lot but when stripped from errror handling it is :

On the sending side:

    flags = 
      srmSettingsFlagBitsPerChar8 | srmSettingsFlagStopBits1 |
      srmSettingsFlagRTSAutoM
    SrmOpen(serPortIrPort    , 9600, &portID);
    SrmControl(portID, srmCtlIrDAEnable, NULL, 0);
    SrmControl(portID,srmCtlSetFlags,&flags,&length);
    SrmReceiveFlush(portID,10);
    SrmSend(portID, sendBuf, StrLen(sendBuf), &err);
  
Receiving side:

    flags = 
      srmSettingsFlagBitsPerChar8 | srmSettingsFlagStopBits1 |
      srmSettingsFlagRTSAutoM
    SrmOpen(serPortIrPort    , 9600, &portID);
    SrmControl(portID, srmCtlIrDAEnable, NULL, 0);
    SrmControl(portID,srmCtlSetFlags,&flags,&length);
    SrmControl(portID,srmCtlRxEnable,0,0);// I have tried to omit this
    anErr = SrmReceiveCheck(portID, &numBytes);
    if (anErr == serErrLineErr)
      SrmClearErr(portID),anErr = 0;
    if(numBytes > 0)
    {
      rec = SrmReceive(portID, receiveBuf, numBytes, 0, &err);
    }

If I am lucky to get in bytes on my Handspring Visor (3.5.2) from my Plam
505 (4.0), but they are mangled bayond recognition.

If I look at what's sent on an infrared receiver diode on a ocsilloscope it
seems like what is sent is wrong. The number of bytes seems to be right but
the bits are somewhat random in a reproduceable way. It is not some kind of
coding, as different bytes sent can end up giving the same value on the
receiving side.

Has anybody had better luck than I doing SIR. Should I be writing directly
to the DragonBall UART registers to make this work?

-- Henrik Dalgaard


/***********************************************************************
 * FUNCTION:  AppEventLoop
 *
 * This code should send a "Hello World" message every 5 secs to another
 * Palm running the same code.
 * 
 ***********************************************************************/
UInt16 portID = 0;
char sendBuf[50];
char receiveBuf[50];
UInt32 nextHello = 0;
UInt32 nextListen = 0;
UInt32 enableRx = 0xffffffff;
char* TEST_STRING =  "Hello, World : %ld Ticks";
char gSprintfStr[299];
Boolean gDoIrComm = false; // code works when setting this true
Boolean gDisableRxOnTx = false; // setting this true does not help
Boolean gDebugIntro = false; // I get a bit extra debug info
                             // on opening if this is true

static void AppEventLoop(void)
{
  UInt16 error;
  EventType event;

  do {
    EvtGetEvent(&event, 1);
    if (TimGetTicks() > nextHello) {
      Err err = 0;
      UInt32 numBytes = 999;
      StrPrintF(sendBuf,TEST_STRING,TimGetTicks());
      if (gDisableRxOnTx){
        err = SrmControl(portID,srmCtlRxDisable,0,0);
        if (err) ErrAlertCustom(err,0,"Control Rx Disable",0);
      }
      SrmSend(portID, sendBuf, StrLen(sendBuf), &err);
      if (err) ErrAlertCustom(err,0,"Ser Send",0);
      enableRx = TimGetTicks() + 150;
      nextListen = TimGetTicks() + 250;
      nextHello = TimGetTicks() + 500;
    }
    
    if ((TimGetTicks() > enableRx) && gDisableRxOnTx)
    {
      Err err = 0;
      err = SrmControl(portID,srmCtlRxEnable,0,0);
      if (err) ErrAlertCustom(err,0,"Control / Rx Enable",0);
      enableRx = 0xffffffff;
    }
    
    if (TimGetTicks() > nextListen)
    {
      UInt32 numBytes=0;
      Err anErr;
      anErr = SrmReceiveCheck(portID, &numBytes);
      if (anErr == serErrLineErr)
      { 
        Err err;
           UInt16 lineErrs;
        UInt32 statusField;
        err = SrmGetStatus(portID, &statusField,&lineErrs);
        if (err) ErrAlertCustom(err,0,"Rx Check SrmGetStatus",0);
        StrPrintF(gSprintfStr, "Stat Field:%lx Adr:%d",
                  statusField,lineErrs);
        ErrAlertCustom(err,gSprintfStr,"Rx Check  Line Error",0);
        SrmClearErr(portID),anErr = 0;
      }
      if (anErr) ErrAlertCustom(anErr,0,"ReceiveCheck",0);
      if(numBytes > 0)
      {
        Err err;
        UInt32 rec;
          MemSet(receiveBuf, 50, 0);
          if (numBytes > 49) numBytes = 49;
           rec = SrmReceive(portID, receiveBuf, numBytes, 0, &err);
           receiveBuf[rec] = 0;
           if (err) ErrAlertCustom(err,NULL,"Receive Err:",receiveBuf);
        if (err == serErrLineErr) {
          Err err2;
             UInt16 lineErrs;
          UInt32 statusField;
          SrmClearErr(portID),anErr = 0;
          err2 = SrmGetStatus(portID, &statusField,&lineErrs);
          if (err2) ErrAlertCustom(err2,0,"Rx SrmGetStatus",0);
          StrPrintF(gSprintfStr, "Stat Field:%lx Adr:%d",
                    statusField,lineErrs);
          ErrAlertCustom(err2,gSprintfStr,"Rx Line Error",0);
          SrmClearErr(portID),err = 0;
        }
           if (rec) ErrAlertCustom(err,"Received Data:",NULL,receiveBuf);
      }
      nextListen = TimGetTicks() + 500;
    }  

    if (! SysHandleEvent(&event))
      if (! MenuHandleEvent(0, &event, &error))
        if (! AppHandleEvent(&event))
          FrmDispatchEvent(&event);

  } while (event.eType != appStopEvent);
}

/***********************************************************************
 * FUNCTION:   AppStart
 ***********************************************************************/
static Err AppStart(void)
{
  StarterPreferenceType prefs;
  DeviceInfoType devInfo;
  UInt16 prefsSize;
  UInt16 lineErrs;
  UInt32 statusField;
  UInt32 flags = 
    srmSettingsFlagBitsPerChar8 | srmSettingsFlagStopBits1 |
    srmSettingsFlagRTSAutoM;
  UInt16 length = sizeof(flags);
  Int32 ctsTimeout;
  Int32 optimalTxSz;
  UInt16 valueLen;
  
  Err err;
  // Read the saved preferences / saved-state information.
  prefsSize = sizeof(StarterPreferenceType);
  if (PrefGetAppPreferences(appFileCreator, appPrefID, &prefs,
     &prefsSize,  true) !=  noPreferenceFound)
  {
  }
  if (gDoIrComm)
    err = SrmOpen(sysFileCVirtIrComm , 9600, &portID);
  else
    err = SrmOpen(serPortIrPort    , 9600, &portID);
  if (err) ErrAlertCustom(err,0,"Open",0);
  if (!gDoIrComm){
    err = SrmControl(portID, srmCtlIrDAEnable, NULL, 0);
    if (err) ErrAlertCustom(err,0,"Control on Open",0);
  }
  nextHello = TimGetTicks() + 500;
  nextListen = TimGetTicks() + 750;
  err = SrmControl(portID,srmCtlSetFlags,&flags,&length);
  if (err) ErrAlertCustom(err,0,"Flags",0);
  err = SrmReceiveFlush(portID,10);
  if (err) ErrAlertCustom(err,0,"Receive Flush",0);
  
  if(gDebugIntro) {
    err = SrmGetDeviceInfo(portID, &devInfo);
    if (err) ErrAlertCustom(err,0,"Get Dev Infoh",0);
    StrPrintF(gSprintfStr, "%s Ftr: %lx MxBaud:%ld Mhsb:%ld",
      devInfo.serDevPortInfoStr,
      devInfo.serDevFtrInfo,
      devInfo.serDevMaxBaudRate,devInfo.serDevHandshakeBaud);
    ErrAlertCustom(err,gSprintfStr,0,0);
    
    err = SrmGetStatus(portID, &statusField,&lineErrs);
    if (err) ErrAlertCustom(err,0,"SrmGetStatus",0);
    StrPrintF(gSprintfStr, "Stat Field: %lx Adr:%d",statusField,lineErrs);
    ErrAlertCustom(err,gSprintfStr,0,0);
    
    valueLen = sizeof(Int32);
    err = SrmControl(portID, srmCtlGetCtsTimeout, &ctsTimeout, &valueLen);
    if (err) ErrAlertCustom(err,0,"srmCtlGetCtsTimeout",0);
    StrPrintF(gSprintfStr, "CtsTimeout: %ld",ctsTimeout);
    ErrAlertCustom(err,gSprintfStr,0,0);
    
    valueLen = sizeof(Int32);
    err = SrmControl(portID, srmCtlGetOptimalTransmitSize,
                     &optimalTxSz, &valueLen);
    if (err) ErrAlertCustom(err,0,"OptTrsmSz Err",0);
    StrPrintF(gSprintfStr, "OptTrsmSz:%ld",optimalTxSz);
    ErrAlertCustom(err,gSprintfStr,0,0);
  }
  return errNone;
}


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to