Shop OBEX P1 Docs P2 Docs Learn Events
code?? - Page 2 — Parallax Forums

code??

2»

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-30 06:46
    More like this:

    try {
    while (inputStream.available() > 0) {
    if (readBuffer == 0x11){//javilen requests stuff
    if (st.hasMoreTokens()){
    outputStream.write(0x12); //send 0x12
    if (index == cmdlen){
    outputStream.write(0x0D); //send CR
    index++;
    }
    else if (index == cmdlen + 1) {
    outputStream.write(0x0A); //send LF
    cmd = false;
    index = 0;
    cmdlen = 0;
    }
    else {
    · outputStream.write(st.nextToken()); //send data byte
    · index++;
    }

    But you really must implement the whole state machine as in my code.
    The javelin may transmit 0x11 inside <messagedata> (see protocol description)
    which in that case IS NOT A REQUEST for data. Also remember that anything that
    the PC transmits to the Javelin, is immediately echoed back to the PC.

    regards peter
    ·
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-08-30 15:18
    well the program that i am writing only reads the input stream if it equals 0x11 if the control signal is echoed back it would be 0x12 (byte) so it would disreguard it. You said however that the javelin may transmit 0x11 in the middle of message data. Is there any way to fix this problem I was thinking maybe having another tokenizer set on the input to search for 0x11 would this work? I am assuming that if it transmits 0x11 in the message data then it won't be recognized by the program.-Adam
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-08-30 15:49
    Would this be a correct implementation of the tokenizer on the input?-Adam

    try {
    ···················· while (cmd==true) {
    ···················· while (input.hasMoreTokens()) {
    ····· token = input.nextToken();
    ····· if (token == 0x11) {
    ········ break;
    ········ }
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-30 17:23
    More like:

    try {
    ···· while (input.hasMoreTokens()) {
    ······· token = input.nextToken();
    ······· if (token == 0x11) {
    ········· if (cmd==true) {
    ··········· ·break; //send 0x12,CR or 0x12,LF or 0x12,databyte
    ··········}
    ········· else {
    ··········· break; //send 0x13
    ········· }
    ······· }
    ····· }
    ·}


    but ONLY and ONLY if you never transmit 0x11 inside a message AND your PC
    program never responses with a databyte· value 0x11.

    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-08-31 02:33
    ok well i have set up the javelin so that it never transmits any data that i know of unless if it echoes the message sent to it. The control signals to the stamp are chars such as a, s, d, f and the like and are separated by the program using a string tokenizer and then transmitting them separately with 0x11 in front of them. I tried to setup the dataflow one way so that the data goes to the javelin and not back but as you said previously it echoes the commands. Can the request from the stamp get embedded in the echo so that I would need a tokenizer on the inputstream to identify 0x11? Thanks!-Adam
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-31 05:14
    Any data send by the javelin to the pc does NOT get echoed back to javelin.

    Only data send by pc to the javelin gets echoed back to the pc.

    regards peter
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-08-31 15:29
    Would 0x11ever be transmitted in an echo? The program only sends data to the stamp it is written to ignore anything else besides 0x11. Adam
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-31 16:36
    No, unless your pc program sends 0x11.

    But you said you only transmit letters like d,f etc. so

    no problem there.

    regards peter
Sign In or Register to comment.