Hardware/TBalancer/FTD2XX.cs
changeset 384 76f859f4aea1
parent 344 3145aadca3d2
     1.1 --- a/Hardware/TBalancer/FTD2XX.cs	Sun Oct 21 14:45:24 2012 +0000
     1.2 +++ b/Hardware/TBalancer/FTD2XX.cs	Sat Oct 27 11:40:28 2012 +0000
     1.3 @@ -4,7 +4,7 @@
     1.4    License, v. 2.0. If a copy of the MPL was not distributed with this
     1.5    file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.6   
     1.7 -  Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
     1.8 +  Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     1.9  	
    1.10  */
    1.11  
    1.12 @@ -99,6 +99,8 @@
    1.13        out uint amountInRxQueue, out uint amountInTxQueue, out uint eventStatus);
    1.14      public delegate FT_STATUS FT_ReadDelegate(FT_HANDLE handle, 
    1.15        [Out] byte[] buffer, uint bytesToRead, out uint bytesReturned);
    1.16 +    public delegate FT_STATUS FT_ReadByteDelegate(FT_HANDLE handle,
    1.17 +      out byte buffer, uint bytesToRead, out uint bytesReturned);
    1.18  
    1.19      public static readonly FT_CreateDeviceInfoListDelegate 
    1.20        FT_CreateDeviceInfoList = CreateDelegate<
    1.21 @@ -136,6 +138,9 @@
    1.22      public static readonly FT_ReadDelegate 
    1.23        FT_Read = CreateDelegate<
    1.24        FT_ReadDelegate>("FT_Read");
    1.25 +    public static readonly FT_ReadByteDelegate
    1.26 +      FT_ReadByte = CreateDelegate<
    1.27 +      FT_ReadByteDelegate>("FT_Read");
    1.28  
    1.29      private FTD2XX() { }
    1.30  
    1.31 @@ -162,12 +167,20 @@
    1.32      }
    1.33  
    1.34      public static byte ReadByte(FT_HANDLE handle) {
    1.35 -      byte[] buffer = new byte[1];
    1.36 +      byte buffer;
    1.37        uint bytesReturned;
    1.38 -      FT_STATUS status = FT_Read(handle, buffer, 1, out bytesReturned);
    1.39 +      FT_STATUS status = FT_ReadByte(handle, out buffer, 1, out bytesReturned);
    1.40        if (status != FT_STATUS.FT_OK || bytesReturned != 1)
    1.41          throw new InvalidOperationException();
    1.42 -      return buffer[0];
    1.43 +      return buffer;
    1.44 +    }
    1.45 +
    1.46 +    public static void Read(FT_HANDLE handle, byte[] buffer) {
    1.47 +      uint bytesReturned;
    1.48 +      FT_STATUS status = 
    1.49 +        FT_Read(handle, buffer, (uint)buffer.Length, out bytesReturned);
    1.50 +      if (status != FT_STATUS.FT_OK || bytesReturned != buffer.Length)
    1.51 +        throw new InvalidOperationException();
    1.52      }
    1.53  
    1.54      private static string GetDllName() {