Esempio n. 1
0
 // connect button
 public void connectButton_Click(object sender, RoutedEventArgs e)
 {
     if (connected == true)
     {
         conText.Text = "Not Connected";
         spectrometer.Dispose();
     }
     else
     {
         conText.Text = "Connecting";
         var usbDevices = GetUSBDevices();  //  query attached devices
         foreach (var usbDevice in usbDevices)
         {
             //    MessageBox.Show("spectrometer: " + usbDevice.DeviceID);
             resourceName = usbDevice.DeviceID;
             specDesc     = usbDevice.Description;
         }
         spectrometer = new TLCCS(resourceName, false, false);
         res          = spectrometer.getDeviceStatus(out status);
         String ErrText = "No error";
         if (res != 0)
         {
             ErrText = res.ToString();
         }
         //   MessageBox.Show("spectrometer status: " + ErrText);
         conText.Text = "Connected: " + specDesc;
     }
     connected = !connected;
 }
Esempio n. 2
0
 private void dispose_Button_Click(object sender, RoutedEventArgs e)
 {
     // release the device
     if (ccsSeries != null)
     {
         try
         {
             ccsSeries.Dispose();
             ccsSeries = null;
         }
         catch (Exception err)
         {
             MessageBox.Show("Can't release CCS" + err.ToString());
         }
         finally
         {
             if (scanTimer.IsEnabled)
             {
                 scanTimer.Stop();
             }
             scan_Button.Background = connect_Button.Background.Clone();
             infoBox.Text           = string.Empty;
         }
     }
     else
     {
         MessageBox.Show("No CCS connected!");
     }
 }
Esempio n. 3
0
        //To connect to the spectrometer
        private void button_Connect_Click(object sender, EventArgs e)
        {
            if (textbox_serialNo.Text.Length == 0)
            {
                MessageBox.Show("Please enter the device information");
                return;
            }

            // set the busy cursor
            this.Cursor = Cursors.WaitCursor;

            // connect the ccs device and start the sample c application. Read out the instrument resource name from the sample application
            // the instrument number 0x8081 is used for the CCS100 device. If you have another CCS instrument please change the number.
            // 0x8081: CCS100
            // 0x8083: CCS125
            // 0x8085: CCS150
            // 0x8087: CCS175
            // 0x8089: CCS200
            string instrumentNumber = "0";
            string serialNumber     = textbox_serialNo.Text.ToString();
            string caseSwitch       = devicemodel_combobox.Text;

            switch (caseSwitch)
            {
            case "CCS100":
                instrumentNumber = "0x8081";
                break;

            case "CCS125":
                instrumentNumber = "0x8083";
                break;

            case "CCS150":
                instrumentNumber = "0x8085";
                break;

            case "CCS175":
                instrumentNumber = "0x8087";
                break;

            case "CCS200":
                instrumentNumber = "0x8089";
                break;

            default:
                MessageBox.Show("Please enter the correct information!");
                return;
            }

            string resourceName = "USB0::0x1313::" + instrumentNumber + "::M" + serialNumber + "::RAW";

            // initialize device with the resource name (be sure the device is still connected)
            CCS100 = new TLCCS(resourceName, true, true);
            CCS100.identificationQuery(new StringBuilder(256), new StringBuilder(256), new StringBuilder(256), new StringBuilder(256), new StringBuilder(256));
            //MessageBox.Show("Device connected!", "Connected", MessageBoxButtons.OK, MessageBoxIcon.Information);
            statusText.Text        = "Device connected!";
            button_connect.Enabled = false;
            this.Cursor            = Cursors.Default;
        }
Esempio n. 4
0
        private void button_StartScan_Click(object sender, EventArgs e)
        {
            if (textBox_SerialNumber.Text.Length == 0)
            {
                MessageBox.Show("Please insert the 8 numerics of the serial number");
                return;
            }

            // set the busy cursor
            this.Cursor = Cursors.WaitCursor;

            // connect the ccs device and start the sample c application. Read out the instrument resource name from the sample application
            // the instrument number 0x8081 is used for the CCS100 device. If you have another CCS instrument please change the number.
            // 0x8081: CCS100
            // 0x8083: CCS125
            // 0x8085: CCS150
            // 0x8087: CCS175
            // 0x8089: CCS200
            string instrumentNumber = "0x8081";
            string resourceName     = "USB0::0x1313::" + instrumentNumber + "::M" + textBox_SerialNumber.Text.ToString() + "::RAW";

            // initialize device with the resource name (be sure the device is still connected)
            ccsSeries = new TLCCS(resourceName, true, true);

            int status;
            int res = ccsSeries.getDeviceStatus(out status);

            // set the integration time
            //res =
            ccsSeries.setIntegrationTime((double)numericUpDown_IntegrationTime.Value);

            // start the scan
            //res =
            ccsSeries.startScan();

            if (res == 0)
            {
                // color the button green
                button_StartScan.BackColor = System.Drawing.Color.Brown;
                button_StartScan.Enabled   = false;
            }

            // reset the cursor
            this.Cursor = Cursors.Default;

            // has the device started?
            res = ccsSeries.getDeviceStatus(out status);

            // camera has data available for transfer
            if ((status & 0x0010) > 0)
            {
                double[] data = new double[3648];
                //res =
                ccsSeries.getScanData(data);
            }
        }
Esempio n. 5
0
 //This function scan once and send the scanned data back into the main function
 static double [] DoScan(int delayTime, int device_Status, TLCCS CCS100)
 {
     double[] ScanData = new double[3648];
     Console.Write("Scanning....\n");
     CCS100.startScan();
     Thread.Sleep(delayTime);
     CCS100.getDeviceStatus(out device_Status);
     Console.Write("Scan completed.\n");
     CCS100.getScanData(ScanData);
     return(ScanData);
 }
