Forums Register Login

IO Exception

+Pie Number of slices to send: Send
i'm trying to communicate with GPS receiver to get gps data(which is NMEA data) but i'm getting an ioException when i reads from inputStreem,
"java.io.IOException: could not receive bytes: some line error". could anyone help me, y i'm gettting line error while reading from inputStreem? ur immediate response wud be much appreciated.
Thanks in advance
Aamir
+Pie Number of slices to send: Send
Does you inputstream code look similar to the following partial listing?
HttpConnection http = null;
InputStream iStrm = null;
...
// Create the connection
http = (HttpConnection) Connector.open(url);
...
iStrm = http.openInputStream();
int length = (int) http.getLength();
if (length != -1)
{
// Read data in one chunk
byte serverData[] = new byte[length];
iStrm.read(serverData);
str = new String(serverData);
}
else // Length not available...
{
ByteArrayOutputStream bStrm =
new ByteArrayOutputStream();

// Read data one character at a time
int ch;
while ((ch = iStrm.read()) != -1)
bStrm.write(ch);

str = new String(bStrm.toByteArray());
bStrm.close();
}
John Muchow
Author of : Core J2ME Technology and MIDP
+Pie Number of slices to send: Send
yeah, ur code is much similar to mine..... there are a no. of points which i want to mention; i'm using StreamConnection instead of httpConnection, 2ndly, as GPS is writing data continuously on serial port, so i'm reading data in chunks of 512 bytes periodically. the 1st time read works fine BUT when i try to read in 2nd attempt then it throws that IOException: couldn't read bytes: Serial Line Error.
waiting for ur reply.....
Aamir
+Pie Number of slices to send: Send
May I look at your code? :roll:
+Pie Number of slices to send: Send
yeah, following is the code that talks to GPS thru serial port and it works fine for me
Note: i'm using IBM's Web Sphere Deveice Developer
private void connect() {
int ch;
InputStreamReader isr;
StreamConnection srlConn;
private final String protocol = "comm:0;baudrate=4800;bitsperchar=8;stopbits=1;parity=none;autorts=on;autocts=on;blocking=on";

try {
if(srlConn == null)
srlConn = (StreamConnection) Connector.open(specs, access, false);
if(isr == null)
isr = new InputStreamReader(srlConn.openInputStream());
} catch(IOException e) {}

while(true) {
try{ch = isr.read();}
catch(IOException ioe) {
// if ioe error = serial error line error then Ignore and continue;
// else break;
}
// other code goes here
}
}

Aamir
+Pie Number of slices to send: Send
looks like you're doing a fairly specialized project, good luck on finding someone here who has done that. On the other hand, I know that one of the nextel apps being sold right now features a midlet with a a GPS connection. you might want to talk to them.
FutureRoads
Could you hold this kitten for a sec? I need to adjust this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1080 times.
Similar Threads
Does anyone know how to write contour using java language ?
GPS projects
gps and j2me
Cursor *N not open
Serial communication possible on SPV C500?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 03:51:01.