ursa_example.cpp
Go to the documentation of this file.
00001 
00027 #include "ursa_driver/ursa_driver.h"
00028 #include <iostream>
00029 #include <fstream>
00030 
00031 int main(int argc, char **argv) {
00032   std::string port = "/dev/pts/14";
00033   int32_t baud = 115200;
00034 
00035   boost::array<uint32_t, 4096> array;
00036   std::ofstream myfile;
00037   myfile.open("sample_output.csv");
00038 
00039   bool GMmode = true;
00040 
00041   ursa::Interface * ursa = new ursa::Interface(port.c_str(), baud);
00042 
00043   ursa->connect();
00044 
00045   if (ursa->connected())
00046     std::cout << "Connected" << std::endl;
00047   else
00048     return (-1);
00049 
00050   ursa->requestSerialNumber();
00051   ursa->requestBatt();
00052   std::cout << "Ursa Batt. voltage: " << boost::lexical_cast<std::string>(ursa->getBatt()) <<std::endl;
00053   //ursa->loadPrevSettings();
00054   ursa->setGain(70);
00055   ursa->setThresholdOffset(100);
00056   ursa->setShapingTime(ursa::TIME1uS);
00057   ursa->setInput(ursa::INPUT1NEG);
00058   ursa->setRamp(6);
00059 
00060   ursa->setVoltage(900); //use appropriate settings
00061 
00062   if (GMmode)
00063   {
00064     ursa->startGM();
00065     for (int i = 0; i < 30; i++)
00066     {
00067       std::cout << "Approx CPS: " << ursa->requestCounts() << std::endl; //number of counts since last read
00068       ursa->requestBatt();
00069       std::cout << "Ursa Batt. voltage: " << boost::lexical_cast<std::string>(ursa->getBatt()) <<std::endl;
00070       sleep(1); //Terrible way to get 1Hz (actual rate on my pc ~.8 Hz)
00071     }
00072     ursa->stopGM();
00073   }
00074 
00075   else
00076   {
00077     ursa->startAcquire();
00078     for (int i = 0; i < 90; i++) //~90 seconds
00079     {
00080       ursa->read();  //process incoming data
00081       ursa->requestBatt();
00082       std::cout << "Ursa Batt. voltage: " << boost::lexical_cast<std::string>(ursa->getBatt()) <<std::endl;
00083       sleep(1);
00084     }
00085     ursa->stopAcquire(); //stop acquiring
00086     ursa->read();      //one last read
00087     ursa->getSpectra(&array); //retrieve the spectra
00088 
00089     for (boost::array<uint32_t, 4096>::iterator i = array.begin();
00090         i != array.end(); i++)
00091     {
00092       myfile << boost::lexical_cast<std::string>(*i) << "," << std::endl; //fill the csv file
00093     }
00094     myfile.close();
00095   }
00096   ursa->setVoltage(0); //disable HV
00097 
00098 }
00099 


ursa_driver
Author(s): Mike Hosmar
autogenerated on Sat Jun 8 2019 20:57:48