I have a strange behaviour im my app.
I open a COM port to comunicate witha a device over Bluetooth. I do the following steps:
- Open the virtual COM port;
- Switch remote bluetooth to command mode;
- Perform few commands (eg. read remote device's serial number);
- Switch remote bluetooth to data amode;
- Send data to device;
Read a byte of answer (ReadByte() from SerialPort class);
The device works fine and answers immediately and everything is fine while I run my app in debug mode via visual studio.
But when I try to run it directly (without visual studio and adebugger attatched - but still compiled with "Debug" option) i get a timeout exception at step 6.
The bug is fully reproducible (no timeouts in Visual Studio, and every time without it).
Does anyone have any idea that could cause such behaviour ?
Here is the code from step 6
private byte[] ReadResponse() {
try {
int bytes2Read = 6;
do {
this.buffer.Append((byte)ReadByte()); // <- there the timeout occurs
if (this.buffer.Length == 6) { // header receiver
// bytes 2 and 3 contain message length
bytes2Read = this.buffer[2] + (this.buffer[3] << 8);
}
} while (this.buffer.Length < bytes2Read);
return this.buffer.ToArray();
} finally {
this.buffer.Clear();
}
}
The method is situated in the class that derives from SerialPort class.