Having a problem with timing
oberoc
Posts: 7
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
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
http://forums.parallax.com/showthread.php?p=469259
Compare your transmission code with the code in that thread.
regards 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?
-Tino
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
·
Lower baudrates requires less cpu background time and the
margin error in baudrate between sender and receiver is better.
regards peter