/// <summary> /// initialises spectrometer /// </summary> internal void SpecInit(Form1 formObject) { Form1 form1 = formObject; //Variable initialisation int ret; int pixelnumber = 2048; int timing_mode = 1; int input_mode = 2; int inttime_base = 6300; double[] coefficeint_a = new double[4]; coefficeint_a[0] = 768.568237181056; coefficeint_a[1] = 0.152779981153354; coefficeint_a[2] = -4.32708905592971E-06; coefficeint_a[3] = -7.58441172603648E-10; double[] coefficeint_b = new double[4]; coefficeint_b[0] = 6076.59925643135; coefficeint_b[1] = 11.2680452636616; coefficeint_b[2] = -0.00700388399164194; coefficeint_b[3] = 3.42144657631367E-06; ret = Spectrometer.bwtekTestUSB(timing_mode, pixelnumber, input_mode, 0, 0); //tests USB connection int inttime_set = Convert.ToInt32(form1.inttime - inttime_base); ret = Spectrometer.bwtekSetTimeUSB(inttime_set, 0); //Sets correct intergration time for spectrometer if (ret < 0) { MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult result; result = MessageBox.Show("Intergration time failed to set check USB connections and power supply for instabilities", "Program will close", buttons); form1.Close(); } }
/// <summary> /// Starts Spectrometer /// </summary> /// /// <param name="Form1">The main form</param> internal void SpecStart(Form1 formObject) { Form1 form1 = formObject; bool retcode = Spectrometer.InitDevices(); if (retcode == false) { MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult result; result = MessageBox.Show("Spectrometer Not Detected. Please connect Spectrometer and then restart", "Program will close", buttons); form1.Close(); } byte[] tmp_channel = new byte[32]; byte[] spec_channel = new byte[32]; int retcode1 = Spectrometer.bwtekSetupChannel(-1, tmp_channel); if (retcode1 > 0) { int device_count = Spectrometer.GetDeviceCount(); for (int i = 0; i < 32; i++) { if (tmp_channel[i] < 32) { spec_channel[i] = tmp_channel[i]; } } } }
/// <summary> /// Takes Spectrum /// </summary> /// <param name="i">Spectrum number</param> private static void SpecTake(int i) { //variable initialisation int ret = 0; SpecThread objThread1 = new SpecThread(); ret = Spectrometer.bwtekDSPDataReadUSB(1, 0, 0, 0, objThread1.DataArray, 0); //read data from spectrometer if (ret < 0) { MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult result; result = MessageBox.Show("Spectrum take failed, check USB connections and power supply for instabilities", "Program will close", buttons); //this.Close(); } SpecSave(objThread1.DataArray, i); //Saves Spectrum from data }
/// <summary> /// Sets the cooler temperature of the component specified to the input temperature /// </summary> /// <param name="DAChannel">Specification of channel, 0 for CCD, 1 for external</param> /// <param name="SetTemp">Temperature value to set</param> internal void SetCoolerTemp(int DAChannel, int SetTemp, Form1 formObject) { Form1 form1 = formObject; //variable initialisation double[] coef = new double[4]; double Rt_R25; double T = SetTemp + 273.15; double Rt, R25, Vset; int DA_Set; if (SetTemp < 0) //determines coefficient operations to peform depending on positive or negative values { coef[0] = -1.6165371 * Math.Pow(10, 1); coef[1] = 5.9362293 * Math.Pow(10, 3); coef[2] = -4.0817384 * Math.Pow(10, 5); coef[3] = 2.2340382 * Math.Pow(10, 7); } else { coef[0] = -1.5702076 * Math.Pow(10, 1); coef[1] = 5.7388897 * Math.Pow(10, 3); coef[2] = -4.0470744 * Math.Pow(10, 5); coef[3] = 2.6675244 * Math.Pow(10, 7); } //calculations to produce DA_Set using thermodynamics Rt_R25 = coef[0] + coef[1] / T + coef[2] / Math.Pow(T, 2) + coef[3] / Math.Pow(T, 3); Rt_R25 = Math.Exp(Rt_R25); R25 = 10000; //R25=10K Rt = Rt_R25 * R25; Vset = (Rt / (Rt + R25) * 1.5); DA_Set = (int)(Vset / 2.28 * 4096); int ret = Spectrometer.bwtekSetAnalogOut(DAChannel, DA_Set, 0); if (ret < 0) { MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult result; result = MessageBox.Show("Spectrometer cooling failed to inialise, check USB connections and power supply for instabilities", "Program will close", buttons); form1.Close(); } }
/// <summary> /// closes down the spectrometer /// </summary> internal void specclose() { Spectrometer.bwtekCloseUSB(0); int y = Spectrometer.CloseDevices(); }