driver_example.cpp
Go to the documentation of this file.
00001 // Copyright (c) 2014, Pepperl+Fuchs GmbH, Mannheim
00002 // Copyright (c) 2014, Denis Dillenberger
00003 // All rights reserved.
00004 //
00005 // Redistribution and use in source and binary forms, with or without modification,
00006 // are permitted provided that the following conditions are met:
00007 //
00008 // * Redistributions of source code must retain the above copyright notice, this
00009 //   list of conditions and the following disclaimer.
00010 //
00011 // * Redistributions in binary form must reproduce the above copyright notice, this
00012 //   list of conditions and the following disclaimer in the documentation and/or
00013 //   other materials provided with the distribution.
00014 //
00015 // * Neither the name of Pepperl+Fuchs nor the names of its
00016 //   contributors may be used to endorse or promote products derived from
00017 //   this software without specific prior written permission.
00018 //
00019 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00020 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00023 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00026 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 
00030 #include <iostream>
00031 #include <string>
00032 #include <thread>
00033 #include <chrono>
00034 #include <pepperl_fuchs_r2000/r2000_driver.h>
00035 
00036 int main(int argc, char **argv)
00037 {
00038     std::cout << "Hello world!" << std::endl;
00039     std::string scanner_ip("192.168.1.71");
00040     pepperl_fuchs::R2000Driver driver;
00041 
00042     for( int i=0; i<2; i++ )
00043     {
00044         std::cout << "Connecting to scanner at " << scanner_ip << " ... ";
00045         if (driver.connect(scanner_ip, 80))
00046             std::cout << "OK" << std::endl;
00047         else
00048         {
00049             std::cout << "FAILED!" << std::endl;
00050             std::cerr << "Connection to scanner at " << scanner_ip << " failed!" << std::endl;
00051             return 1;
00052         }
00053 
00054         driver.setScanFrequency(35);
00055         driver.setSamplesPerScan(3600);
00056         auto params = driver.getParameters();
00057         std::cout << "Current scanner settings:" << std::endl;
00058         std::cout << "============================================================" << std::endl;
00059         for (const auto& p : params)
00060             std::cout << p.first << " : " << p.second << std::endl;
00061         std::cout << "============================================================" << std::endl;
00062 
00063 
00064         // Start capturing scanner data
00065         //-------------------------------------------------------------------------
00066         std::cout << "Starting capturing: ";
00067         if (driver.startCapturingUDP())
00068             std::cout << "OK" << std::endl;
00069         else
00070         {
00071             std::cout << "FAILED!" << std::endl;
00072             return 1;
00073         }
00074 
00075         for (int s = 0; s < 5; s++)
00076         {
00077             std::this_thread::sleep_for(std::chrono::seconds(1));
00078             int scans_captured = 0;
00079             int scans_available = driver.getFullScansAvailable();
00080             for (int i = 0; i < scans_available; i++)
00081             {
00082                 auto scandata = driver.getScan();
00083                 scans_captured++;
00084             }
00085             std::cout << "Received " << scans_captured << " from scanner" << std::endl;
00086         }
00087 
00088         std::cout << "Trying to stop capture" << std::endl;
00089 
00090         std::cout << "Stopping capture: " << driver.stopCapturing() << std::endl;
00091 
00092     }
00093 
00094     std::cout << "Goodbye world!" << std::endl;
00095     return 0;
00096 }


pepperl_fuchs_r2000
Author(s): Denis Dillenberger
autogenerated on Sat Sep 17 2016 04:01:08