Problem with IrDA

Login to reply to this topic.
Thu, 2005-01-27 10:20
Joined: 2005-01-04
Forum posts: 14
Hello everybody

I am trying to transfer files through IrDA. I have opened a socket and socket server. But i am not able search for nearby devices. For bluetooth there are classes for service searcher...is there any similar class for IrDA also??Can anybody plz help me out in this...

Thanks a lot
Prathima

Mon, 2005-01-31 05:53
Joined: 2004-07-08
Forum posts: 13
Problem with IrDA
If I am clear with your requirement, I used RHostResolver class to discover the IRDA device within line of sight. make sure you place your IRDA device in Line with the device you want to connect with..

Probably this helps Roll Eyes

Cheers,
Achilles
Mon, 2005-01-31 06:04
Joined: 2005-01-04
Forum posts: 14
Problem with IrDA
Hi

Yes i am using RHostResolver class for this but after getting the host name and address i get a E32User-CBase 46 error....
my code looks like this....


ret=iHostResolver.Open(iSockSrv,tinyTpInfo.iAddrFamily,tinyTpInfo.iProtocol);
      if (ret!=KErrNone)
      {
         //no protocol found/busy
      }          
      // Get host by name
      THostName name;
      iHostResolver.GetByName(name,iLog,iStatus);
      iState = EGettingDevice;
      _LIT(KErrMsg,"got host address");
      _LIT(KApp, "host opened");
      CEikonEnv::Static()->InfoWinL(KErrMsg, KApp);
      SetActive();

after getting the InfowinL message i get the above mentioned error...
and i place both the devices in the line of sight....

plz tell me what the problem might be at the earliest....

Thanks
Prathima
Mon, 2005-01-31 06:53
Joined: 2004-07-08
Forum posts: 13
Problem with IrDA
Quote from: prathima
Hi

Yes i am using RHostResolver class for this but after getting the host name and address i get a E32User-CBase 46 error....
my code looks like this....


ret=iHostResolver.Open(iSockSrv,tinyTpInfo.iAddrFamily,tinyTpInfo.iProtocol);
      if (ret!=KErrNone)
      {
         //no protocol found/busy
      }          
      // Get host by name
      THostName name;
      iHostResolver.GetByName(name,iLog,iStatus);
      iState = EGettingDevice;
      _LIT(KErrMsg,"got host address");
      _LIT(KApp, "host opened");
      CEikonEnv::Static()->InfoWinL(KErrMsg, KApp);
      SetActive();

after getting the InfowinL message i get the above mentioned error...
and i place both the devices in the line of sight....

plz tell me what the problem might be at the earliest....

Thanks
Prathima


Hi,
  the problem might be related to 1. the cactive request is not handled properly. 2. I haven't worked with the UI for displaying stuff. I used logs for trapping the msg/. I suggest you use User::WaitForRequest() immediately after iHostResolver.GetByName(name,iLog,iStatus); and remove the setActive that is present after displaying the dialog.
3. If the method in which your code is present is a CActive inherited, then place setactive after iHostResolver.GetByName(name,iLog,iStatus); ..

Hope the suggestions might be helpful.. User::base 46 may occur for differnet reasons, but a common aspect might be with handling of CActive Objects[or dealing with asynchronous requests]

Cheers,
Achilles
Mon, 2005-01-31 08:10
Anonymous (not verified)
Forum posts: 2043
Problem with IrDA
Hi

Thanks a lot for your patience but there is still a problem....
I have tried removing setactive and i used User::WaitForRequest(iStatus).
When it comes to this point there is nothing happening after this....no message is displayed after this....it is not going into the next state also...
i have enabled irda on both the devices....and i m placing them facing the irda ports.....is this not the way we do???

My method actually is inherited from CActive but still i tried using the above method...
Any suggestions???

Thanks
Prathima
Mon, 2005-01-31 09:10
Joined: 2004-07-28
Forum posts: 1379
Problem with IrDA
It's the InfoWinL.

Which enters a inner scheduler loop.

And you have called GetByName, but not yet called SetActive.

Either do this:

ret=iHostResolver.Open(iSockSrv,tinyTpInfo.iAddrFamily,tinyTpInfo.iProtocol);
if (ret!=KErrNone)
{
//no protocol found/busy
}
// Get host by name
THostName name;
iHostResolver.GetByName(name,iLog,iStatus);
iState = EGettingDevice;
SetActive();  

_LIT(KErrMsg,"got host address");
_LIT(KApp, "host opened");
CEikonEnv::Static()->InfoWinL(KErrMsg, KApp);

Or, move the InfoWinL to your RunL.

didster

Mon, 2005-02-14 11:00
Joined: 2005-01-04
Forum posts: 14
Problem with IrDA
Hi

My IrDA problem still exists...it says connection error....my code looks sth like this....plz do help me...

