Mercurial > hg > ucis.core
diff USBLib/Communication/LibUsbDotNet.cs @ 67:2d16447eff12
Simplified USB communication code, added functions to abort pipe transfers
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Wed, 16 Oct 2013 01:11:49 +0200 |
parents | abe0d55a2201 |
children |
line wrap: on
line diff
--- a/USBLib/Communication/LibUsbDotNet.cs Tue Oct 15 16:22:54 2013 +0200 +++ b/USBLib/Communication/LibUsbDotNet.cs Wed Oct 16 01:11:49 2013 +0200 @@ -34,11 +34,7 @@ } } public bool ControlTransfer(ref UsbSetupPacket setupPacket, Byte[] buffer, int bufferLength, out int lengthTransferred) { - if ((setupPacket.RequestType & 128) != 0) { - lengthTransferred = Device.ControlRead((UsbControlRequestType)setupPacket.RequestType, setupPacket.Request, setupPacket.Value, setupPacket.Index, buffer, 0, bufferLength); - } else { - lengthTransferred = Device.ControlWrite((UsbControlRequestType)setupPacket.RequestType, setupPacket.Request, setupPacket.Value, setupPacket.Index, buffer, 0, bufferLength); - } + lengthTransferred = Device.ControlTransfer((UsbControlRequestType)setupPacket.RequestType, setupPacket.Request, setupPacket.Value, setupPacket.Index, buffer, 0, bufferLength); return true; } public UsbEndpointReader OpenEndpointReader(ReadEndpointID readEndpointID, int buffersize, EndpointType endpointType) { @@ -139,11 +135,7 @@ ReadBufferSize = 4096; } public ErrorCode Read(byte[] buffer, int offset, int count, int timeout, out int transferLength) { - switch (EndpointType) { - case EndpointType.Bulk: transferLength = Device.BulkRead(EndpointID, buffer, offset, count); break; - case EndpointType.Interrupt: transferLength = Device.InterruptRead(EndpointID, buffer, offset, count); break; - default: transferLength = 0; return ErrorCode.Error; - } + transferLength = Device.PipeTransfer(EndpointID, buffer, offset, count); return ErrorCode.Ok; } public void Dispose() { DataReceivedEnabled = false; }