SerialPort Write whilst Reading

Topics: Bluetooth - Microsoft
Feb 15, 2012 at 12:24 PM


I'm connecting a WinCE terminal (using the Microsoft stack) to a hand-held bluetooth barcode scanner.  Everything's running fine apart from one thing.

First, the setup:  The terminal starts a BluetoothListener and the scanner initiates the connection to the terminal.  A BluetoothClient is created successfully and GetStream is called.  On that stream, a StreamReader and StreamWriter are opened.  The StreamReader correctly receives data as the scans are performed.

This particular scanner allows the terminal to send an ASCII BEL (7) character back to the scanner to produce some audio feedback.  When this is needed, the program calls the StreamWriter as so:


However, the audio feedback is never heard -- I'm currently assuming that the BEL character is not being received by the scanner, since the scanner itself is configured correctly.  Bear in mind that whilst this is being attempted, there's a background thread running which is in the following loop:

While Not m_BTStreamReader.EndOfStream
code = m_BTStreamReader.ReadLine
RaiseEvent BluetoothScanEvent(code)
End While

Is there a problem with attempting to write to the base stream via a StreamWriter whilst that m_BTStreamReader.ReadLine is blocking?  Or is this a case of the code should be working so I should look elsewhere?



Feb 16, 2012 at 7:12 PM

There shouldn't be any issue with simultaneous access to read and write.

Are there any other command you can send to the scanner?  Do they work?

It *might* be that the StreamWriter is doing something to the 7 value.  Try just a simple program that writes the single 7 byte to the Stream, without wrapping it in a StreamWriter. (I doubt this is the problem).

Is the protocol all line based perhaps? So do you need to send a NewLine (e.g. CRLF) to get the scanner to action each command?