Mercurial > hg > ucis.core
annotate USBLib/Communication/UsbInterface.cs @ 44:5a2b51b0d71b
USBLib: Fixed initialization of multi-interface USBIO devices
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Wed, 12 Jun 2013 23:08:48 +0200 |
parents | 6fcedb1030bf |
children | 053cc617af54 |
rev | line source |
---|---|
21 | 1 ???using System; |
2 using System.Text; | |
3 using UCIS.USBLib.Descriptor; | |
4 | |
5 namespace UCIS.USBLib.Communication { | |
6 public abstract class UsbInterface : IUsbInterface { | |
7 public virtual byte Configuration { | |
8 get { | |
9 byte[] buf = new byte[1]; | |
10 int tl = ControlRead( | |
11 UsbControlRequestType.EndpointIn | UsbControlRequestType.TypeStandard | UsbControlRequestType.RecipDevice, | |
12 (byte)UsbStandardRequest.GetConfiguration, 0, 0, | |
13 buf, 0, buf.Length); | |
14 if (tl != buf.Length) throw new Exception("Read failed"); | |
15 return buf[0]; | |
16 } | |
17 set { | |
18 throw new NotImplementedException(); | |
19 } | |
20 } | |
21 public unsafe virtual string GetString(short langId, byte stringIndex) { | |
22 Byte[] buffer = new Byte[256]; | |
23 int tl = GetDescriptor((byte)UsbDescriptorType.String, stringIndex, langId, buffer, 0, buffer.Length); | |
24 if (tl < 2) return null; | |
25 return UsbStringDescriptor.GetString(buffer, 0, tl); | |
26 } | |
27 public virtual int GetDescriptor(byte descriptorType, byte index, short langId, byte[] buffer, int offset, int length) { | |
28 return ControlRead( | |
29 UsbControlRequestType.EndpointIn | UsbControlRequestType.RecipDevice | UsbControlRequestType.TypeStandard, | |
30 (Byte)UsbStandardRequest.GetDescriptor, | |
31 (short)((descriptorType << 8) | index), langId, buffer, offset, length); | |
32 } | |
33 public virtual int ControlWrite(UsbControlRequestType requestType, byte request, short value, short index) { | |
34 return ControlWrite(requestType, request, value, index, null, 0, 0); | |
35 } | |
36 | |
37 public abstract void Close(); | |
38 | |
39 public abstract int BulkWrite(Byte endpoint, Byte[] buffer, int offset, int length); | |
40 public abstract int BulkRead(Byte endpoint, Byte[] buffer, int offset, int length); | |
41 public abstract int InterruptWrite(Byte endpoint, Byte[] buffer, int offset, int length); | |
42 public abstract int InterruptRead(Byte endpoint, Byte[] buffer, int offset, int length); | |
43 public abstract int ControlWrite(UsbControlRequestType requestType, byte request, short value, short index, byte[] buffer, int offset, int length); | |
44 public abstract int ControlRead(UsbControlRequestType requestType, byte request, short value, short index, byte[] buffer, int offset, int length); | |
45 | |
35
6fcedb1030bf
USBLib: Added support for USBIO driver
Ivo Smits <Ivo@UCIS.nl>
parents:
21
diff
changeset
|
46 public virtual UsbPipeStream GetBulkStream(Byte endpoint) { |
21 | 47 return new UsbPipeStream(this, endpoint, false); |
48 } | |
35
6fcedb1030bf
USBLib: Added support for USBIO driver
Ivo Smits <Ivo@UCIS.nl>
parents:
21
diff
changeset
|
49 public virtual UsbPipeStream GetInterruptStream(Byte endpoint) { |
21 | 50 return new UsbPipeStream(this, endpoint, true); |
51 } | |
52 | |
53 public void Dispose() { | |
54 Close(); | |
55 GC.SuppressFinalize(this); | |
56 } | |
57 ~UsbInterface() { | |
58 Close(); | |
59 } | |
60 } | |
61 } |