Results 1 to 3 of 3
  1. #1
    sagar474 is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,446
    Rep Power
    18

    Default Re: Problem useing Streams

    What value?
    Please do not ask for code as refusal often offends.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Problem useing Streams

    Does that device use any protocol? Or is it just you send something and that thing sends something back? Can it buffer data being sent to it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. byte to string conversion creates problem in streams
    By sakshi.13agg in forum Networking
    Replies: 1
    Last Post: 12-05-2012, 10:11 PM
  2. problem with streams and swings
    By sandeepsai17 in forum New To Java
    Replies: 14
    Last Post: 07-21-2009, 06:23 PM
  3. run command in the background ( useing runtime)
    By itaipee in forum New To Java
    Replies: 7
    Last Post: 03-17-2009, 04:08 PM
  4. Problem With Streams
    By mm2236 in forum Advanced Java
    Replies: 2
    Last Post: 09-23-2008, 01:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •