Results 1 to 3 of 3
Thread: Problem useing Streams
- 11-22-2012, 09:59 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
Problem useing Streams
I have external device connected to the computer. I'm using rxtx library to interface that device. that device transmits a byte immediately as replay to that bye that i send.
example
if i send '1' it replays a
'2' it replays b
....
first i Tried it for 1 byte. send '1' and receive a;
and it works fine.
In first case a[0] has expected value
Java Code:byte[] a; a = new byte[1024]; char ch[] = {'1','2','3','4','5','6','7','8'}; byte adc[] = new byte[8]; int length; int i=0; try { out.write((byte)'1'); length = in.read(a); if(length==1) { this.perameters.setTempreture(a[0]);//a[0] has expected value reading successful } } catch (IOException ex) { System.out.println("Error in writing"); Logger.getLogger(CommunicationLayer.class.getName()).log(Level.SEVERE, null, ex); }
but when i tried it for 8 bytes. it doesn't work.
In this case adc[0] has unexpected value.
Java Code:byte[] a; a = new byte[1024]; char ch[] = {'1','2','3','4','5','6','7','8'}; byte adc[] = new byte[8]; int length; int i=0; try { for(i=0;i<=7;++i) { out.write((byte)ch[i]); length = in.read(a); if(length==1) { adc[i] = a[i]; } } this.perameters.setTempreture(adc[0]);//adc[0] is unexpected } catch (IOException ex) { System.out.println("Error in writing"); Logger.getLogger(CommunicationLayer.class.getName()).log(Level.SEVERE, null, ex); }Last edited by sagar474; 11-22-2012 at 10:06 PM.
- 11-23-2012, 09:34 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Problem useing Streams
What value?
Please do not ask for code as refusal often offends.
- 11-23-2012, 06:50 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
byte to string conversion creates problem in streams
By sakshi.13agg in forum NetworkingReplies: 1Last Post: 12-05-2012, 10:11 PM -
problem with streams and swings
By sandeepsai17 in forum New To JavaReplies: 14Last Post: 07-21-2009, 06:23 PM -
run command in the background ( useing runtime)
By itaipee in forum New To JavaReplies: 7Last Post: 03-17-2009, 04:08 PM -
Problem With Streams
By mm2236 in forum Advanced JavaReplies: 2Last Post: 09-23-2008, 01:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks