public void checkFreqValidity(double fine, ref double freq, int coarse, FTDIdevice thisUSB, Device device, SSLInterface ssl)
 {
     //makes sure freq isn't out of range or a duplicate measurement, using the following general procedure: if it's invalid, measure it again; if it's still invalid, throw error.
     if (freq > 12001400 || freq < 11998000) // if out of range of trimming
     {
         //first, try again
         freq = FreqAtTrim(thisUSB, ssl, coarse, Convert.ToInt32(fine));
         //if freq is wildly off, probably unseated
         if (freq > 12010000 || freq < 11990000) throw new Exception_Yellow("Frequency counter range error (coarse " + coarse.ToString() + " fine " + fine.ToString() + " " + freq.ToString() + "). Please ensure that board is properly seated and try again.  If error persists, testing fails.");
         if (freq > 12001400 || freq < 11998000) throw new Exception_Red("Crystal frequency is outside acceptable range (coarse " + FinalCoarse.ToString() + " fine " + FinalFine.ToString() + "). Testing fails. Insert a new board and press \"Run Test\" or Enter.");  // freqency is too far from 12 MHz to be trimmed
     }    //        (make sure that this catches a null freq)
     //if this frequency is more than twice as close as we'd expect to the previous measurement, probably unseated:
     if (previouscoarseforchecking != -12345) //if this is not the first time we're running a check
     {
         if (coarse == previouscoarseforchecking && Convert.ToInt32(fine) != Convert.ToInt32(previousfineforchecking))  //if fine trims can be compared on their own
         {
             if ((freq - previousfreqforchecking) / (finetrimsizeinHz * (fine - previousfineforchecking)) < .5)
             {
                 freq = FreqAtTrim(thisUSB, ssl, coarse, Convert.ToInt32(fine));
                 if ((freq - previousfreqforchecking) / (finetrimsizeinHz * (Convert.ToInt32(fine) - Convert.ToInt32(previousfineforchecking))) < .5) throw new Exception_Yellow("Frequency counter repeat or anomaly error (coarse " + coarse.ToString() + " fine " + fine.ToString() + " " + freq.ToString() + "). Please ensure that board is properly seated and try again.  If error persists, testing fails.");
             }
         }
         else if (Math.Abs(freq - previousfreqforchecking) < .3 * finetrimsizeinHz)
         {
             freq = FreqAtTrim(thisUSB, ssl, coarse, Convert.ToInt32(fine));
             if (Math.Abs(freq - previousfreqforchecking) < .3 * finetrimsizeinHz) throw new Exception_Yellow("Frequency counter repeat or anomaly error (coarse " + coarse.ToString() + " fine " + fine.ToString() + " " + freq.ToString() + "). Please ensure that board is properly seated and try again.  If error persists, testing fails.");
         }
     }
     previousfreqforchecking = freq;
     previousfineforchecking = fine;
     previouscoarseforchecking = coarse;
 }
