Author Topic: Help - Cannot read from Wiimote error is caused because of a threading issue  (Read 3636 times)

Offline nechmads

  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
I'm having the same problem but I have more data on why it happens.

I succesfully connected the wiimote to my dell laptop (windows vista and Visual studio 2008).
If I run the test application that comes with the wiimotelib, everything works fine.

But, when I run (debug or release) the multigridpoint project I also get the error of "Cannot read from Wiimote - is it connected".

I tried to write my own allication that use the wiimote library and found out what seems to be the problem.

If I just put a windows form, call the connect method and on the event handler of the wiimote object state change method I try to set a text of a control on the form I get an error about "possible synch problem between threads".

In order to solve it, I added a delegate object and from the event handler called the delagee.
When ever the project has the followin gline, you get the "cannot read from wiimote" error. when I comment this line, everything works fine:
delegate void SetTextCallback(string x, string y);

I debugeed the multigridpoint project and saw that it alwasy fail on this line:
if(!mReadDone.WaitOne(2500, false))
Which also points to the same threading issue.

I have no idea how to solve this...





Offline nechmads

  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
I just found a solution (although not sure it is the correct way to do things):

1. In Wiimote.cs find the WriteReport method.
2. comment the if statement and leave the mothod with just two lines:

private void WriteReport()
{
       HIDImports.HidD_SetOutputReport(this.mHandle.DangerousGetHandle(), mBuff, (uint)mBuff.Length);
       Thread.Sleep(100);
}

save, buiuld the project and run. Everything will work now.