From: Marek Vavrusa Date: Tue, 21 Oct 2008 19:54:42 +0000 (+0200) Subject: Added C++ wrapper examples X-Git-Tag: v0.15~10 X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=commitdiff_plain;h=818b119666360f52e42b9a95ec3949152228d835 Added C++ wrapper examples --- diff --git a/examples/find_all.cpp b/examples/find_all.cpp new file mode 100644 index 0000000..cc321f1 --- /dev/null +++ b/examples/find_all.cpp @@ -0,0 +1,62 @@ +/* cpp-simple.cpp + + Simple libftdi-cpp usage + + This program is distributed under the GPL, version 2 +*/ + +#include "ftdi.hpp" +#include +#include +#include +#include +using namespace Ftdi; + +int main(int argc, char **argv) +{ + // Show help + if(argc > 1) + { + if(strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"--help") == 0) + { + std::cout << "Usage: " << argv[0] << " [-v VENDOR_ID] [-p PRODUCT_ID]" << std::endl; + return EXIT_SUCCESS; + } + } + + // Parse args + int vid = 0x0403, pid = 0x6010, tmp = 0; + for(int i = 0; i < (argc - 1); i++) + { + if(strcmp(argv[i], "-v") == 0) + if((tmp = strtol(argv[++i], 0, 16)) >= 0) + vid = tmp; + + if(strcmp(argv[i], "-p") == 0) + if((tmp = strtol(argv[++i], 0, 16)) >= 0) + pid = tmp; + } + + // Print header + std::cout << std::hex << std::showbase + << "Found devices ( VID: " << vid << ", PID: " << pid << " )" + << std::endl + << "------------------------------------------------" + << std::endl << std::dec; + + // Print whole list + List* list = List::find_all(vid, pid); + for(List::iterator it = list->begin(); it != list->end(); it++) + { + std::cout << "FTDI (" << &*it << "): " + << it->vendor() << ", " + << it->description() << ", " + << it->serial() + << std::endl; + + } + + delete list; + + return EXIT_SUCCESS; +} diff --git a/examples/memorytest.cpp b/examples/memorytest.cpp new file mode 100644 index 0000000..1cb57e4 --- /dev/null +++ b/examples/memorytest.cpp @@ -0,0 +1,28 @@ +/* cpp-simple.cpp + + Simple libftdi-cpp usage + + This program is distributed under the GPL, version 2 +*/ + +#include "ftdi.hpp" +#include +using namespace Ftdi; + +int main(int argc, char **argv) +{ + std::cerr << "Creating ct context" << std::endl; + Context ct; + { + std::cerr << "Copying ct2 context" << std::endl; + Context ct2 = ct; + } + + std::cerr << "Copying ct3 context" << std::endl; + Context ct3(ct); + + std::cerr << "Result: " << ct.vendor() << std::endl; + + return 0; +} +