serial between javalins....
Hi,
Anybody else had a problem sending and recieving between two javalins? My byte gets recieved as a signed byte, i.e. I send 254 and get 2 out....
· static Uart RS485RX = new Uart(Uart.dirReceive,CPU.pin0,Uart.dontInvert, Uart.speed9600,Uart.stop1);
· static Uart RS485TX = new Uart(Uart.dirTransmit,CPU.pin1,Uart.dontInvert, Uart.speed9600,Uart.stop1);
· .... transmitt code....
· while (true)
· {
····· RS485TX.sendByte(254);·
····· CPU.delay(10000);
··}
and
· ....·recieve code....
· static int data = 0;·
··· while (true)
··· {
····· while (RS485RX.byteAvailable() == true)
····· {
······· data = (int) RS485RX.receiveByte();
······· System.out.print(data);
······}
····}
James
Post Edited (Javalin) : 9/16/2005 6:08:37 PM GMT
Anybody else had a problem sending and recieving between two javalins? My byte gets recieved as a signed byte, i.e. I send 254 and get 2 out....
· static Uart RS485RX = new Uart(Uart.dirReceive,CPU.pin0,Uart.dontInvert, Uart.speed9600,Uart.stop1);
· static Uart RS485TX = new Uart(Uart.dirTransmit,CPU.pin1,Uart.dontInvert, Uart.speed9600,Uart.stop1);
· .... transmitt code....
· while (true)
· {
····· RS485TX.sendByte(254);·
····· CPU.delay(10000);
··}
and
· ....·recieve code....
· static int data = 0;·
··· while (true)
··· {
····· while (RS485RX.byteAvailable() == true)
····· {
······· data = (int) RS485RX.receiveByte();
······· System.out.print(data);
······}
····}
James
Post Edited (Javalin) : 9/16/2005 6:08:37 PM GMT
Comments
JMLStamp2p
//Code for the receiving end
import stamp.core.*;
public class Main_Receiver{
// final static int dirReceive = 0;
// final static int speed = 9600;
// final static boolean dontInvert = true;
// final static int stop1 = 0;
final static int dataPin = CPU.pin4;
static Uart rxUart = new Uart ( Uart.dirReceive, dataPin, Uart.dontInvert, Uart.speed2400, Uart.stop1 );
static char[noparse]/noparse buffer = new char[noparse][[/noparse]7];
static int SpeechCode;
static int bufindex=0;
static void bufferMessage(){
SpeechCode = 0xff;
//treat \r as newline
while (SpeechCode != '\n'){
if (rxUart.byteAvailable()){
SpeechCode = rxUart.receiveByte();
if (SpeechCode == '\r') SpeechCode = '\n'; //easier for printing
buffer[noparse][[/noparse]bufindex++] = (char)SpeechCode;
}
}
buffer[noparse][[/noparse]bufindex]=0;
bufindex=0;
while (buffer[noparse][[/noparse]bufindex]!=0) System.out.print(buffer[noparse][[/noparse]bufindex++]); //display incoming message
}
public static void main(){
while (true) { //receive and display ALL messages
bufindex=0; //clear buffer
bufferMessage(); //receive and display one incoming message
}
}
}