Пример #1
0
        private static void VoltageTest()
        {
            System.Console.WriteLine("Connecting to instruments");
            Agilent.AgU3606x.Interop.IAgU3606x u3606a_dev1 = new Agilent.AgU3606x.Interop.AgU3606xClass();
            u3606a_dev1.Initialize("USBInstrument1", false, false, "");
            Agilent.AgU3606x.Interop.IAgU3606x u3606a_dev2 = new Agilent.AgU3606x.Interop.AgU3606xClass();
            u3606a_dev2.Initialize("USBInstrument2", false, false, "");
            Agilent.AgU3606x.Interop.IAgU3606x u3606a_dev3 = new Agilent.AgU3606x.Interop.AgU3606xClass();
            u3606a_dev3.Initialize("USBInstrument3", false, false, "");
            Agilent.AgU3606x.Interop.IAgU3606x u3606a_dev4 = new Agilent.AgU3606x.Interop.AgU3606xClass();
            u3606a_dev4.Initialize("USBInstrument4", false, false, "");

#if WITH_TEMP
            U1272A meter = new U1272A("COM10");
#endif
#if WITH_SIMDEBUG
            Replayer board = new Replayer("COM1");
#endif

            System.Console.WriteLine("{0},{1},{2},{3}", u3606a_dev1.Identity.InstrumentManufacturer, 
                                                        u3606a_dev1.Identity.InstrumentModel,
                                                        u3606a_dev1.Identity.Revision, 
                                                        u3606a_dev1.Identity.InstrumentFirmwareRevision
                                                        );
            System.Console.WriteLine("{0},{1},{2},{3}", u3606a_dev2.Identity.InstrumentManufacturer,
                                                        u3606a_dev2.Identity.InstrumentModel,
                                                        u3606a_dev2.Identity.Revision,
                                                        u3606a_dev2.Identity.InstrumentFirmwareRevision
                                                        );
            System.Console.WriteLine("{0},{1},{2},{3}", u3606a_dev3.Identity.InstrumentManufacturer,
                                                        u3606a_dev3.Identity.InstrumentModel,
                                                        u3606a_dev3.Identity.Revision,
                                                        u3606a_dev3.Identity.InstrumentFirmwareRevision
                                                        );
            System.Console.WriteLine("{0},{1},{2},{3}", u3606a_dev4.Identity.InstrumentManufacturer,
                                                        u3606a_dev4.Identity.InstrumentModel,
                                                        u3606a_dev4.Identity.Revision,
                                                        u3606a_dev4.Identity.InstrumentFirmwareRevision
                                                        );
#if WITH_TEMP
            System.Console.WriteLine(meter.Identification());
#endif
#if WITH_SIMDEBUG
            System.Console.WriteLine(board.getVersion());
#endif


            // max 5V, low resolution for speed
            u3606a_dev1.Voltage.DC.Configure(5, Agilent.AgU3606x.Interop.AgU3606xResolutionEnum.AgU3606xResolutionLeast);
            u3606a_dev1.Measurement.SetInitiateContinuous(true);

            // 2 A range, low resolution for speed
            u3606a_dev2.Current.DC.Configure(2, Agilent.AgU3606x.Interop.AgU3606xResolutionEnum.AgU3606xResolutionLeast);
            u3606a_dev2.Measurement.SetInitiateContinuous(true);

            // max 15V, low resolution for speed
            u3606a_dev3.Voltage.DC.Configure(15, Agilent.AgU3606x.Interop.AgU3606xResolutionEnum.AgU3606xResolutionLeast);
            u3606a_dev3.Measurement.SetInitiateContinuous(true);

            // max 15V, low resolution for speed
            u3606a_dev4.Voltage.DC.Configure(15, Agilent.AgU3606x.Interop.AgU3606xResolutionEnum.AgU3606xResolutionLeast);
            u3606a_dev4.Measurement.SetInitiateContinuous(true);

            // enable output
            u3606a_dev2.Output.Enabled = true;
            u3606a_dev3.Output.Enabled = true;
            u3606a_dev4.Output.Enabled = true;
           
            double voltage = 0;
            double current = 0;
            double Vb = 0;
            double Ve = 0;
            double temperature = 0;
            var stopwatch = Stopwatch.StartNew();
            string time;
            string line;
            var start_time = DateTime.UtcNow;

            StreamWriter log_file = File.AppendText("multimeter_debug_log.csv");
            // write header
#if WITH_SIMDEBUG
            log_file.WriteLine("Time, Voltage, Current, Vb, Ve, Vbe, R_equiv, Temp(C), xmin, xmax, Vpred, Ipred, m_meas, error, delta, Vout, Iout, Gain, OP Vout");
#else
            log_file.WriteLine("Time, Voltage, Current, Vb, Ve, Vbe, R_equiv, Temp(C)");
#endif
            u3606a_dev1.Measurement.Fetch();
            u3606a_dev2.Measurement.Fetch();
            u3606a_dev3.Measurement.Fetch();
            u3606a_dev4.Measurement.Fetch();
            try
            {
                while (keepRunning)
                {

#if VERBOSE
                    stopwatch = Stopwatch.StartNew();
#endif
                    #region ParallelTasks
                    Parallel.Invoke(() =>
                    {
                        voltage = u3606a_dev1.Measurement.Fetch();
                    },
                    () =>
                    {
                        current = u3606a_dev2.Measurement.Fetch();
                    },
                    () =>
                    {
                        Vb = u3606a_dev3.Measurement.Fetch();
                    },

                    () =>
                    {
                        Ve = u3606a_dev4.Measurement.Fetch();
                    },


                    () =>
                    {
#if WITH_TEMP
                        temperature = Convert.ToDouble(meter.Fetch());   
#endif
                    });
                    #endregion                    

                    time = DateTime.Now.ToString("hh:mm:ss.fff tt");


#if VERBOSE
                stopwatch.Stop(); 
                Console.WriteLine(stopwatch.ElapsedMilliseconds);
                Console.WriteLine(time);
                Console.WriteLine("V: {0:0.0000}", voltage);
                Console.WriteLine("I: {0:0.0000}", current);
                Console.WriteLine("Vb: {0:0.0000}", Vb);
                Console.WriteLine("Temp (C): {0:0.0000}", temperature);
#endif

#if WITH_SIMDEBUG
                    ReplayerBoard.DebugData db = board.getDebugData();                    
                    line = string.Join(", ", new string[] { time, voltage.ToString(), current.ToString(), Vb.ToString(), Ve.ToString(), (Vb-Ve).ToString(), (voltage/current).ToString(), temperature.ToString(), db.xmin.ToString(), db.xmax.ToString(), db.Vpred.ToString(), db.Ipred.ToString(), db.m_meas.ToString(), db.error.ToString(), db.delta.ToString(), db.Vout.ToString(), db.current.ToString(), db.gain.ToString(), db.operating_point_vout.ToString() });
#else
                    line = string.Join(", ", new string[] { time, voltage.ToString(), current.ToString(), Vb.ToString(), Ve.ToString(), (Vb-Ve).ToString(), (voltage/current).ToString(), temperature.ToString() });
#endif
                    Console.WriteLine(line);
                    log_file.WriteLine(line);

#if WITH_AUTO_STOP
                    if ((DateTime.UtcNow - start_time) > TimeSpan.FromSeconds(STOP_TIME))
                    {
                        keepRunning = false;
                        // disable output                        
                        u3606a_dev3.Output.Enabled = false;
                    }                            
#endif
                }
            }
            catch (AggregateException ae)
            {
                Console.WriteLine("Exception");
            }

#if WITH_AUTO_STOP
            u3606a_dev3.Output.Enabled = false;
#endif
            u3606a_dev1.Close();
            u3606a_dev2.Close();
            u3606a_dev3.Close();
            u3606a_dev4.Close();
            log_file.Close();
            Console.WriteLine("Exiting");

        }
