public static void programDACs()
        {
            bias_index             = 0;
            bias_bytes[bias_index] = 0;
            bias_index++;
            bias_bytes[bias_index] = (byte)(outputDriverValue << 4);
            bias_index++;

            BiasName b = 0;

            for (int i = 0; i < 28; i++) //there are 28 bias voltages for this version of the chip
            {
                ChangeBias(b, (int)BiasVoltage[b]);
                b++;
            }
            ATISinterface.SendBiasValues(bias_bytes);

            //temporary file writing for debugging
            string       filename    = "binaryBiases.bin";
            FileStream   propFsBias  = new FileStream(filename, FileMode.Create);
            BinaryWriter DebugWriter = new BinaryWriter(propFsBias);

            DebugWriter.Write(bias_bytes, 0, 114);
            DebugWriter.Close();
            //end debugging

            bias_index = 0;
        }
        private static void ChangeBias(BiasName bname, int voltage)
        {
            BiasVoltage[bname] = voltage;

            UInt16 upper_16 = 0;
            UInt16 lower_16 = 0;
            
            UInt16 polarity = 0;
            UInt32 registerValue;

            //lookup the values
            int searchIndex = 0;
            if (BiasTypes[bname] == BiasType.Voltage)
                if (max_1800[bname] == true)
                {
                    while ((BiasLookup18[searchIndex, 0] < voltage) & (searchIndex < (num_1800_values - 1)))
                        searchIndex++;
                    registerValue = (UInt32)BiasLookup18[searchIndex, 1];
                    polarity = (UInt16)BiasLookup18[searchIndex, 2];
                }
                else
                {
                    while ((BiasLookup33[searchIndex, 0] < voltage) & (searchIndex < (num_3300_values - 1)))
                        searchIndex++;
                    registerValue = (UInt32)BiasLookup33[searchIndex, 1];
                    polarity = (UInt16)BiasLookup18[searchIndex, 2];
                }
            else
                registerValue = 0;


            //create the programming string
            
            //bit 31 (pad enable) set to 0 for internal bias generator

            //bit 30 (internal bias enable) set to 1 for internal bias generator
            upper_16 += 1 << 14;

            //bit 29 is polarity. Set to 1 for N
            upper_16 += (UInt16)(polarity << 13);

            //bit 28 is cascode. Set to 1 for cascode
            if (BiasCascode[bname] == true)
                upper_16 += 1 << 12;

            //bit 27 voltage/current type. Set to 1 for voltage
            if (BiasTypes[bname] == BiasType.Voltage)
                upper_16 += 1 << 11;

            //bit 26:21 = 8;
            upper_16 += 8 << 5;


            


            //bit 20:0 = voltage/current value
            upper_16 += (UInt16)(registerValue >> 16);

            lower_16 += (UInt16)(registerValue);

            bias_bytes[bias_index] = (byte)lower_16;
            bias_index++;
            bias_bytes[bias_index] = (byte)(lower_16>>8);
            bias_index++;
            bias_bytes[bias_index] = (byte)(upper_16);
            bias_index++;
            bias_bytes[bias_index] = (byte)(upper_16 >> 8);
            bias_index++;
        }
        //names                                       APSvrefL-26                               APSvrefH-25                                         APSbiasOut-24                                       APSbiasHyst-23                                      CtrlbiasLP-12                                       APSbiasTail-22                                      CtrlbiasLBBuff-11                                   TDbiasCas-21                                        CtrlbiasDelTD-10                                    TDbiasDiffOff-19                                    CtrlbiasSeqDelAPS-9                                 TDbiasDiffOn-18                                     CtrlbiasDelAPS-8                                    TDbiasInv-20                                        biasSendReqPdY 7                                    TDbiasFo-16                                         biasSendReqPdX-6                                    TDbiasDiff-17                                       CtrlbiasGB-5                                        TDbiasBulk-13                                       TDbiasReqPuY-4                                      TDbiasRefr-15                                       TDbiasReqPuX-3                                      TDbiasPR-14                                         APSbiasReqPuY-2                                     APSbiasReqPuX-1
        /*
        public Int64[] address = new Int64[] { (0 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (15 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (14 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (13 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (12 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (12 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (11 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (11 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (10 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (9 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (9 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (8 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (8 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (10 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (7 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (6 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (6 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (7 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (5 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (3 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (4 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (5 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (3 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (4 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (2 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (1 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)) };
        public Int64[] offset = new Int64[] { (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 26) };
        public int[] BiasMax = new int[] { 3300, 3300, 3300, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 1800 };
        
        
        public int[] BiasNormal = new int[] { 3050, 3150, 750, 620, 620, 700, 950, 2000, 400, 620, 320, 780, 350, 880, 850, 2950, 1150, 700, 970, 2680, 810, 2800, 1240, 3150, 1100, 820 };
        public int[] BiasPresent = new int[] { 3050, 3150, 750, 620, 620, 700, 950, 2000, 400, 620, 320, 780, 350, 880, 850, 2950, 1150, 700, 970, 2680, 810, 2800, 1240, 3150, 1100, 820 };
         * */
        //public int[] BiasCustom = new int[] { 2300, 3150, 750, 620, 620, 700, 950, 2000, 400, 550,/*570*/           320, 800/*800*/, 350, 880, 850, 2900, 1150,               /*590*/600, 970, 2680, 810, 2400, 1240, 2750, 1100, 820 };
        //private int[] BiasFast = new int[] { 3050, 3150, 750, 620, 620, 700, 950, 2000, 400, 520, 320, 720, 350, 790, 850, 2950, 1150, 600, 970, 2680, 810, 2900, 1240, 2950, 1100, 820 };
        //private int[] BiasFast = new int[] {      3050,           3150,           750,            620,                620,                700,                950,                2000,               400,                    520,                    320,                720,                350,                    790,                850,                2950,           1150,               600,            970,            2680,           810,                2900,           1240,              2950,            1100,               820 };
        //names                                 APSvrefL-26     APSvrefH-25     APSbiasOut-24   APSbiasHyst-23      CtrlbiasLP-12       APSbiasTail-22      CtrlbiasLBBuff-11   TDbiasCas-21        CtrlbiasDelTD-10        TDbiasDiffOff-19    CtrlbiasSeqDelAPS-9     TDbiasDiffOn-18     CtrlbiasDelAPS-8        TDbiasInv-20        biasSendReqPdY 7    TDbiasFo-16     biasSendReqPdX-6   TDbiasDiff-17   CtrlbiasGB-5    TDbiasBulk-13   TDbiasReqPuY-4      TDbiasRefr-15   TDbiasReqPuX-3      TDbiasPR-14     APSbiasReqPuY-2     APSbiasReqPuX-1                
        #endregion

        public static void ModifyBias(BiasName bname, int voltage)
        {
            BiasVoltage[bname] = voltage;
        }
        private static void ChangeBias(BiasName bname, int voltage)
        {
            BiasVoltage[bname] = voltage;

            UInt16 upper_16 = 0;
            UInt16 lower_16 = 0;

            UInt16 polarity = 0;
            UInt32 registerValue;

            //lookup the values
            int searchIndex = 0;

            if (BiasTypes[bname] == BiasType.Voltage)
            {
                if (max_1800[bname] == true)
                {
                    while ((BiasLookup18[searchIndex, 0] < voltage) & (searchIndex < (num_1800_values - 1)))
                    {
                        searchIndex++;
                    }
                    registerValue = (UInt32)BiasLookup18[searchIndex, 1];
                    polarity      = (UInt16)BiasLookup18[searchIndex, 2];
                }
                else
                {
                    while ((BiasLookup33[searchIndex, 0] < voltage) & (searchIndex < (num_3300_values - 1)))
                    {
                        searchIndex++;
                    }
                    registerValue = (UInt32)BiasLookup33[searchIndex, 1];
                    polarity      = (UInt16)BiasLookup18[searchIndex, 2];
                }
            }
            else
            {
                registerValue = 0;
            }


            //create the programming string

            //bit 31 (pad enable) set to 0 for internal bias generator

            //bit 30 (internal bias enable) set to 1 for internal bias generator
            upper_16 += 1 << 14;

            //bit 29 is polarity. Set to 1 for N
            upper_16 += (UInt16)(polarity << 13);

            //bit 28 is cascode. Set to 1 for cascode
            if (BiasCascode[bname] == true)
            {
                upper_16 += 1 << 12;
            }

            //bit 27 voltage/current type. Set to 1 for voltage
            if (BiasTypes[bname] == BiasType.Voltage)
            {
                upper_16 += 1 << 11;
            }

            //bit 26:21 = 8;
            upper_16 += 8 << 5;



            //bit 20:0 = voltage/current value
            upper_16 += (UInt16)(registerValue >> 16);

            lower_16 += (UInt16)(registerValue);

            bias_bytes[bias_index] = (byte)lower_16;
            bias_index++;
            bias_bytes[bias_index] = (byte)(lower_16 >> 8);
            bias_index++;
            bias_bytes[bias_index] = (byte)(upper_16);
            bias_index++;
            bias_bytes[bias_index] = (byte)(upper_16 >> 8);
            bias_index++;
        }
        //names                                       APSvrefL-26                               APSvrefH-25                                         APSbiasOut-24                                       APSbiasHyst-23                                      CtrlbiasLP-12                                       APSbiasTail-22                                      CtrlbiasLBBuff-11                                   TDbiasCas-21                                        CtrlbiasDelTD-10                                    TDbiasDiffOff-19                                    CtrlbiasSeqDelAPS-9                                 TDbiasDiffOn-18                                     CtrlbiasDelAPS-8                                    TDbiasInv-20                                        biasSendReqPdY 7                                    TDbiasFo-16                                         biasSendReqPdX-6                                    TDbiasDiff-17                                       CtrlbiasGB-5                                        TDbiasBulk-13                                       TDbiasReqPuY-4                                      TDbiasRefr-15                                       TDbiasReqPuX-3                                      TDbiasPR-14                                         APSbiasReqPuY-2                                     APSbiasReqPuX-1

        /*
         * public Int64[] address = new Int64[] { (0 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (15 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (14 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (13 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (12 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (12 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (11 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (11 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (10 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (9 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (9 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (8 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (8 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (10 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (7 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (6 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (6 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (7 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (5 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (3 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (4 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (5 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (3 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (4 * (Int64)Math.Pow(2.0, 16) + 3 * (Int64)Math.Pow(2.0, 14)), (2 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)), (1 * (Int64)Math.Pow(2.0, 40) + 3 * (Int64)Math.Pow(2.0, 38)) };
         * public Int64[] offset = new Int64[] { (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 2), (Int64)Math.Pow(2.0, 26), (Int64)Math.Pow(2.0, 26) };
         * public int[] BiasMax = new int[] { 3300, 3300, 3300, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 3300, 1800, 1800 };
         *
         *
         * public int[] BiasNormal = new int[] { 3050, 3150, 750, 620, 620, 700, 950, 2000, 400, 620, 320, 780, 350, 880, 850, 2950, 1150, 700, 970, 2680, 810, 2800, 1240, 3150, 1100, 820 };
         * public int[] BiasPresent = new int[] { 3050, 3150, 750, 620, 620, 700, 950, 2000, 400, 620, 320, 780, 350, 880, 850, 2950, 1150, 700, 970, 2680, 810, 2800, 1240, 3150, 1100, 820 };
         * */
        //public int[] BiasCustom = new int[] { 2300, 3150, 750, 620, 620, 700, 950, 2000, 400, 550,/*570*/           320, 800/*800*/, 350, 880, 850, 2900, 1150,               /*590*/600, 970, 2680, 810, 2400, 1240, 2750, 1100, 820 };
        //private int[] BiasFast = new int[] { 3050, 3150, 750, 620, 620, 700, 950, 2000, 400, 520, 320, 720, 350, 790, 850, 2950, 1150, 600, 970, 2680, 810, 2900, 1240, 2950, 1100, 820 };
        //private int[] BiasFast = new int[] {      3050,           3150,           750,            620,                620,                700,                950,                2000,               400,                    520,                    320,                720,                350,                    790,                850,                2950,           1150,               600,            970,            2680,           810,                2900,           1240,              2950,            1100,               820 };
        //names                                 APSvrefL-26     APSvrefH-25     APSbiasOut-24   APSbiasHyst-23      CtrlbiasLP-12       APSbiasTail-22      CtrlbiasLBBuff-11   TDbiasCas-21        CtrlbiasDelTD-10        TDbiasDiffOff-19    CtrlbiasSeqDelAPS-9     TDbiasDiffOn-18     CtrlbiasDelAPS-8        TDbiasInv-20        biasSendReqPdY 7    TDbiasFo-16     biasSendReqPdX-6   TDbiasDiff-17   CtrlbiasGB-5    TDbiasBulk-13   TDbiasReqPuY-4      TDbiasRefr-15   TDbiasReqPuX-3      TDbiasPR-14     APSbiasReqPuY-2     APSbiasReqPuX-1
        #endregion

        public static void ModifyBias(BiasName bname, int voltage)
        {
            BiasVoltage[bname] = voltage;
        }