Uart with the LinkMatik by Flexipanel
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
Post Edited (Dorling) : 5/20/2007 1:48:41 PM GMT
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
But when I do:
I get a reply of
and not
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
The uarts have 256-byte buffers and as you use handshaking
there should be no loss of data.
regards peter
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
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
size to a larger value, say 400.
regards peter
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
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
Jonathan
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
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
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
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
It explains how the buffer operates with handshake, and what handshake
signals are expected, depending on Uart.invert and Uart.dontInvert settings.
regards peter