Пример #2
0
        private static void DarlingtonTest()
        {
            System.Console.WriteLine("Connecting to instruments");
            Agilent.AgU3606x.Interop.IAgU3606x u3606a_dev1 = new Agilent.AgU3606x.Interop.AgU3606xClass();
            u3606a_dev1.Initialize("USBInstrument1", false, false, "");
            Agilent.AgU3606x.Interop.IAgU3606x u3606a_dev2 = new Agilent.AgU3606x.Interop.AgU3606xClass();
            u3606a_dev2.Initialize("USBInstrument2", false, false, "");
            Agilent.AgU3606x.Interop.IAgU3606x u3606a_dev3 = new Agilent.AgU3606x.Interop.AgU3606xClass();
            u3606a_dev3.Initialize("USBInstrument3", false, false, "");
            Agilent.AgU3606x.Interop.IAgU3606x u3606a_dev4 = new Agilent.AgU3606x.Interop.AgU3606xClass();
            u3606a_dev4.Initialize("USBInstrument4", false, false, "");
            
            U1272A meter = new U1272A("COM10");
            Replayer board = new Replayer("COM1");

            System.Console.WriteLine("{0},{1},{2},{3}", u3606a_dev1.Identity.InstrumentManufacturer, 
                                                        u3606a_dev1.Identity.InstrumentModel,
                                                        u3606a_dev1.Identity.Revision, 
                                                        u3606a_dev1.Identity.InstrumentFirmwareRevision
                                                        );
            System.Console.WriteLine("{0},{1},{2},{3}", u3606a_dev2.Identity.InstrumentManufacturer,
                                                        u3606a_dev2.Identity.InstrumentModel,
                                                        u3606a_dev2.Identity.Revision,
                                                        u3606a_dev2.Identity.InstrumentFirmwareRevision
                                                        );
            System.Console.WriteLine("{0},{1},{2},{3}", u3606a_dev3.Identity.InstrumentManufacturer,
                                                        u3606a_dev3.Identity.InstrumentModel,
                                                        u3606a_dev3.Identity.Revision,
                                                        u3606a_dev3.Identity.InstrumentFirmwareRevision
                                                        );
            System.Console.WriteLine("{0},{1},{2},{3}", u3606a_dev4.Identity.InstrumentManufacturer,
                                                        u3606a_dev4.Identity.InstrumentModel,
                                                        u3606a_dev4.Identity.Revision,
                                                        u3606a_dev4.Identity.InstrumentFirmwareRevision
                                                        );
            System.Console.WriteLine(meter.Identification());
            System.Console.WriteLine(board.getVersion());


            // max 5V, low resolution for speed
            u3606a_dev1.Voltage.DC.Configure(5, Agilent.AgU3606x.Interop.AgU3606xResolutionEnum.AgU3606xResolutionLeast);
            u3606a_dev1.Measurement.SetInitiateContinuous(true);

            // 1 A range, low resolution for speed
            u3606a_dev2.Current.DC.Configure(1, Agilent.AgU3606x.Interop.AgU3606xResolutionEnum.AgU3606xResolutionLeast);
            u3606a_dev2.Measurement.SetInitiateContinuous(true);

            // max 15V, low resolution for speed
            u3606a_dev3.Voltage.DC.Configure(15, Agilent.AgU3606x.Interop.AgU3606xResolutionEnum.AgU3606xResolutionLeast);
            u3606a_dev3.Measurement.SetInitiateContinuous(true);

            // max 15V, low resolution for speed
            u3606a_dev4.Voltage.DC.Configure(15, Agilent.AgU3606x.Interop.AgU3606xResolutionEnum.AgU3606xResolutionLeast);
            u3606a_dev4.Measurement.SetInitiateContinuous(true);

            float Ve_board;
            float Ve_max;
            float Ve_min;
            float Ve_delta;
            float Vb_board;
            float Vbe_on;
            float Vbe_sat;
            float Vb_delta;
            bool low_power = false;
            double voltage = 0;
            double current = 0;
            double Vb = 0;
            double Ve = 0;
            double temperature = 0;
            var stopwatch = Stopwatch.StartNew();
            string time;
            string line;
            
            //board.setVE(Ve_board);
            //board.setVB(Vb_board);

            // set amp gain to lowest
            board.setGain(AD8253.GAIN_1);

            StreamWriter log_file = File.AppendText("multimeter_log.csv");
            // write header
            if (new FileInfo("multimeter_log.csv").Length == 0)
            {
                log_file.WriteLine("Time, Voltage, Current, Vb, Ve, Vbe, R_equiv, Temp(C)");
            }
            // set parameters
            if (low_power)
            {
                Ve_max = 6.5F;
                Ve_min = 6.0F;
                Ve_delta = 0.5F;
                Vbe_on = 0.6F;
                Vbe_sat = 1.3F;
                Vb_delta = 0.003F;
            }
            else
            {
                Ve_max = 10.0F;
                Ve_min = 9.5F;
                Ve_delta = 0.5F;
                Vbe_on = 1.2F;
                Vbe_sat = 1.3F;
                Vb_delta = 0.0005F;
            }
            try
            {
#if BENCHMARK_SWEEP
                for (Ve_board = Ve_max; Ve_board > Ve_min; Ve_board -= Ve_delta)
                {
                    board.setVE(Ve_board);
                    for (Vb_board = Ve_board - Vbe_on; Vb_board > Ve_board - Vbe_sat; Vb_board -= Vb_delta)
                    {
                        for (int i = 0; i < 1; i++)
                        {
                            board.setVB(Vb_board);
                            System.Console.WriteLine("Ve: {0}, Vb: {1}", Ve_board, Vb_board);
                            Thread.Sleep(3000);

#if VERBOSE
                    stopwatch = Stopwatch.StartNew();
#endif
                            #region ParallelTasks
                            Parallel.Invoke(() =>
                            {
                                voltage = u3606a_dev1.Measurement.Fetch();
                            },
                            () =>
                            {
                                current = u3606a_dev2.Measurement.Fetch();
                            },
                            () =>
                            {
                                Vb = u3606a_dev3.Measurement.Fetch();
                            },

                            () =>
                            {
                                Ve = u3606a_dev4.Measurement.Fetch();
                            },

                            () =>
                            {
                                temperature = Convert.ToDouble(meter.Fetch());
                            });
                            #endregion

                            //time = DateTime.Now.ToLongTimeString();
                            time = DateTime.Now.ToString("hh:mm:ss.fff tt");


#if VERBOSE
                stopwatch.Stop(); 
                Console.WriteLine(stopwatch.ElapsedMilliseconds);
                Console.WriteLine(time);
                Console.WriteLine("V: {0:0.0000}", voltage);
                Console.WriteLine("I: {0:0.0000}", current);
                Console.WriteLine("Vb: {0:0.0000}", Vb);
                Console.WriteLine("Temp (C): {0:0.0000}", temperature);
#endif

                            line = string.Join(", ", new string[] { time, voltage.ToString(), current.ToString(), Vb.ToString(), Ve.ToString(), (Vb - Ve).ToString(), (voltage / current).ToString(), temperature.ToString() });
                            Console.WriteLine(line);
                            log_file.WriteLine(line);                            

                            if (!keepRunning)
                                goto Exit;
                        }
                    }
                }

#endif
            }
            catch (AggregateException ae)
            {
                Console.WriteLine("Exception");
            }

            Exit:
            // put in cutoff
            board.setVE(4.0F);
            board.setVB(4.0F);


            u3606a_dev1.Close();
            u3606a_dev2.Close();
            u3606a_dev3.Close();
            u3606a_dev4.Close();
            log_file.Close();
            Console.WriteLine("Exiting");

        }