1 package lejos.rcxcomm;
\r
6 * Emulates RCX LLC class using the RCXLink class.
\r
9 private static RCXLink link;
\r
10 private static byte[] data = new byte[1];
\r
16 * Initialize LLC and set port
\r
18 public static void init(SensorPort port){
\r
19 link = new RCXLink(port);
\r
20 link.setDefaultSpeed();
\r
27 public static void init() {
\r
28 link.setDefaultSpeed();
\r
35 public static void setPort(SensorPort port) {
\r
36 link = new RCXLink(port);
\r
40 * read a single byte, if available
\r
41 * @return the byte read, or -1 if no byte is available
\r
43 public static int read() {
\r
44 int numBytes = link.bytesAvailable();
\r
45 if (numBytes == 0) return -1;
\r
47 link.readBytes(data);
\r
48 return (data[0] & 0xFF);
\r
54 * @param buf the bytes to write
\r
55 * @param len the number of bytes
\r
57 private static void write(byte [] buf, int len) {
\r
58 link.sendBytes(buf, len);
\r
62 * Indicate whether the last send is still active
\r
63 * @return true if still sending, else false
\r
65 public static boolean isSending() {
\r
70 * Return the error status of the last send
\r
71 * @return true if still sending, else false
\r
73 public static boolean isSendError() {
\r
78 * Send a number of bytes and wait for completion of transmission
\r
79 * @param buf the array of bytes to send
\r
80 * @param len the number of bytes to send
\r
81 * @return true if the send is successful, else false
\r
83 public static boolean sendBytes(byte [] buf, int len) {
\r
84 LLC.write(buf, len);
\r
89 * wait a little while for a byte to become available
\r
90 * @return the byte received, or -1 if no byte available
\r
92 public static int receive() {
\r
94 for(int i=0;i<10;i++) {
\r
96 if (r >= 0) return r;
\r
103 * Sets long range transmision.
\r
105 public static void setRangeLong()
\r
107 link.setRangeLong();
\r
111 * Sets short range transmision.
\r
113 public static void setRangeShort()
\r
115 link.setRangeLong();
\r
119 * Return the RCXLink object associated with LLC
\r
121 * @return the RCXLink used
\r
123 public static RCXLink getLink() {
\r