const TUint KNumOfDevicesToDiscover = 1;
const TUint KPortNumber = 0x02;
_LIT(KDev,"got device");
_LIT(KDisc, "getting connection ");
_LIT(KDevMsg,"getting device");
_LIT(KDiscApp, "before discovery");
_LIT(Kb4addrMsg, "before getting address");
      

CObjectExchangeClientIrD* CObjectExchangeClientIrD::NewL()
{
   CObjectExchangeClientIrD* self = NewLC();
   CleanupStack::Pop(self);
   return self;
}

CObjectExchangeClientIrD* CObjectExchangeClientIrD::NewLC()
{
   CObjectExchangeClientIrD* self = new (ELeave) CObjectExchangeClientIrD();
   CleanupStack::PushL(self);
   self->ConstructL();
   return self;
}

CObjectExchangeClientIrD::CObjectExchangeClientIrD()
: CActive(CActive::EPriorityStandard),
iState(EWaitingToGetDevice)
{
   CActiveScheduler::Add(this);
}


void CObjectExchangeClientIrD::ConstructL()
{
   
   iCurrObject = CObexFileObject::NewL();
}

CObjectExchangeClientIrD::~CObjectExchangeClientIrD()
{
   
   delete iCurrObject;
   iCurrObject = NULL;
   
   if (iState != EWaitingToGetDevice && iClient)
   {
       iClient->Abort();
      iStatus = KErrNone;
   }
   
   Cancel();
   
   delete iCurrObject;   
   iHostResolver.Close();
   iSockSrv.Close();
   iSock.Close();
   delete iClient;
}

void CObjectExchangeClientIrD::DoCancel()
{
}

void CObjectExchangeClientIrD::ErrorL(const TDesC& aErrText)
{
   CAknErrorNote* note = new (ELeave) CAknErrorNote(ETrue);
   note->ExecuteLD(aErrText);
}

void CObjectExchangeClientIrD::RunL()
{
   if (iStatus != KErrNone)
   {
       switch (iState)
      {
      case EGettingDevice:
         if (iStatus == KErrCancel)
         {
            ErrorL(_L("No device selected"));
         }
         iState = EWaitingToGetDevice;
         break;
      case EGettingService:
      case EGettingConnection:
      case EDisconnecting:
         ErrorL(_L("Connection error "));
         iState = EWaitingToGetDevice;
         break;
      case EWaitingToSend:
         ErrorL(_L("Send error "));
         iState = EWaitingToGetDevice;
         break;
      default:
         Panic(EBTObjectExchangeUnexpectedLogicState);
         break;
      }
   }
   else
   {
       switch (iState)
      {
      case EGettingDevice:
      /* // found a device now search for a suitable service
      //iLog.LogL(iServiceSearcher->ResponseParams().DeviceName());
      iState = EGettingService;
      iStatus = KRequestPending; // this means that the RunL can not be called until
      // this program does something to iStatus
      //iServiceSearcher->FindServiceL(iStatus);
         SetActive();*/
         CEikonEnv::Static()->InfoWinL(Kb4addrMsg, Kb4addrMsg);
         iState = EGettingConnection;
         //iHostResolver.Close();
         // Store remote device address
         iIrdaSockAddr = TIrdaSockAddr(iLog().iAddr);
         
      CEikonEnv::Static()->InfoWinL(KDevMsg, KDiscApp);
         ConnectAfterDiscL();
         break;
         
      case EGettingService:
         iState = EGettingConnection;
         ConnectToServerL();
         break;
         
      case EGettingConnection:
         
      
      CEikonEnv::Static()->InfoWinL(KDev, KDisc);
         SendObjectL();
         iState = EWaitingToSend;
         break;
         
      case EWaitingToSend:
         DisconnectL();
         break;
         
      case EDisconnecting:
         iState = EWaitingToGetDevice;
         break;
         
      default:
         Panic(EBTObjectExchangeSdpRecordDelete);
         break;
      };
   }
}


