RogerioNT
Posts: 4
Joined: Wed Mar 04, 2009 10:05 pm

How to set read/write timeout

Wed Mar 04, 2009 10:06 pm

I'm writing a byte to my device.
Then I'm read the answer.
How can I set the timeout for the read answer ? I just want to wait 5
seconds for read; If do not read in 5 seconds break;
Also, WriteByte will write 1 byte or will write my byte Tipo complete?

Here my code:

byte Tipo=0xFF;
byte[] mybuffer = new byte[25];
currentStream.WriteByte((byte)Tipo);
currentStream.Read(mybuffer, 0, mybuffer.Length);

thank you

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: How to set read/write timeout

Thu Mar 05, 2009 5:56 pm

There is no way of doing this nicely.
The best you can do is closing the Stream after 5 seconds using i.e. a timer.

I don't see the difference in writing 1 byte and writing your Tipo byte. It will write one byte with the value 0xFF to the remote device.

Regards,
Jonas

RogerioNT
Posts: 4
Joined: Wed Mar 04, 2009 10:05 pm

RE: How to set read/write timeout

Fri Mar 06, 2009 7:56 pm

Hi,

I'm trying to set the currentStream.ReadTimeout=1000; but Always return error; Why ?
thanks

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: How to set read/write timeout

Sat Mar 07, 2009 12:10 pm

As I said, the concept of timeout doesn't exists for BlueTools. You are only seeing the property because ServiceStream is inheriting from Stream.

Regards,
Jonas

Return to “BlueTools”