Esempio n. 6
0
        private void connectCCS()
        {
            if (serialNoBox.Text.Length == 0)
            {
                MessageBox.Show("Please insert the 8 numerics of the serial number");
                return;
            }

            // set the busy cursor
            Cursor = Cursors.Wait;

            // 0x8081: CCS100
            // 0x8083: CCS125
            // 0x8085: CCS150
            // 0x8087: CCS175
            // 0x8089: CCS200
            try
            {
                if (ccsSeries == null)
                {
                    string instrumentNumber = "0x8089";
                    string resourceName     = "USB0::0x1313::" + instrumentNumber + "::M" + serialNoBox.Text.ToString() + "::RAW";
                    ccsSeries = new TLCCS(resourceName, false, false);
                    int res = ccsSeries.getWavelengthData((short)0, wavelength, out minWave, out maxWave);
                    simpleWav = DataSimplify(wavelength);
                    DeviceInformation();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("Connected failed\n" + err.ToString());
            }
            finally
            {
                Cursor = Cursors.Arrow;
            }
        }
Esempio n. 7
0
        //private const string Resource_Name = "USB0::0x1313::0x8081::M00445812::RAW";

        static void Main(string[] args)
        {
            double[] Data = new double[3648];
            double[] wavelength_Data = new double[3648];
            double   min_Wave = 0.00, max_Wave = 0.00;
            double   integration_Time = 0.00; //2.67,
            int      device_Status;
            int      delayTime = 0;

            string[] Resource_Name = new string[2];
            //Setting up the device
            Resource_Name = DeviceSetup();
            TLCCS tLCCS  = new TLCCS(Resource_Name[0], true, true);
            TLCCS CCS100 = tLCCS;

            CCS100.identificationQuery(new StringBuilder(256), new StringBuilder(256), new StringBuilder(256), new StringBuilder(256), new StringBuilder(256));
            Console.Write("Device is connected.\n");
            Console.Write("Plesse key in integration time for the spectrometer." + "\n");
            //Setup integration time for the device
            integration_Time = Convert.ToDouble(Console.ReadLine());
            CCS100.setIntegrationTime(integration_Time);
            CCS100.getIntegrationTime(out integration_Time);
            Console.Write("Integration time set to " + integration_Time + "sec.\n");
            CCS100.getDeviceStatus(out device_Status);
            Console.Write("Current device status is " + device_Status + "\n");
            delayTime = (int)Math.Ceiling(integration_Time) * 1000;
            Console.Write("Delay time is set to " + delayTime + "millisec\n");
            Console.Write("The device is ready" + "\n");
            //Wait for the command
            string DeviceAction = "0";

            while (DeviceAction != "exit")
            {
                Console.Write("Enter the next action.\n");
                DeviceAction = Console.ReadLine();
                switch (DeviceAction)
                {
                //Scan once, get the result and save it in the file called Scan.csv
                case "scan once":
                    Data = DoScan(delayTime, device_Status, CCS100);
                    StreamWriter sw = new StreamWriter(@"C:\Users\AungMyin\Desktop\School\FYP\Final-Year-Project\Scan.csv", false);
                    for (int i = 0; i < Data.Length; i++)
                    {
                        {
                            sw.WriteLine(Data[i].ToString());
                            sw.Write("\t");
                        }
                    }
                    sw.Write("\r\n");
                    sw.Flush();
                    sw.Close();
                    Console.Write("Scan completed and data saved in Scan.csv \n");
                    break;

                //Get wavelength information and save in the csv file called Wavelength.csv
                case "wavelength info":
                    CCS100.getWavelengthData(0, wavelength_Data, out min_Wave, out max_Wave);
                    Console.WriteLine("minimum wavelenght is " + min_Wave);
                    Console.WriteLine("maximum wavelength is " + max_Wave);
                    Console.WriteLine("total wavelength " + wavelength_Data.Length);
                    StreamWriter sw1 = new StreamWriter(@"C:\Users\AungMyin\Desktop\School\FYP\Final-Year-Project\Wavelength.csv", false);
                    for (int i = 0; i < wavelength_Data.Length; i++)
                    {
                        {
                            sw1.WriteLine(wavelength_Data[i].ToString());
                            sw1.Write("\t");
                        }
                    }
                    sw1.Write("\r\n");
                    sw1.Flush();
                    sw1.Close();
                    Console.Write("Wavelength points are saved in Wavelength.csv \n");
                    break;

                //Get device information for the user
                case "device info":
                    CCS100.getIntegrationTime(out integration_Time);
                    Console.Write("Device type: " + Resource_Name[1] + "\n");
                    Console.Write(Resource_Name[0] + "\n");
                    Console.Write("Integration time: " + integration_Time + " Delay Time " + delayTime + "\n");
                    break;

                //Changing the integration time
                case "change integration":
                    Console.Write("Plesse key in integration time to be change." + "\n");
                    integration_Time = Convert.ToDouble(Console.ReadLine());
                    CCS100.setIntegrationTime(integration_Time);
                    CCS100.getIntegrationTime(out integration_Time);
                    Console.Write("Integration time set to " + integration_Time + "sec.\n");
                    delayTime = (int)Math.Ceiling(integration_Time) * 1000;
                    Console.Write("Delay time is set to " + delayTime + "sec\n");
                    break;

                //If user enter the incorrect code as for valid command
                default:
                    Console.Write("Please enter the valid funcation. \n");
                    break;
                }
            }
            Console.WriteLine("Press enter to close...");
            Console.ReadLine();
        }