Shop OBEX P1 Docs P2 Docs Learn Events
serial between javalins.... — Parallax Forums

serial between javalins....

JavalinJavalin Posts: 892
edited 2005-10-06 01:56 in General Discussion
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

Comments

  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2005-10-06 01:56
    ·Hello, I am sendind and receiving data between two Javalin's through high powered tranceivers. I have had the same problem ... but I am only a couple weeks into java :>) This is a bit of code that peter sent this afternoon for the receiving end. I noticed that in a java book that Im reading they used·...····· system.out.println (+ num);·· ......for an int value. Let me know how your doing and maybe we can help each other learn :>)

    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
    }
    }
    }
Sign In or Register to comment.