Hello,
I try to communicate with a DSLR via the USB interface with my G80 Development Board.
I used the following example as a basis: https://www.ghielectronics.com/community/codeshare/entry/939
When the program enters the CheckEvents() method and invokes the NativeTransfer() on inputPipe, the application freezes.
With the following instructions in comments, everything works correctly on the interruptPipe.
[quote]
if ((int)methodNativeTransfer.Invoke(inputPipe, new object[] { inputData, 0, inputData.Length, 0 }) > 0)
{
Debug.Print("Input data: " + inputData.ToString());
}[/quote]
Here is the code used for my DSLRDevice class:
using System;
using Microsoft.SPOT;
using GHI.Usb.Host;
using GHI.Usb.Descriptors;
using System.Reflection;
namespace CRVBox.Core.Device
{
public class DSLRDevice : RawDevice
{
private const int classCode = 0x06;
private const int subclassCode = 0x01;
private const int protocolCode = 0x01;
private const int inputPipeEndpoint = 0;
private const int outputPipeEndpoint = 1;
private const int interruptPipeEndpoint = 2;
private RawDevice.Pipe inputPipe;
private RawDevice.Pipe outputPipe;
private RawDevice.Pipe interruptPipe;
private byte[] inputData;
private byte[] interruptData;
static MethodInfo methodNativeTransfer = typeof(RawDevice.Pipe).GetMethod("NativeTransfer", BindingFlags.NonPublic | BindingFlags.Instance);
public DSLRDevice(Controller.UnknownDeviceConnectedEventArgs paras) : base(paras.Id, paras.InterfaceIndex, paras.VendorId, paras.ProductId, paras.PortNumber, paras.Type)
{
var configuration = GetConfigurationDescriptor(0);
foreach (Interface i in configuration.Interfaces)
{
if (i.ClassCode == classCode && i.SubclassCode == subclassCode && i.NumberEndpoints == 3 && i.ProtocolCode == protocolCode)
{
SendSetupPacket(0x00, 0x09, configuration.Value, 0x00);
inputPipe = OpenPipe(i.Endpoints[inputPipeEndpoint]);
inputPipe.TransferTimeout = 0;
outputPipe = OpenPipe(i.Endpoints[outputPipeEndpoint]);
outputPipe.TransferTimeout = 0;
interruptPipe = OpenPipe(i.Endpoints[interruptPipeEndpoint]);
interruptPipe.TransferTimeout = 0;
inputData = new byte[inputPipe.Endpoint.MaximumPacketSize];
interruptData = new byte[interruptPipe.Endpoint.MaximumPacketSize];
//WorkerInterval = interruptPipe.Endpoint.Interval;
WorkerInterval = 1 * 1000;
break;
}
}
}
protected override void CheckEvents(object sender)
{
Debug.Print("CheckEvents() => IN");
if (!CheckObjectState(false))
{
return;
}
try
{
if ((int)methodNativeTransfer.Invoke(inputPipe, new object[] { inputData, 0, inputData.Length, 0 }) > 0)
{
Debug.Print("Input data: " + inputData.ToString());
}
if ((int)methodNativeTransfer.Invoke(interruptPipe, new object[] { interruptData, 0, interruptData.Length, 0 }) > 0)
{
Debug.Print("Interrupt data: " + interruptData.ToString());
}
}
catch (Exception e)
{
Debug.Print("Input Error: " + Controller.GetLastError().ToString());
Debug.Print(e.Message);
}
Debug.Print("CheckEvents() => OUT");
}
}
}
Below is the capture done with a utility under Windows of the characteristics of the USB client device:
Interface Descriptor:
0x09 bLength
0x04 bDescriptorType
0x00 bInterfaceNumber
0x00 bAlternateSetting
0x03 bNumEndPoints
0x06 bInterfaceClass (Imaging Device Class)
0x01 bInterfaceSubClass
0x01 bInterfaceProtocol
0x00 iInterface
Endpoint Descriptor:
0x07 bLength
0x05 bDescriptorType
0x81 bEndpointAddress (IN Endpoint)
0x02 bmAttributes (Transfer: Bulk / Synch: None / Usage: Data)
0x0040 wMaxPacketSize (64 Bytes)
0x00 bInterval
Endpoint Descriptor:
0x07 bLength
0x05 bDescriptorType
0x02 bEndpointAddress (OUT Endpoint)
0x02 bmAttributes (Transfer: Bulk / Synch: None / Usage: Data)
0x0040 wMaxPacketSize (64 Bytes)
0x00 bInterval
Endpoint Descriptor:
0x07 bLength
0x05 bDescriptorType
0x83 bEndpointAddress (IN Endpoint)
0x03 bmAttributes (Transfer: Interrupt / Synch: None / Usage: Data)
0x0008 wMaxPacketSize (8 Bytes)
0x0A bInterval
And I find exactly the same values in my .NETMF application.
I really do not understand what happens, if someone has experience in this domain.
Thank you.