void CObjectExchangeClientIrD::ConnectL()
{
   
   if (iState == EWaitingToGetDevice && !IsActive())
   {
      
      User::LeaveIfError(iSockSrv.Connect());
      
      _LIT(KSerApp, "socket server opened");
      CEikonEnv::Static()->InfoWinL(KSerApp, KSerApp);
      TUint numProtocols;
      // Number of protocols socket server is aware of
      TInt err = iSockSrv.NumProtocols(numProtocols);
      User::LeaveIfError(err);
      
      TProtocolName KTinyTP = _L("IrTinyTP");
      TProtocolDesc tinyTpInfo;
      TInt ret=User::LeaveIfError(iSockSrv.FindProtocol(KTinyTP, tinyTpInfo));
      
      ret = iSock.Open(iSockSrv, tinyTpInfo.iAddrFamily, tinyTpInfo.iSockType, tinyTpInfo.iProtocol);
      if(ret != KErrNone && ret != KErrAlreadyExists)
      {
         User::Leave(ret);
      }
      TPckgBuf<TUint> buf(KNumOfDevicesToDiscover);
      iSock.SetOpt(KDiscoverySlotsOpt, KLevelIrlap, buf);
      _LIT(KSockMsg,"socket opened");
         CEikonEnv::Static()->InfoWinL(KSockMsg, KSockMsg);
      ret=iHostResolver.Open(iSockSrv,tinyTpInfo.iAddrFamily,tinyTpInfo.iProtocol);
      if (ret!=KErrNone)
      {
         //no protocol found/busy
      }          
      // Get host by name
      THostName name;
      iHostResolver.GetByName(name,iLog,iStatus);
      iState = EGettingDevice;
   /*   _LIT(KErrMsg,"got host address");
      _LIT(KApp, "host opened");
      CEikonEnv::Static()->InfoWinL(KErrMsg, KApp);*/
      SetActive();
   }
   else
   {
       User::Leave(KErrInUse);
   }
}

void CObjectExchangeClientIrD::ConnectAfterDiscL()
{
   iIrdaSockAddr.SetPort(KPortNumber);
   
   iSock.Connect(iIrdaSockAddr, iStatus);
   /*   _LIT(KConnMsg,"connected");
      _LIT(KSockApp, "socket connected");
      CEikonEnv::Static()->InfoWinL(KConnMsg, KSockApp);*/
      iState = EGettingConnection;
   SetActive();
}


void CObjectExchangeClientIrD::ConnectToServerL()
{
   TObexIrProtocolInfo protocolInfo;
   protocolInfo.iAddr = iLog().iAddr;
   protocolInfo.iAddr.SetPort(iLog().iAddr.Port());
   protocolInfo.iTransport = _L("IrTinyTP");
   protocolInfo.iClassName = _L8("OBEX");;
   protocolInfo.iAttributeName =_L8("IrDA:TinyTP:LsapSel");
   
   if (iClient)
   {
       delete iClient;
       iClient = NULL;
   }
   iHostResolver.Close();
   iSockSrv.Close();
   
   
   iClient = CObexClient::NewL(protocolInfo);
   
   iClient->Connect(iStatus);
   _LIT(KProtoMsg,"protocol connected");
   //   _LIT(KApp, "socket opened");
      CEikonEnv::Static()->InfoWinL(KProtoMsg, KProtoMsg);
   SetActive();
}

void CObjectExchangeClientIrD::SendObjectL()
{
   if (iState != EWaitingToSend)
   {
       User::Leave(KErrDisconnected);
   }
   else if (IsActive())
   {
       User::Leave(KErrInUse);
   }

   _LIT(KBSendMsg,"before sending");
   CEikonEnv::Static()->InfoWinL(KBSendMsg, KBSendMsg);

   iCurrObject->InitFromFileL(iPath);
   iClient->Put(*iCurrObject, iStatus);

   _LIT(KASendMsg,"after sending");
   CEikonEnv::Static()->InfoWinL(KASendMsg, KASendMsg);
   SetActive();
}

void CObjectExchangeClientIrD::StopL()
{
   if (iClient && iClient->IsConnected())
   {
       iClient->Abort();
       iState = EWaitingToGetDevice;
   }
}

void CObjectExchangeClientIrD::DisconnectL()
{
   if (iState == EWaitingToGetDevice)
   {
       return;
   }
   if (iState == EWaitingToSend)
   {
       iState = EDisconnecting;
       iClient->Disconnect(iStatus);
       SetActive();
   }
   else
   {
       User::Leave(KErrInUse);
   }
}

TBool CObjectExchangeClientIrD::IsBusy()
{
   return IsActive();
}

TBool CObjectExchangeClientIrD::IsConnected()
{
   return iState == EWaitingToSend;
}

void CObjectExchangeClientIrD::SetFullNameL(TDesC& aFilePath)
{
   
   iPath=aFilePath;
}
Wed, 2006-07-19 11:04
Joined: 2005-08-26
Forum posts: 38
Re: Problem with IrDA
Hi 

Prathima  did you  made  the above  code worked   i mean  can you send a file from mobile to  mobile or mobile  to  pc via  infrared  can you  help me in tht  i  tried your code but  was not sucessful  can  you  help  me  in this
Wed, 2006-09-13 10:23
Joined: 2005-08-26
Forum posts: 38
Re: Problem with IrDA
Hi    if  you  go any   check  the release notes  or known  issue  for series60  3rd addition you  will  find that   they have mentioned 

There  is  a  problem  with  sending a file  via   IRda  so  all  our efforts were  in vein   

With  Regards
Bharat
  • Login to reply to this topic.