Example #2
0
        /// <summary>
        /// 打开串口
        /// </summary>
        /// <param name="comName"></param>
        /// <param name="er"></param>
        /// <param name="setting"></param>
        /// <returns></returns>
        public bool Open(string comName, out string er, string setting = "9600,n,8,1")
        {
            er = string.Empty;

            try
            {
                if (com != null)
                {
                    com.Dispose();
                    com = null;
                }

                int boardNum = System.Convert.ToInt16(comName);

                byte primaryAddress = System.Convert.ToByte(setting);

                byte secondaryAddress = 0;

                com = new NationalInstruments.NI4882.Device(boardNum, primaryAddress, secondaryAddress);

                _conStatus = true;

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
        }
 public Trimmer(Parameters pars, FTDIdevice USB)
 {
     parameters = pars;
     thisUSB = USB;
     //Frequency counter must be programmed with the following address information: GPIB ID 0, primary address 9, and no secondary address.
     //FREQ_COUNTER = new Device(0, 15, 0); // create an object to hold the frequency counter, with GPIB ID 0, primary addr 9, and no secondary addr.  the primary addr was manually set on the counter itself.
     FREQ_COUNTER = new Device(0, parameters.counter_id, 0); // create an object to hold the frequency counter, with GPIB ID 0, primary addr 9, and no secondary addr.  the primary addr was manually set on the counter itself.
 }
Example #4
0
        public mainform()
        {
            InitializeComponent();

            //Disposing of old GPIB settings for the LIA.
            Byte newliagpib = Convert.ToByte(LIA_GPIB.Text);
            LIA = new Device(0, newliagpib, 0);

            //Disposing of old GPIB settings for the monochromator.
            Byte newgpib = Convert.ToByte(MC_GPIB.Text);
            monochromator = new Device(0, newgpib, 0);

            //Filters:

            //Clears list from previous settings
            currentfilter.Items.Clear();
            newfilter.Items.Clear();

            //Builds new lists with previously defined filters
            this.currentfilter.Items.AddRange(new object[] {
                Filter1,
                Filter2,
                Filter3,
                Filter4,
                Filter5,
                Filter6});

            this.newfilter.Items.AddRange(new object[] {
                Filter1,
                Filter2,
                Filter3,
                Filter4,
                Filter5,
                Filter6});

            //Monochromator default selection:
            automotorspeed.SelectedItem = "400";
            motorspeed.SelectedItem = "100";
            currentfilter.SelectedItem = Filter1;
            newfilter.SelectedItem = Filter1;
            autounits.SelectedItem = "Dial";
            MCmanunit.SelectedItem = "Dial";
            //Remember that "D0200T\n" will rotate filter wheel 360 degrees.

            //Calibration - These are default values for the diffraction grating and offset.
            grating.Text = "598.96";
            offset.Text = "-21.57";

            //Lock-In Amplifier default selection:
            input.SelectedItem = "Voltage: A";
            linefilter.SelectedItem = "50 and 100Hz";

            //Operation tab default selection:
            sweepstart.Text = "500";
            sweepend.Text = "2500";
            sweepstartunit.SelectedItem = "Wavelength (nm)";
            sweependunit.SelectedItem = "Wavelength (nm)";
        }
        public static void SetDAC(int n, double v)
        {
            Device device = new Device(0, 12, 0);
            device.SetEndOnEndOfString = true;
            device.SetEndOnWrite = true;

            device.Write(String.Format("DAC. {0} {1}", n.ToString(), v.ToString("F4")));

            device.Dispose();
        }
Example #6
0
 internal void GPIBOpen()
 {
     try
     {
         this.device = new Device(this._BoardID, this._PrimaryAddress, this._SecondaryAddress);
     }
     catch (Exception exception)
     {
         this.device = null;
         MessageBox.Show(exception.Message);
     }
 }
Example #7
0
        /// <summary>
        /// 关闭串口
        /// </summary>
        public void Close()
        {
            if (com == null)
            {
                return;
            }

            com.Dispose();

            com = null;

            _conStatus = false;
        }
Example #8
0
        static void Main(string[] args)
        {
            var device = new Device(0, new Address(12, 96));
            device.Write("*IDN?");
            string data = device.ReadString();
            Console.WriteLine(data);
            Console.ReadLine();

            //device.Write("DAT:SOU CH1");
            //device.Write("DAT:ENC RIB;WID 1");
            //device.Write("HOR:RECORDL 500");
            //device.Write("DAT:STAR 1");
            //device.Write("DAT:STOP 500");
            //device.Write("HEAD OFF");
            //device.Write("ACQ:STATE RUN");

            //device.Write("WFMPRE:CH1:NR_PT?;YOFF?;YMULT?;XINCR?;PT_OFF?;XUNIT?;YUNIT?WFMPRE:CH1:NR_PT?;YOFF?;YMULT?;XINCR?;PT_OFF?;XUNIT?;YUNIT?");
            //data = device.ReadString();
            //Console.WriteLine(data);
            //Console.ReadLine();
            for (int i = 0; i < 100; i++)
            {
                device.Write("curv?");
                device.ReadByteArray(1);
                int length = Convert.ToInt32(System.Text.Encoding.ASCII.GetString(device.ReadByteArray(1)));
                int count = Convert.ToInt32(System.Text.Encoding.ASCII.GetString(device.ReadByteArray(length)));
                Byte[] curve = device.ReadByteArray(count);
                foreach(byte b in curve)
                {
                    int number = Convert.ToInt32( b);
                    Console.Write(number+",");
                }
                Console.WriteLine();

                device.Write("curv?");
                data = device.ReadString();
                Console.WriteLine(data.Length);
                length = Convert.ToInt32(data[1].ToString());
                for(int j= 2 + length; j < data.Length; j++)
                {
                    int number = (int)data[j] ;
                    Console.Write(number + ",");
                }
                Console.WriteLine();
                Console.WriteLine(data);
            }
            Console.ReadLine();
        }
Example #9
0
        /*public static bool IsDeviceOpen()
         * {
         *  return bDeviceOpen;
         * }*/

        public static void InitDevice(byte Address)    //Open device at specified address. GPIB address of each function generator set via front panel controls
        {
            if (!bDeviceOpen)
            {
                try
                {
                    device = new Device(0, Address, 0);
                    device.Write("AMPL:STATE ON");    //Try switching on RF output for selected device, if no device present, exception will be thrown
                    bDeviceOpen = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #10
0
        /*public static bool IsDeviceOpen()
        {
            return bDeviceOpen;
        }*/

        public static void InitDevice(byte Address)    //Open device at specified address. GPIB address of each function generator set via front panel controls
        {
            if (!bDeviceOpen)
            {
                try
                {
                    device = new Device(0, Address, 0);
                    device.Write("AMPL:STATE ON");    //Try switching on RF output for selected device, if no device present, exception will be thrown
                    bDeviceOpen = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        public static double AverageADC(int n, int samples)
        {
            Device device = new Device(0, 12, 0);
            device.SetEndOnEndOfString = true;
            device.SetEndOnWrite = true;

            var V = Vector<double>.Build;
            var data = V.Dense(samples);
            for (int i = 0; i < samples; i++)
            {
                device.Write("ADC.2");
                string response = device.ReadString();
                data[i] = Convert.ToDouble(response);
            }

            device.Dispose();
            return data.Average();
        }
Example #12
0
 public MXA_N9020A(byte GPIB_Address)
 {
     _MXA_N9020A = new Device(Instruments_address._00, GPIB_Address);
 }
 public Trimmer_NI4882(Parameters pars, FTDIdevice USB)
 {
     parameters = pars;
     thisUSB = USB;
     FREQ_COUNTER = new Device(0, 9, 0); // create an object to hold the frequency counter, with GPIB ID 0, primary addr 9, and no secondary addr.  the primary addr was manually set on the counter itself.
 }
 //add by nino @20120309
 public static void testtrimmerisattached(byte counterid)
 {
     Device d = new Device(0, counterid, 0);
     //d.Write(":meas:freq? 12,0.0000001");
     d.Write(":MEASURE:FREQ? 12,0.0000001");
 }
Example #15
0
 //Initialize the DSO with an address
 public DSO(byte addr)
 {
     device = new NI.Device(0, addr);            //dso address and board number 0
 }
Example #16
0
 //Initialize the DMM with an address
 public DMM(byte addr)
 {
     device = new NI.Device(0, addr);
 }
Example #17
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            String response  = "INITIALIZED";                                           //PER IL MULTIMETRO -- DOVE MEMORIZZIAMO LA SUA RISPOSTA
            Task   writeTask = null;
            AnalogSingleChannelWriter writer = null;

            //create a write task
            try
            {
                writeTask = new Task();
                writeTask.AOChannels.CreateVoltageChannel(dev + "/ao0", "", 0, 5,
                                                          AOVoltageUnits.Volts);

                writeTask.Control(TaskAction.Verify);
                writer = new AnalogSingleChannelWriter(writeTask.Stream);
                double dataOut = 3;
                //AppendATextCrossThread(textBoxDAQ, ">> SDAQ INVIA" + dataOut + "\n");
                writer.WriteSingleSample(true, dataOut);
            }
            catch (DaqException exception)
            {
                MessageBox.Show(exception.Message);
            }
            finally
            {
                //qua potrei inviare il comando ad Arduino

                textBoxMessage.AppendText(" Sending adc");
                serialPortInstrument.Write("meas\n");
                Application.DoEvents();


                //qua potrei leggere il multimetro
                try
                {
                    gpibDmm = new  NationalInstruments.NI4882.Device(BOARD, ADDRESS, SEC_ADDRESS);  //OGGETTO ATTRAVERSO IL QUALE SCRIVERE IL COMANDO AD ARDUINO
                    gpibDmm.DefaultBufferSize = 32000;                                              //SIZE OF THE INTERNAL BUFFER FOR READING THE DATA
                    gpibDmm.IOTimeout         = TimeoutValue.T10s;                                  //FEED THE DOG
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    //return;
                }
                //'write the request
                try
                {
                    gpibDmm.Write("MEAS:VOLT:DC? 10,0.00001\n");                                    //IO METTEREI UNA PRECISIONE DI 6 E MEZZO // COMANDO COPIATO DALLE SLIDE
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    //return;
                }
                //'get the answer
                try
                {
                    response = gpibDmm.ReadString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    //return;
                }
                AppendATextCrossThread(textBoxResponse, ">> SDAQ INVIA" + response + "\n");
                //textBoxResponse.Text = response;                                                //CROSS THREADING
                writeTask.Dispose();                                                                  //dispose the task for less memory usage
            }
        }
Example #18
0
 //Initialize the DMM with an address
 public DMM(byte addr)
 {
     device = new NI.Device(0, addr);
 }
Example #19
0
 public PS_E3631A(byte GPIB_Address)
 {
     isInit = false;
     PowerSupply_E3631A = new Device(Instruments_address._00, GPIB_Address);
 }
Example #20
0
 //Updating lock-in amplifier GPIB address
 private void LIA_GPIB_update_Click(object sender, EventArgs e)
 {
     LIA.Dispose();
     Byte newliagpib = Convert.ToByte(LIA_GPIB.Text);
     LIA = new Device(0, newliagpib, 0);
 }
Example #21
0
 public PS_66332A(byte GPIB_Address)
 {
     PowerSupply_66332A = new Device(Instruments_address._00, GPIB_Address);
 }
Example #22
0
 //Updating monochromator GBIP address
 private void updateGPIB_Click(object sender, EventArgs e)
 {
     monochromator.Dispose();
     Byte newgpib = Convert.ToByte(MC_GPIB.Text);
     monochromator = new Device(0, newgpib, 0);
 }
Example #23
0
 public Arb_33522A(byte GPIB_Address)
 {
     AWG_33522A = new Device(Instruments_address._00, GPIB_Address);
 }
Example #24
0
 public E4438C(byte GPIB_Address)
 {
     ESG_E4438C = new Device(Instruments_address._00, GPIB_Address);
 }
Example #25
0
 public PM_437B(byte GPIB_Address)
 {
     PowerMeter_437B = new Device(Instruments_address._00, GPIB_Address);
 }
Example #26
0
 public HP8665B(byte GPIB_Address)
 {
     ESG_8665B = new Device(Instruments_address._00, GPIB_Address);
 }
Example #27
0
 public PM_N1913A(byte GPIB_Address)
 {
     PowerMeter_N1913A = new Device(Instruments_address._00, GPIB_Address);
 }