Hardware/TBalancer/TBalancer.cs
changeset 384 76f859f4aea1
parent 344 3145aadca3d2
     1.1 --- a/Hardware/TBalancer/TBalancer.cs	Sun Oct 21 14:45:24 2012 +0000
     1.2 +++ b/Hardware/TBalancer/TBalancer.cs	Sat Oct 27 11:40:28 2012 +0000
     1.3 @@ -30,8 +30,9 @@
     1.4      private readonly List<ISensor> deactivating = new List<ISensor>();
     1.5  
     1.6      private FT_HANDLE handle;
     1.7 -    private int[] primaryData = new int[0];
     1.8 -    private int[] alternativeData = new int[0];
     1.9 +    private byte[] data = new byte[285];
    1.10 +    private byte[] primaryData = new byte[0];
    1.11 +    private byte[] alternativeData = new byte[0];
    1.12  
    1.13      public const byte STARTFLAG = 100;
    1.14      public const byte ENDFLAG = 254;
    1.15 @@ -110,7 +111,7 @@
    1.16        }     
    1.17      }
    1.18  
    1.19 -    private void ReadminiNG(int[] data, int number) {
    1.20 +    private void ReadminiNG(int number) {
    1.21        int offset = 1 + number * 65;
    1.22  
    1.23        if (data[offset + 61] != ENDFLAG)
    1.24 @@ -147,9 +148,7 @@
    1.25      }
    1.26  
    1.27      private void ReadData() {
    1.28 -      int[] data = new int[285];
    1.29 -      for (int i = 0; i < data.Length; i++)
    1.30 -        data[i] = FTD2XX.ReadByte(handle);
    1.31 +      FTD2XX.Read(handle, data);
    1.32        
    1.33        if (data[0] != STARTFLAG) {
    1.34          FTD2XX.FT_Purge(handle, FT_PURGE.FT_PURGE_RX);   
    1.35 @@ -161,7 +160,9 @@
    1.36          if (data[274] != protocolVersion) 
    1.37            return;
    1.38  
    1.39 -        this.primaryData = data;
    1.40 +        if (primaryData.Length == 0)
    1.41 +          primaryData = new byte[data.Length];
    1.42 +        data.CopyTo(primaryData, 0);
    1.43  
    1.44          for (int i = 0; i < digitalTemperatures.Length; i++)
    1.45            if (data[238 + i] > 0) {
    1.46 @@ -223,12 +224,14 @@
    1.47          }
    1.48  
    1.49        } else if (data[1] == 253) { // miniNG #1
    1.50 -        this.alternativeData = data;
    1.51 +        if (alternativeData.Length == 0)
    1.52 +          alternativeData = new byte[data.Length];
    1.53 +        data.CopyTo(alternativeData, 0);
    1.54  
    1.55 -        ReadminiNG(data, 0);        
    1.56 +        ReadminiNG(0);        
    1.57                
    1.58          if (data[66] == 253)  // miniNG #2
    1.59 -          ReadminiNG(data, 1);
    1.60 +          ReadminiNG(1);
    1.61        } 
    1.62      }
    1.63