Author Topic: Exception thrown in C# Generic HID at fileStreamDeviceData.write  (Read 22540 times)

mihooper

  • Member
  • ***
  • Posts: 24
I am attempting to use Generic HID to talk to my TI MSP board. I can find the device, but an exception is thrown here:
Code: [Select]
private void ExchangeInputAndOutputReports()
....
fileStreamDeviceData.Write(outputReportBuffer, 0, outputReportBuffer.Length);
The exception says:
Quote
System.IO.IOException was caught
  Message=IO operation will not work. Most likely the file will become too long or the handle was not opened to support synchronous IO operations.
  Source=mscorlib
  StackTrace:
       at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
       at GenericHid.FrmMain.ExchangeInputAndOutputReports() in C:\Users\Mike\Documents\Visual Studio 2010\Projects\generic_hid_cs\FrmMain.cs:line 1256
  InnerException:

I am fairly new to all of this. Can anyone offer a suggestion on what could be happening?

Thx,

MikeH

« Last Edit: April 28, 2012, 12:58:55 pm by mihooper »
Thx,
MikeH

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Exception thrown in C# Generic HID at fileStreamDeviceData.write
« Reply #1 on: April 28, 2012, 01:20:07 pm »
Does your device have a a HID OUT report that matches the length of the data you're trying to send?

Jan

mihooper

  • Member
  • ***
  • Posts: 24
Re: Exception thrown in C# Generic HID at fileStreamDeviceData.write
« Reply #2 on: April 28, 2012, 02:11:28 pm »
Jan,

Yes, it does.
Quote
MyHid.Capabilities.InputReportByteLength = 0x0040
MyHid.Capabilities.OutputReportByteLength = 0x0040
Very confusing. I consistently get this exception. I have stepped through each line of code and all looks OK. Weird.
« Last Edit: April 28, 2012, 02:19:26 pm by mihooper »
Thx,
MikeH

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Exception thrown in C# Generic HID at fileStreamDeviceData.write
« Reply #3 on: April 29, 2012, 10:33:31 am »
I don't know the reason why you're seeing this or why the error message refers to WriteCore instead of Write:

System.IO.FileStream.WriteCore

You could try my version that uses Writefile:

http://www.lvr.com/hidpage.htm#MyExampleCode

or search on the error message for clues.

Jan

mihooper

  • Member
  • ***
  • Posts: 24
Re: Exception thrown in C# Generic HID at fileStreamDeviceData.write
« Reply #4 on: April 30, 2012, 06:47:39 am »
Jan,

Your example code seems to work (generic_hid_cs_46). Thanks for responding.
Thx,
MikeH

mihooper

  • Member
  • ***
  • Posts: 24
Re: Exception thrown in C# Generic HID at fileStreamDeviceData.write
« Reply #5 on: April 30, 2012, 09:31:15 am »
Mystery solved....(sort of).

My HID device requires a ReportID = 63. The your generic_HID code inserts ReportID = 0. This apparently caused the exception to be thrown. After changing the ReportID to 63, all is working properly!

Thanks again!
Thx,
MikeH

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Exception thrown in C# Generic HID at fileStreamDeviceData.write
« Reply #6 on: April 30, 2012, 02:33:00 pm »
Glad you got it working.

If the HID has no more than 1 report of each type (Input, Output, Feature), it should use report ID zero.

Jan
 

mihooper

  • Member
  • ***
  • Posts: 24
Re: Exception thrown in C# Generic HID at fileStreamDeviceData.write
« Reply #7 on: April 30, 2012, 03:13:53 pm »
Jan,

I am using the TI MSP430 "datapipe" HID. It is a special HID that does not require a custom driver on the PC, but allows you to pass 64 bytes of data. I'm still learning about how it all works, but I noticed in the TI demo app that ReportID must be set fo 63 for the USB transactions to work.

FYI, TI's documentation on USB and HID is very good. It is well written and comprehensive. If folks are looking for a good USB solution, I recommend taking a look at the MSP430 product family. I am using the MSP430529 eval board http://www.ti.com/tool/msp-exp430f5529.

Thx,
MikeH