Shop OBEX P1 Docs P2 Docs Learn Events
Having a problem with timing — Parallax Forums

Having a problem with timing

oberocoberoc Posts: 7
edited 2005-11-10 15:12 in General Discussion
Hi,

I am using the Javelin Stamp plus the eb500 bluetooth board to transmit some signals to
a basic stamp board.

My calling code:
response=TxRx("con " + address,"cmd");
response=TxRx("get_net","data");
if (response.toString() != null) {
if (MyNetwork.equals(response.toString())) {
address=null;
}
} else {
response=TxRx("set_net " + MyNetwork,"data");
}
response=TxRx("dis","cmd");

My TxRx Method:
static String TxRx(String sendString,String mode){
StringBuffer oneBuf = new StringBuffer();
char tempChar;
if (mode == "cmd") {
System.out.println(sendString);
if (CPU.readPin(CONNECT_STATUS) == true){
if (hardbufMode() == false) {
System.out.println("Failed: Switch to buf mode\r");
}
}
}
txUart.sendString(sendString);
txUart.sendString("\r");
if (mode == "cmd") {
if (Expect.string(rxUart, "ACK\r", EXPECTDELAY)){
while ( (tempChar =(char)rxUart.receiveByte()) != '>' ) {
oneBuf.append(tempChar);
}
} else {
System.out.println("Blah");
}

}
return oneBuf.toString();
}

And the hardbuf method
static boolean hardbufMode(){

CPU.writePin(COMMAND_PIN,false);
txUart.sendString("\r");
if (Expect.string(rxUart, ">", EXPECTDELAY))
return true;
else
return false;
}

What is the problem is that when my program gets done calling sending get_net to the
TxRx method, I send a dis to disconnect from the remote board. But, in the hard buffer
method, the Expect.string(rxUart, ">", EXPECTDELAY) is not coming back with a > like it
supposed to. Now, I call the TxRx function with the cmd parameter earlier in the program
with no problem. I believe that it is some kind of timing issue. Could anybody shed some like
on this?

-Tino

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-09 20:11
    See this thread concerning the EB500.

    http://forums.parallax.com/showthread.php?p=469259

    Compare your transmission code with the code in that thread.

    regards peter
  • oberocoberoc Posts: 7
    edited 2005-11-10 14:17
    Hi Peter,

    Looked at his code. The only statement I was missing was the CPU.delay(2000). I put that in and no luck. I did however get a stack trace. Which I have include here.

    Here is the offending code:
    CPU.writePin(COMMAND_PIN,false);
    CPU.delay(5000);
    txUart.sendString("\r");
    if (Expect.string(rxUart, ">", EXPECTDELAY))
    return true;
    else
    return false;
    }

    From debug - static variables
    stamp.core.CPU pin #6 0x0040 '.@'

    rxUart.buffer is a bunch of bluetooth addresses, >, and ACKs

    Any suugestions?
  • oberocoberoc Posts: 7
    edited 2005-11-10 14:22
    Something I forgot. It seems like a problem with the rxUart buffer, because the pin 6 is going false, but the rxUart buffer is not getting the right characters in (even though the last byte is .>). Thanks.

    -Tino
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-10 15:09
    I would replace
    txUart.sendString("\r");· //this uses doublequotes
    by
    txUart.sendByte('\r');·· //this uses singlequotes

    the character '\r' is 13 decimal (CR) and I guess it makes no difference
    except that sendByte is faster code (saves time)

    regards peter
    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-10 15:12
    Have you tried a lower baudrate like 1200?

    Lower baudrates requires less cpu background time and the

    margin error in baudrate between sender and receiver is better.

    regards peter
Sign In or Register to comment.