Problem with IrDA
| Thu, 2005-01-27 10:20 | |
|
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 |
|






Forum posts: 13
Probably this helps
Cheers,
Achilles
Forum posts: 14
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
Forum posts: 13
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
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
Forum posts: 1379
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
Forum posts: 14
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;
}
Forum posts: 38
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
Forum posts: 38
There is a problem with sending a file via IRda so all our efforts were in vein
With Regards
Bharat