Subject:
|
Help with DataOutputStream and DataInputStream
|
Newsgroups:
|
lugnet.robotics.rcx.java
|
Date:
|
Fri, 7 Feb 2003 23:52:18 GMT
|
Viewed:
|
4741 times
|
| |
| |
Hi people,
I´m working with lejos 2.1 and the serial tower. I was trying to send a
matrix of floats from the PC to the RCX using as a model the DataInputStream
and DataOutputStream examples that came with lejos.
The problem I have, is that I´m loosing some floats during the sending
process (i. e. I send 9 floats from the PC but I receive only 6 or 7 in the
RCX). I´m attaching the code so you can help me to identify the mistake.
I need to find some way to make me sure that no float is loosed during the
transmission. Any idea?
Any help will be really appreciated!!!
Thanks in advanced,
Mario Sassone
PC Code:
=======
import java.io.*;
import josx.rcxcomm.*;
public class SendMatrix {
public static void main(String[] args) {
float matrix[][] = new float[3][3];
try {
RCXPort port = new RCXPort();
OutputStream os = port.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
for (int i=0; i < 3; i++) {
for (int j=0; j < 3; j++) {
matrix[i][j] = 0.25F;
dos.writeFloat(matrix[i][j]);
dos.flush();
System.err.println("I=" + i + " J=" + j);
}
}
}
catch (Exception e) {
System.err.println(e);
}
}
}
RCX Code:
========
import java.io.*;
import josx.rcxcomm.*;
import josx.platform.rcx.*;
public class ReceiveMatrix {
public static void main(String[] args) {
float matrix[][] = new float[3][3];
int k = 1;
LCD.showNumber(9999);
try {
RCXPort port = new RCXPort();
InputStream is = port.getInputStream();
DataInputStream dis = new DataInputStream(is);
for (int i=0; i < 3; i++) {
for (int j=0; j < 3; j++) {
matrix[i][j] = dis.readFloat();
LCD.showNumber(k++);
}
}
}
catch (Exception e) {
}
}
}
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|