Shop OBEX P1 Docs P2 Docs Learn Events
Little serial confusion - Page 2 — Parallax Forums

Little serial confusion

2»

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-05 12:26
    Why not leave all the bytes in and just use the index for whatever you need.
    That is easier to debug if things don't work out immediately.
    regards peter
  • arnoarno Posts: 43
    edited 2006-06-05 13:14
    It's look like i can't go into this part of the readgsm fonction:
    if ( GSMdata.charAt(2) == '+' || GSMdata.charAt(2) == '~' ) { // answer to a command
    GSMret = GSMdata.indexOf( ":" ); // Start position of the answer
    GSMdata.subString( GSMret+2, GSMindex-2, GSMcode );
    System.out.println( GSMcode.toString() );
    return 1;
    }


    even when I got an answer like that :
    GSMdata in hexbytes
    0D 0A 2B 43 52 45 47 3A 20 31 2C 30 0D 0A 0D 0A 4F 4B 0D 0A
    GSMdata in ascii bytes
    ..+CREG: 1,0....OK..

    what is wrong with my test ?
    Wha I wan't is remove the CR/LF at the start, put the answer (what is after the [noparse]:)[/noparse] to GSMcode
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-05 13:30
    Did you install the corrected StringBuffer and String class?
    Those classes installed from the downloaded installer have an error.
    See earlier post.
    regards peter
  • arnoarno Posts: 43
    edited 2006-06-05 13:33
    Yes I did.
    So now my program dosen't crash any more (thank you very mutch for your help)

    but it dosen't enter into this test.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-05 14:04
    Use GSMdata.toString().toChar()
    Also note that GSMindex is not set to end of string
    as it is not used in the code above.
    Replace it by GSMdata.length()

    regards peter
  • arnoarno Posts: 43
    edited 2006-06-05 14:39
    their is no toChar indise the string class !?!?
    And how should define wich char I want ?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-05 14:39
    Note that the Format class also has a bscanf() method,
    to parse strings.

    So if GSMdata holds
    0D 0A 2B 43 52 45 47 3A 20 31 2C 30 0D 0A 0D 0A 4F 4B 0D 0A
    which is "\r\n+CREG: 1,0\r\n\r\nOK\r\n" which has a known format for a specific command
    then you can use
    int k=0;
    int[noparse]/noparse pReg = new int[noparse][[/noparse]1];
    int[noparse]/noparse pValue = new int[noparse][[/noparse]1];
    k = Format.bscanf(GSMdata.toString(),k,"\r\n+CREG: %d",pReg); //make pReg[noparse][[/noparse]0] integervalue at %d position
    k = Format.bscanf(GSMdata.toString(),k,",%d",pValue); //make pValue[noparse][[/noparse]0] integervalue at %d position

    regards peter

    Post Edited (Peter Verkaik) : 6/5/2006 2:43:47 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-05 14:42
    Sorry, I meant GSMdata.toString().charAt()
    regards peter
  • arnoarno Posts: 43
    edited 2006-06-05 19:06
    Hmm yes that's good.
    thank you very much for all your help.

    I will look tomorrow for the next step:

    GSP part and SMS

    By the way I don't to make a bscanf for the +CREG message, since I have other message that will givbe me an answer. so I
    try to make as universal as possible.

    best regards

    arno
Sign In or Register to comment.