NotifyDataAvailable() in RComm & RunL() not working

Login to reply to this topic.
Thu, 2008-02-28 15:20
Joined: 2007-12-01
Forum posts: 10

Greetings newLC members,

I will be thankful if you please help me to resolve the following problem.
My application is listening on serial port for any incoming data over serial port.
Problem is RunL() is not being called when the data arrives on the serial port
The code snippet is below.

//SerialListener.h

class CSerialListener : public CActive
{
public:
        // C++ constructor
        CSerialListener();
        static CSerialListener* NewL();
        static CSerialListener* NewLC();
        // Second-phase constructor
        void ConstructL();
        // Cancel and destroy
        ~CSerialListener();

public: // New functions
        // Function for making the initial request
        void InitializeL();
        void StartListenerL();

private: // From CActive
        // Handle completion
        void RunL();
       
        // How to cancel me
        void DoCancel();
       
        // Override to handle leaves from RunL(). Default implementation causes
        // the active scheduler to panic.
        //TInt RunError(TInt aError);

private:
        RCommServ iCommServer;
        RComm iCommPort;
        TRequestStatus readStat;
        TBuf8 <5> localInputBuffer;
};





//SerialListener.cpp impementation

CSerialListener::CSerialListener() :
CActive(EPriorityStandard)
{
CActiveScheduler::Add(this);
}

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

void CSerialListener::ConstructL()
{       
}

void CSerialListener::InitializeL()
{

        ......
        ......
        //Load logical & physical drivers
        //Connect with the comm server
        //Opens the RComm iCommPort ACM::0
       
}

CSerialListener::~CSerialListener()
{
        Cancel(); // Cancel any request, if outstanding
        iCommPort.Close();
        iCommServer.Close();       
}

void CSerialListener::StartListenerL()
{
        Cancel();                // Cancel any request, just to be sure
        iCommPort.NotifyDataAvailable(iStatus);
        SetActive();        // Tell scheduler a request is active
        console->Printf(_L("StartL Notify Called"));
       
}

void CSerialListener::RunL()
{
        console->Printf(_L("\n RunL called"));
        console->Getch();
        TBuf8 <10> aDes;
        iCommPort.ReadOneOrMore(readStat,aDes);
        User::WaitForRequest(readStat);
        if(status != KErrNone)
        iCommPort.ReadCancel();
        iCommPort.NotifyDataAvailable(iStatus);        // Set for 1 sec later
        SetActive();        // Tell scheduler a request is active
}

Your suggestions are welcome.

With Kind regards
Parveen Bhatia.


Thu, 2008-02-28 17:25
Joined: 2007-09-23
Forum posts: 132
Re: NotifyDataAvailable() in RComm & RunL() not working

Presumably this isn't a GUI app so have you started the active schuduler?

Fri, 2008-02-29 08:23
Joined: 2007-12-01
Forum posts: 10
Re: NotifyDataAvailable() in RComm & RunL() not working

Thanks for reply Numpty Alert,

I am calling above active object from the console application & i have installed the Active Scheduler.
The calling code is shown below.

LOCAL_C void DoStartL()
        {
        // Create active scheduler (to run active objects)
        CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
        CleanupStack::PushL(scheduler);
        CActiveScheduler::Install(scheduler);
        CSerialListener* iSerialListener= CSerialListener::NewLC();
        iSerialListener->InitializeL();
        iSerialListener->StartListenerL();
        for(;;)
                {
                User::After(1000000);
                }
       
        // Delete serial Listener & active scheduler
        CleanupStack::PopAndDestroy(2);
        }

GLDEF_C TInt E32Main()
        {
        // Create cleanup stack
        __UHEAP_MARK;
        CTrapCleanup* cleanup = CTrapCleanup::New();
        TRAPD(mainError, DoStartL());
        delete cleanup;
        __UHEAP_MARKEND;
        return KErrNone;
        }

RunL() is not being called when th data is available.
If there is anything wrong then please help me.

Fri, 2008-02-29 22:48
Joined: 2007-09-23
Forum posts: 132
Re: NotifyDataAvailable() in RComm & RunL() not working

I didn't say have you installed an active scheduler, I said have you started one.

P.S.
What on earth is this?

for(;;)
{
User::After(1000000);
}

I think you had better read item number 8:
http://www.newlc.com/topic-13580

Mon, 2008-03-03 08:44
Joined: 2007-12-01
Forum posts: 10
Re: NotifyDataAvailable() in RComm & RunL() not working

Thanks Numpty,

I have seen the link and it is very helpful for all members.
I don't want to Start the active scheduler because i have to
execute another code statements inside my loop...

for(;;)
{

//Program statements
User::After(1000000);
}

I just want to be notified when the data is available & handle this data
in RunL() and if data is not available above loop statements will perform
their function.

I think this is possible but code never enters RunL().
What may be the reason?

Tue, 2008-03-04 00:09
Joined: 2007-09-23
Forum posts: 132
Re: NotifyDataAvailable() in RComm & RunL() not working

In the same sentence you said you don't want to start the active scheduler and your RunL doesn't enter.
You can't have your cake and eat it.

Reread that post, you have got to stop thinking in terms of loops and realise you are writing for a real time system. If you have to write a loop you have done something wrong.

Tue, 2008-03-04 09:44
Joined: 2007-12-01
Forum posts: 10
Re: NotifyDataAvailable() in RComm & RunL() not working

I realized my mistake, all works well when i started my Active Scheduler.
Thanks for your kind help.

Mon, 2008-06-16 09:27
Joined: 2007-11-12
Forum posts: 2
Re: NotifyDataAvailable() in RComm & RunL() not working

How did you start your Active Scheduler?

I don't understand too,could you give more detail?

Thanks!

  • Login to reply to this topic.