Reading from Serial

Hi guys,

I have the following code:

byte[] inpContent;

String strBuffer =new String();

this.objDialer =new Dialer(this.objSerialPort);

this.objDialer.send(ATCommands.MODEM_STATE);

this.objDialer.pause(1000);

inpContent =newbyte[this.objSerialPort.getInputStream().available()];

this.objSerialPort.getInputStream().read(inpContent);

while(!(strBuffer.indexOf("\r\n") > 2))

{

inpContent =newbyte[this.objSerialPort.getInputStream().available()];

this.objSerialPort.getInputStream().read(inpContent);

strBuffer =new String(inpContent);

this.objDialer.pause(2000);

}

What it does is reading the modem response after sending in some AT commands... but for some reason the while loop never ends. The response from the modem should always finish with "\r\n". It seems that the loop is blocking the input stream whatsoever, this because if I print the byte[] it comes empty. Have you guys have any idea?

Many thanks,

MeTitus

[1415 byte] By [Me_Titusa] at [2007-11-27 6:49:42]
# 1
If the loop is not terminating then the condition(!(strBuffer.indexOf("\r\n") > 2))Is never true
Jamwaa at 2007-7-12 18:23:29 > top of Java-index,Java Essentials,Java Programming...
# 2

> If the loop is not terminating then the condition

>

> > (!(strBuffer.indexOf("\r\n") > 2))

>

>

> Is never true

Well my dear friend, I didn't need to come here to realise that ...

What I am asking is if the method getInputStream is a blocking method, this because although I know I will be returned an answer from the modem, if a print byte[] it comes empty.

But if I increase the delay say to 4 sec, the stream is already read.

Thanks,

MeTitus

Me_Titusa at 2007-7-12 18:23:29 > top of Java-index,Java Essentials,Java Programming...