×

Discussion Board

Results 1 to 12 of 12

Hybrid View

  1. #1
    Registered User
    Join Date
    Feb 2007
    Posts
    18

    Using Bluetooth serial port in MIDlets (nokia 9500 issue)

    Hi,

    I've created a midlet that reads data from a bluetooth GPS. It works perfectly on for example Nokia 6600, but gives the error message below on nokia 9500:

    Reason code: E32USER-CBase
    Number Code:40

    I googled on this and found the issue below:

    KIJ000109
    Another issue is that the InputStream cannot use a bigger byte array than 512 bytes when reading stream. A bigger byte array may crash the MIDlet.
    Solution to the stream size issue: Do not use a bigger byte array than 512 bytes. Read the input stream in a loop or keep the whole length of the stream under 512 bytes.(http://forum.nokia.com/document/Forum_Nokia_Technical_Library/contents/FNTL/Using_Bluetooth_serial_port_in_MIDlets.htm)

    I consider this a very likely reason, because my midlet gets data continously from the GPS so it may happen that this limit is exceeded.

    My question is: how should I modify my code to avoid this error? The data is coming continously from the GPS so I guess I can't limit the input. I'm thinking about reseting regularly somehow the inputstream, but couldn't figure out how to do this.
    I would greatly appreciate any suggestions on this.
    Here is my code to modify:

    // connecting to BT GPS device
    public void connect()
    {
    state = CONNECTING;
    try
    {
    // kapcsolodas
    connection = (StreamConnection) Connector.ope(serviceURL, Connector.READ);
    reader = new InputStreamReader(connection.openInputStream());

    }
    catch (IOException ex)
    {
    ex.printStackTrace();
    midlet.Dump(StrErrorConnFailed);
    }

    }

    // continous reading from BT GPS device
    public void run()
    {

    // folyamatos adatolvasas
    try
    {
    String data="";
    int c;

    while((c=reader.read())!= LINE_DELIMITER)
    {
    data += (char)c;
    }

    btm.appendRawData(data);

    }

    catch (IOException ex)
    {
    midlet.Dump(ex.getMessage());
    }


    }

    Thanks a lot!
    Örs

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Using Bluetooth serial port in MIDlets (nokia 9500 issue)

    Hi Ors,

    If i got it right you can use the public int read(char[] cbuf,
    int off,
    int len)
    throws IOException
    method of InputStreamReader class instead of the no-arg version, read(). Just provide the array with size equals to 512 and add to secondary buffer as required while in the loop. I am not sure if it's going to work properly as it's related to a known Nokia issue, though.

    Please do not crosspost as below and create your own threads (no hijacking) as well so this forum will be kept organized, ok?
    http://discussion.forum.nokia.com/fo...ad.php?t=87666

    Hope this helps
    Juarez Alvares Barbosa Junior - Brazil

  3. #3
    Registered User
    Join Date
    Feb 2007
    Posts
    18

    Re: Using Bluetooth serial port in MIDlets (nokia 9500 issue)

    Hi,

    Juarez, thanks for your answer! According to your recommendation I managed to avoid the error mentioned below. Unfortunately the problem is not solved, I ran into another error: Program: jes-232-java-comms, Reason code: KERN-EXEC, Reason number: 3

    So I created a demo code to isolate this error. It is caused by the "read" line with bold. Any idea what is the reason, or how to avoid it? I know that this code has to work somehow, because I found and decompiled another midlet, and it runs perfectly with similar code (unfortunately it was obfuscated).

    Let me know if you have any idea how to move forward with this!
    Thanks a lot!
    Örs

    Here is the test code:

    public void run()
    {
    if (!isConnected()) connect();
    try
    {
    int n=0;
    if (stream!=null)
    {
    n = stream.available();
    if (n>2048) stream.skip(n);
    else
    {
    int i = 0;
    int c;
    // the line below causes panic error (Reason code: KERN- EXEC, Reason number: 3) after run a couple of times
    while ((c=stream.read()) >-1)
    {
    i++;
    if ((c==LINE_DELIMITER)||(i>=256)) break;
    // do something with the data
    }
    }
    }
    }
    catch (Throwable th)
    {
    midlet.Dump("skip'n'read error: " + th.toString());
    }
    }
    Last edited by orsteglasy; 2007-02-28 at 23:32.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    1

    Re: Using Bluetooth serial port in MIDlets (nokia 9500 issue)

    Hi Ors,

    Have you tried doing what juarezjunior recommended? If i read your requirment correctly, it would look something like this:

    Code:
    byte[] buffer = new byte[512];
    int c;
    while ((c=stream.read(buffer, 0, 512)) != -1) 
    {
        // do something with buffer here
    }
    Hth

  5. #5
    Registered User
    Join Date
    Feb 2007
    Posts
    18

    Re: Using Bluetooth serial port in MIDlets (nokia 9500 issue)

    Hi,

    Yes, I tested the code recommended by Juarez, but it gives the same error message as in the first post (E32USER-CBase, 40). Then I tried to use the code shown in my previous post, it's from a decompiled midlet, which do the same task perfectly on nokia 9500. I really don't understand the situation because we have the same read-code but my midlet crashes the other one doesn't, so there must be a solution for this. Do you have any idea what other factors may influence this behavior? Or how is it possible to "debug" this error, and figure out the fix?

    I would really appreciate your help!
    Thanks!
    Örs

  6. #6
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Using Bluetooth serial port in MIDlets (nokia 9500 issue)

    Hi Örs,

    Nice to know you managed to solve your first problem.

    "I ran into another error: Program: jes-232-java-comms, Reason code: KERN-EXEC, Reason number: 3 "
    I am not sure but it seems to be an error by the low-level implementation. Let's see if someone else can help you this time.

    Best,
    Juarez Alvares Barbosa Junior - Brazil

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2003
    Posts
    4,105
    I try to debug this issue, too. Is that other non-affected MIDlet using L2CAP or SPP, too?

Similar Threads

  1. ###Upgrading Firmware###
    By zahid44 in forum General Development Questions
    Replies: 27
    Last Post: 2008-10-21, 07:17
  2. Nokia Mobile VPN Client
    By marcyl in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2003-12-01, 14:47
  3. Nokia 6310i bluetooth link with Sony laptop
    By MikeCrouch in forum Bluetooth Technology
    Replies: 1
    Last Post: 2002-10-30, 16:48

Posting Permissions

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