×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    File access frequently by two program

    Hello!

    We are developing a project invloving two seperate programs, a bluetooth(BT) connection program and application program(program A). In order to pass received BT data from a bluetooth device, we use file I/O skills, that is saving those data to several 'txt', says data.txt...etc. While the BT program is writing those files, program A will read those files for data processing and displaying. And now we have encountered the following problems.

    1> while BT program and program A is running at the same time, the data wrote to those file seems distorted. Let's say, the BT data that is written to the file is '98', but actual value storing in that 'txt' file is '0'.

    2> Orginally, BT program writing frequency is 3 times per second, and program A reading frequency is 2 time per second. In this case, the mobile crashed immediately after 2 programs run. After reducing the frequency or reading and writing, the problem happened after serveral seconds. Once the data is distorted, the problem keeps going on.

    In addtiton, the constrain here is the fileIO rate cannot be too low and the data receiving rate of BT program cannot be changed, therefore we have no idea how to solve the problems.

    Hope that someone can help us...^.^

    Thanks in advance!

  2. #2
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: File access frequently by two program

    are both apps reading and writing using the same charset and encoding?
    Jason Glass
    http://IChiBanComputers.Com

  3. #3
    Regular Contributor
    Join Date
    May 2005
    Location
    Tokyo
    Posts
    365

    Re: File access frequently by two program

    hi, whynot use the Observer-Mode.
    1,write BT date into a file
    2,writing complete,then notify program A to read data from that file

    "BT program writing frequency is 3 times per second, and program A reading frequency is 2 time per second. "
    sorry,i think this way isnt the best........
    however,if u open a file for reading and writing with read and write shared access, use:
    "file.Open(FS,NAME,EFileWrite|EFileShareAny)"
    plz.

    good luck
    Last edited by SymbianLN; 2006-03-30 at 02:19.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Re: File access frequently by two program

    Quote Originally Posted by SymbianLN
    hi, whynot use the Observer-Mode.
    1,write BT date into a file
    2,writing complete,then notify program A to read data from that file
    these things are exactly what i want to do, however i am not familiar about the Observer-Mode, so could u pls post some example code to let me know how to use it..

    THX..

  5. #5
    Regular Contributor
    Join Date
    May 2005
    Location
    Tokyo
    Posts
    365

    Re: File access frequently by two program

    i just wrote some code,wish it to be helpful.........
    class MObserver
    {//Observer class
    public:
    virtual void WriteComplete() = 0;
    }

    class CAppA : public CBase , public MObserver
    {// Application which read from file
    public: // From MObserver
    void WriteComplete();
    private:
    void ConstructL();
    CAppB* iAppB;
    }

    void CAppA::WriteComplete()
    {
    //Read from file
    }

    void CAppA::ConstructL()
    {
    //iAppB is AppB`s pointer;
    iAppB->SetObserver(this);
    }


    class CAppB : public CBase
    {//application which write into file
    public:
    void WriteFileL();
    void SetObserver(MObserver* aObserver);
    private:
    MObserver* iObserver;
    }

    void CAppB::WriteFileL()
    {
    //Write into file
    iObserver->WriteComplete();// write complete
    }
    void CAppB::SetObserver(MObserver* aObserver)
    {
    iObserver = aObserver;
    }

    good luck

  6. #6
    Regular Contributor
    Join Date
    May 2005
    Location
    Tokyo
    Posts
    365

    Re: File access frequently by two program

    sorry,,,,,,by the way
    if u use "file.Open(FS,NAME,EFileWrite|EFileShareAny)"
    i think u can do as "BT program writing frequency is 3 times per second, and program A reading frequency is 2 time per second. "

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Re: File access frequently by two program

    Thank you, I have use "EShareAny" in the code but the two programs still crash. I am not quite sure about the reason but the BT program indeed give a heavy fileIO loading to the system since BT acutally writing approx. 2 files with frequency 2 times per sec. and 3 other files per 3 sec.

    For the "Observer" method, i would like to ask if program A needs to check continuously if BT program finished writing? If yes, there still have chance to crash, but is on that observer file instead.


    thank you.

  8. #8
    Regular Contributor
    Join Date
    May 2005
    Location
    Tokyo
    Posts
    365

    Re: File access frequently by two program

    " i would like to ask if program A needs to check continuously if BT program finished writing? "
    the answer is "NO" (^&^)
    when BT program finishes writing,itself(BT) calls programA`s method(WriteComplete) to notify programA that A can read from file.
    programA doesnt care if the BT finished writing.

  9. #9
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: File access frequently by two program

    To be quite honest you are going to have to use something like a Semaphore or Mutex and use that to get a read or write lock on the file, this will prevent overlaps where one proccess is reading and another it writing.

    Alternativly you could use the queuing architecture RMsgQueue if you are using OS9
    or the Client Server architecture to mediate between the BT and application processes for any version of symbian

Similar Threads

  1. How to include and load a png file in a program?
    By tomsoft in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2006-03-04, 17:33
  2. File access using J2ME in 3650
    By rave_symbian in forum Mobile Java General
    Replies: 1
    Last Post: 2005-12-16, 16:20
  3. JSR75 file access -- URGENT
    By earamsey in forum Mobile Java General
    Replies: 5
    Last Post: 2005-10-20, 08:25
  4. How to get a web page file by a program in 9210?
    By wu_genqing in forum Symbian
    Replies: 0
    Last Post: 2003-07-28, 08:14
  5. Can not run file manager program
    By agsapt in forum Symbian
    Replies: 0
    Last Post: 2002-08-27, 07:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×