Shop OBEX P1 Docs P2 Docs Learn Events
Uart with the LinkMatik by Flexipanel — Parallax Forums

Uart with the LinkMatik by Flexipanel

DorlingDorling Posts: 32
edited 2007-05-23 05:32 in General Discussion
Hi all,

I am trying to talk to the LinkMatik (http://www.flexipanel.com/Docs/LinkMatik 2.0 DS379.pdf). But I am not getting any feedback from the LinkMatik. My Code is below could some one help me please?

All that the message windows comes out with is "0 - ".

Thanks

Jonathan


import stamp.core.*;

public class LinkMatik {

  // public final int RESET = CPU.pin4;
  // public final int ATN = CPU.pin6;
  // public final int ESC = CPU.pin5;

  public static final int TxD = CPU.pin0; // RxD on the linkMatik pin 4
  public static final int RTS = CPU.pin1; // CTS on the linkMatik pin 5
  public static final int RxD = CPU.pin2; // TxD on the linkMatik pin 7
  public static final int CTS = CPU.pin3; // RTS on the linkMatik pin 8

  public static Uart      rx;
  public static Uart      tx;

  public static void main() {

    for (int i = 0; i < 16; i++) {
      CPU.writePin(CPU.pins[i], false);
    }

    tx =
        new Uart(Uart.dirTransmit, TxD, Uart.invert, CTS, Uart.invert,
            Uart.speed9600, Uart.stop1);
    rx =
        new Uart(Uart.dirReceive, RxD, Uart.invert, RTS, Uart.invert,
            Uart.speed9600, Uart.stop1);

    System.out.println("INFO");

    tx.sendString("INFO");

    while (true) {
      if(rx.byteAvailable()){
        System.out.print((int) rx.receiveByte());
        System.out.print(" - ");
        System.out.println((char) rx.receiveByte());
      }
    }

  }

}[/i]

Post Edited (Dorling) : 5/20/2007 1:48:41 PM GMT

Comments

  • DorlingDorling Posts: 32
    edited 2007-05-22 18:08
    i got it working. Don't know what I change but it works. which is good.

    But when I do:

    tx.sendString("INFO");
    



    I get a reply of
    said...
    WRAPware version 2810
    - up 0 days, 00:20, 0 connections (pool 1)
    READY.

    and not
    said...
    WRAP THOR AI (2.1.0 build 23)
    Copyright (c) 2003-2006 Bluegiga Technologies Inc.
    Compiled on Mar 28 2006 15:06:49, running on WT11 module, psr v12
    - BOCK3 version 16 (Mar 21 2006 15:31:36) (max acl/sco 7/1)
    - Bluetooth version 2.0, Power class 1
    - Firmware version 2810
    - up 0 days, 00:12, 0 connections (pool 1)
    READY.

    as i do in HyperTerminal!

    This is down the buffer size and that when the buffer is full. It start at the begin again and over write it. But when the javelin reads the buffer it starts from the begin. So you loss data on the buffer from the over write but also because when it reads the buffer it start from index 0.

    So is there a way of increase the buffer size? I see that there is a stdBufferSize but this is just for the local buffer array.

    Many Thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-22 18:28
    Please post your code as an attachement.
    The uarts have 256-byte buffers and as you use handshaking
    there should be no loss of data.

    regards peter
  • DorlingDorling Posts: 32
    edited 2007-05-22 18:40
    It doesn't loss data from the uart. The problem is that:

    The javelin received a,b,c,d,e,f,g.

    buffer = [noparse][[/noparse]f,g,c,d,e]

    when you do receiveByte(). it only reads f,g. But on a bigger scale than 5.

    Thanks

    Jonathan


    import stamp.core.*;
    
    public class LinkMatik {
    
      // public final int RESET = CPU.pin4;
      // public final int ATN = CPU.pin6;
      // public final int ESC = CPU.pin5;
    
      public static final int TxD = CPU.pin0; // RxD on the linkMatik pin 4
      public static final int RxD = CPU.pin2; // TxD on the linkMatik pin 7
    
      public static final int RTS = CPU.pin1; // CTS on the linkMatik pin 5   in
      public static final int CTS = CPU.pin3; // RTS on the linkMatik pin 8   out
    
      public static Uart      rx;
      public static Uart      tx;
    
      public LinkMatik(){}
    
      public static void main() {
    
      LinkMatik l = new LinkMatik();
    
        tx = new Uart(Uart.dirTransmit, TxD, Uart.dontInvert, CTS, Uart.speed9600, Uart.stop1);
    
        rx = new Uart(Uart.dirReceive, RxD, Uart.dontInvert, RTS, Uart.speed9600, Uart.stop1);
    
    
        System.out.println("INFO");
        tx.sendString("INFO\r\n");
    
        while (true) {
          if(Terminal.byteAvailable()){
            l.getString();
    
            System.out.println("\nYour String is: ");
            System.out.println(buffer.toString());
            System.out.println("\n");
    
            tx.sendString(buffer.toString());
            tx.sendString("\r\n");
          }
    
          if(rx.byteAvailable()){
            System.out.print((char) rx.receiveByte());
          }
        }
    
      }
    
      static StringBuffer buffer = new StringBuffer(128);
      static char c;
      public void getString(){
      buffer.clear();
        c = 0x0ff;
        while(c != '\r'){
          c = (char) Terminal.getChar();
          buffer.append(c);
        }
    
      }
    
    }
    
    
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-22 19:22
    I have split your code in two classes.
    A LinkMatik class and a LinkMatik_test class.
    It is good practice never to put a main() inside a library class,
    but to write a special program class that has the main() method.
    This keeps your code clean and allows you to reuse library classes.
    You should make a directory·....\lib\stamp\peripheral\wireless\linkmatik
    inside the Javelin IDE program folder and put the two
    attachements inside the linkmatik folder.
    The names are case sensitive and should be as given.
    Try this and report your output.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-22 19:34
    The response to INFO is 326 bytes long. So you need to increase the buffer
    size to a larger value, say 400.

    regards peter
  • DorlingDorling Posts: 32
    edited 2007-05-22 20:18
    Yes peter it does need increase. How do I go about this? There is an stdBufferSize but this is just for the local buffer array. How do i change the size of the buffer?

    The file I show you before was work in progress that why i had not move the main method. I have change the file a little bit see below.

    Many Thanks

    Jonathan

    package stamp.peripheral.wireless.linkmatik;
    
    import stamp.core.Uart;
    
    public class LinkMatik {
    
      private Uart rx;
      private Uart tx;
    
      public LinkMatik(Uart tx, Uart rx) {
        this.tx = tx;
        this.rx = rx;
      }
    
      StringBuffer sb = new StringBuffer();
    
      public String getResponse() {
        sb.clear();
        while (rx.byteAvailable()) {
          sb.append((char) rx.receiveByte());
        }
        return sb.toString();
      }
    
      public void sendString(String s) {
        tx.sendString(s);
        tx.sendString("\r\n");
      }
    
    }
    
    

    package stamp.peripheral.wireless.linkmatik;
    
    import stamp.core.CPU;
    import stamp.core.Terminal;
    import stamp.core.Uart;
    import stamp.peripheral.wireless.linkmatik.LinkMatik;
    
    public class LinkMatik_test {
    
      // public final int RESET = CPU.pin4;
      // public final int ATN = CPU.pin6;
      // public final int ESC = CPU.pin5;
    
      static final int TxD = CPU.pin0; // RxD on the linkMatik pin 4
      static final int RxD = CPU.pin2; // TxD on the linkMatik pin 7
      static final int RTS = CPU.pin1; // CTS on the linkMatik pin 5   in
      static final int CTS = CPU.pin3; // RTS on the linkMatik pin 8   out
    
      static Uart rx = new Uart(Uart.dirReceive, RxD, Uart.dontInvert, RTS, Uart.speed9600, Uart.stop1);
      static Uart tx = new Uart(Uart.dirTransmit, TxD, Uart.dontInvert, CTS, Uart.speed9600, Uart.stop1);
    
      static LinkMatik l = new LinkMatik(tx,rx);
      static StringBuffer buffer = new StringBuffer(128);
    
      static void main() {
        String s;
        while (true) {
          System.out.println("\nPlease type in your next command to send to the LinkMatik"); //display response
          getStringFromUser(buffer);  //get user command to send to the LinkMatik
          System.out.println("\nUser command is: "); //display response
          System.out.println(buffer.toString());
          System.out.println("\n");
          l.sendString(buffer.toString()); //send user command to LinkMatik
          s = l.getResponse();  //get response from LinkMatik
          System.out.println("\nResponse is: "); //display response
          System.out.println(s);
          System.out.println("\n");
        }
    
      }
      private static char c;
      public static void getStringFromUser(StringBuffer s){
        s.clear();
        c = 0x0ff;
        while(c != '\r'){
          c = (char) Terminal.getChar();
          s.append(c);
        }
      }
    
    }
    
    
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-22 20:34
    package·stamp.peripheral.wireless.linkmatik;

    import·stamp.core.Uart;

    public·class·LinkMatik·{

    ··private·Uart·rx;
    ··private·Uart·tx;

    ··public·LinkMatik(Uart·tx,·Uart·rx)·{
    ····this.tx·=·tx;
    ····this.rx·=·rx;
    ··}

    ··StringBuffer·sb·=·new·StringBuffer(400);· //this should be large enough to hold any response

    ··public·String·getResponse()·{
    ····sb.clear();
    ····while·(rx.byteAvailable())·{
    ······sb.append((char)·rx.receiveByte());
    ····}
    ····return·sb.toString();
    ··}

    ··public·void·sendString(String·s)·{
    ····tx.sendString(s);
    ····tx.sendString("\r\n");
    ··}

    }

    regards peter
  • DorlingDorling Posts: 32
    edited 2007-05-22 20:49
    This will only increase the buffer if the method is executing if not the buffer is to small. How can I fix this? Do I need to create a VP that extends the class UART so that I can have a bigger buffer

    Jonathan
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-22 20:56
    If the method is not executing, then the uart buffer will be filled
    up to 240 bytes, then the RTS line is disasserted (tells linkmatik to hold transmitting).
    When the method is executing, the uart buffer is emptied until there
    are 16 or less bytes in the buffer, then the RTS line is asserted (tells linkmatik to start transmitting).
    All you need to ensure, is that your storage buffer is large enough
    to hold any response.

    regards peter
  • DorlingDorling Posts: 32
    edited 2007-05-22 21:08
    Thanks peter. that doesn't happen at all. it just over the buffer
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-22 21:19
    If the handshake is working, then the uart VP will ensure no data is lost.
    Perhaps your handshake settings are still not right.
    Try defining the rx uart as
    ····rx·=·new·Uart(Uart.dirReceive,·RxD,·Uart.dontInvert,·Uart.speed9600,·Uart.stop1);
    and make pin RTS permanent low, this enables the linkmatik to transmit.
    put CPU.writePin(RTS,false); before the while (true) loop in main().

    regards peter
  • DorlingDorling Posts: 32
    edited 2007-05-22 22:39
    Thanks peter I sorted the problem with the handshaking lines.

    Two last question:

    1) How did you learn/find out all this information like that the uart buffer will be filled up to 240 bytes and disasserted the RTS?

    2) Why does when the program run when you do rx.receiveByte() it doesn't take up any Memory?

    Many Thanks a again

    Jonathan
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-22 22:50
    1) I don't recall where I read about the uart buffer use when using handshake, but it probably
    is mentioned somewhere in the manual.
    2) The uart VP handles the communication with an external device. Your program
    merely reads and writes to the uart buffer using the send and receive methods.
    All memory involved is statically allocated when you declare a uart.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-23 05:32
    Read javelin manual chapter 9, page 189 for uart information.
    It explains how the buffer operates with handshake, and what handshake
    signals are expected, depending on Uart.invert and Uart.dontInvert settings.

    regards peter
Sign In or Register to comment.