This project has moved. For the latest updates, please go here.
5
Vote

Unhandled IOException in WiimoteLib.Wiimote.OnReadData(IAsyncResult ar)

description

Hi,
 
there is a unhandled IOException in WiimoteLib.Wiimote.OnReadData(IAsyncResult ar) which occurs if the batteries of the Wiimote are removed or the Bluetooth dongle is unpluged or something.
I catched this exception in the latest SVN release (19218) and now all works fine.
 
private void OnReadData(IAsyncResult ar)
    {
        // grab the byte buffer
        byte[] buff = (byte[])ar.AsyncState;
 
        try
        {
            // end the current read
            mStream.EndRead(ar);
 
            // parse it
            if(ParseInputReport(buff))
            {
                // post an event
                if(WiimoteChanged != null)
                    WiimoteChanged(this, new WiimoteChangedEventArgs(mWiimoteState));
            }
 
            // start reading again
            BeginAsyncRead();
        } catch (IOException) { //new catch statement
            Debug.WriteLine("IOException");
        } catch(OperationCanceledException)
        {
            Debug.WriteLine("OperationCanceledException");
        }
    }

file attachments

comments

twig wrote Mar 15, 2013 at 12:14 PM

Hi there,

Found this fix and it's working fine.

I've gone one step further and added a disconnect handler.
Attached is a diff file for you to apply (pastebin in case the file is lost - http://pastebin.com/kRqG0SBa)

My apologies for using different code formatting
The only code changes made are in the IO exception block.

wrote Feb 18, 2015 at 2:55 AM