Shop OBEX P1 Docs P2 Docs Learn Events
Basic stamp program to javelin program — Parallax Forums

Basic stamp program to javelin program

RacoonRacoon Posts: 15
edited 2009-08-20 06:10 in General Discussion
Dear all,

I am trying to convert some coding from basic stamp code to javelin code.

below is the basic stamp code.


RcvData VAR Byte(10)
SEROUT 7, 84, [noparse][[/noparse]"RS", CR]
SEROUT 7, 84, [noparse][[/noparse]"L1 1",CR]
serin 9, 84, [noparse][[/noparse]STR RcvData\10]
debug DEC RCVData(2)

I write the beginning like this

import stamp.core.*;

public class test{

final static int TX = CPU.pin7;
final static int RX = CPU.pin9;

static Uart txUart = new Uart( Uart.dirTransmit, TX, Uart.dontInvert, Uart.speed9600,Uart.stop1 );
static Uart rxUart = new Uart( Uart.dirReceive, RX, Uart.dontInvert, Uart.speed9600,Uart.stop1 );


after this I do not know how to continue the above conversion.

Thank you for your help in advance.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-08-19 04:13
    import stamp.core.*;
    
    public class test{
    
     final static int TX = CPU.pin7; 
     final static int RX = CPU.pin9; 
    
     static Uart txUart = new Uart(Uart.dirTransmit,TX,Uart.dontInvert,Uart.speed9600,Uart.stop1);
     static Uart rxUart = new Uart(Uart.dirReceive,RX,Uart.dontInvert,Uart.speed9600,Uart.stop1);
    
     static char str = new char[noparse][[/noparse]10];
    
     static void main() {
       System.out.println("Program test");
       txUart.sendString("RS\r");
       txUart.sendString("L1 1\r");
       for (int i=0; i<10; i++) {
         str[noparse][[/noparse]i] = (char)rxUart.receiveByte();
       }
       System.out.print(str[noparse][[/noparse]2]&255);
    
       while (true) {
       }
     }
    
    }
    
    
    

    regards peter
  • RacoonRacoon Posts: 15
    edited 2009-08-19 04:47
    Thank you very much peter

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The truth in physics is changed with time.
  • RacoonRacoon Posts: 15
    edited 2009-08-20 06:10
    Hi peter,

    I got some more questions.

    For example, if I connect the cmucam3 directly to hyperterminal, if I type the following command. the following data will be appear. Below got remark one is I type one and without remark one is computer return one.

    RS // I type the reset command

    ACK

    CMUcam2 v1.00 c6

    OM 0 3 // Request for data package

    ACK

    TC 0 50 0 50 0 50 // I request to track black color

    T 11 6
    T 30 40
    ...
    ...

    Now i convert the above coding actually only 3 command: RS, OM 0 3, TC 0 50 0 50 0 50 to java programm like below. Seems I cannot get the exactly data that appears
    I mean the character T(applear as other character sometimes, sometimes correct), and the data value(after T) I receive in javelin terminal is different from what I receive in hyperterminal.

    Thank you in advance.



    import stamp.core.*;

    public class cmucam1_2{


    final static int TX = CPU.pin3;
    final static int RX = CPU.pin4;

    static Uart txUart = new Uart(Uart.dirTransmit,TX,Uart.dontInvert,Uart.speed57600,Uart.stop1);
    static Uart rxUart = new Uart(Uart.dirReceive,RX,Uart.dontInvert,Uart.speed57600,Uart.stop1);


    static StringBuffer buffer = new StringBuffer(128);

    static char[noparse]/noparse buf = new char[noparse][[/noparse]8];
    static int i;

    static void bufferMessage(){

    if(rxUart.byteAvailable()){
    for (i=1; i<4; i++) {
    buf= (char)rxUart.receiveByte();
    buffer.append(buf);
    }

    }
    }

    static void main() {
    txUart.sendString("RS\r");
    CPU.delay(5000);
    txUart.sendString("OM 0 3\r");
    CPU.delay(5000);

    txUart.sendString("TC 0 50 0 50 0 50\r");
    CPU.delay(5000);

    while(true){
    bufferMessage();
    buf = (char) rxUart.receiveByte();
    System.out.println("");
    System.out.print(buf);
    System.out.print(" ");
    System.out.print(buf&255);
    System.out.print(" ");
    System.out.print(buf&255);
    System.out.print(" ");


    }
    }




    }

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The truth in physics is changed with time.

Sign In or Register to comment.