11/*
22Connect to a Zivid camera using the different available methods.
33
4- Replace the IP address and serial number in the code with the ones of your camera.
4+ Replace the IP address, serial number and hostname in the code with the ones of your camera,
5+ or provide them with --serial, --ip and --hostname.
56*/
67
78#include < Zivid/Zivid.h>
89
10+ #include < clipp.h>
11+
912#include < iostream>
1013
1114namespace
1215{
16+ struct CameraIdentifiers
17+ {
18+ std::string serialNumber{ " 2020C0DE" };
19+ std::string ipAddress{ " 172.28.60.5" };
20+ std::string hostname{ " zivid-2020C0DE.local" };
21+ };
22+
23+ CameraIdentifiers parseOptions (int argc, char **argv)
24+ {
25+ CameraIdentifiers identifiers;
26+ auto cli =
27+ (clipp::option (" --serial" )
28+ & clipp::value (" serial number" , identifiers.serialNumber ).doc (" Serial number of the camera" ),
29+ clipp::option (" --ip" ) & clipp::value (" ip address" , identifiers.ipAddress ).doc (" IP address of the camera" ),
30+ clipp::option (" --hostname" )
31+ & clipp::value (" hostname" , identifiers.hostname ).doc (" Hostname of the camera" ));
32+
33+ if (!clipp::parse (argc, argv, cli))
34+ {
35+ std::cout << clipp::usage_lines (cli, " Connect" ) << std::endl;
36+ throw std::runtime_error{ " Invalid usage" };
37+ }
38+ return identifiers;
39+ }
40+
1341 void printDiscoveredCameras (Zivid::Application &zivid)
1442 {
1543 std::cout << " Discovered cameras:" << std::endl;
@@ -21,41 +49,39 @@ namespace
2149 }
2250} // namespace
2351
24- int main ()
52+ int main (int argc, char **argv )
2553{
2654 try
2755 {
56+ const auto identifiers = parseOptions (argc, argv);
57+
2858 Zivid::Application zivid;
2959
3060 printDiscoveredCameras (zivid);
3161
32- std::cout << " The serial number, IP address and hostname below are placeholders. "
33- " Replace them with the ones of your camera."
34- << std::endl;
35-
3662 {
3763 std::cout << " Connecting to the first available camera" << std::endl;
3864 auto camera = zivid.connectCamera ();
3965 camera.disconnect ();
4066 }
4167
4268 {
43- std::cout << " Connecting to the camera with a specific serial number" << std::endl;
44- auto camera = zivid.connectCamera (Zivid::CameraInfo::SerialNumber{ " 2020C0DE " });
69+ std::cout << " Connecting to the camera with serial number " << identifiers. serialNumber << std::endl;
70+ auto camera = zivid.connectCamera (Zivid::CameraInfo::SerialNumber{ identifiers. serialNumber });
4571 camera.disconnect ();
4672 }
4773
4874 {
49- std::cout << " Connecting to the camera at a specific IP address" << std::endl;
50- auto camera = zivid.connectCamera (Zivid::CameraAddress{ " 172.28.60.5 " });
75+ std::cout << " Connecting to the camera at IP address " << identifiers. ipAddress << std::endl;
76+ auto camera = zivid.connectCamera (Zivid::CameraAddress{ identifiers. ipAddress });
5177 camera.disconnect ();
5278 }
5379
5480 {
55- std::cout << " Connecting to the camera at a specific hostname" << std::endl;
81+ std::cout << " Connecting to the camera at hostname " << identifiers. hostname << std::endl;
5682 // The default hostname format is "zivid-<serial-number>.local".
5783 // The hostname cannot be read or set through the SDK.
58- auto camera = zivid.connectCamera (Zivid::CameraAddress{ " zivid-2020C0DE.local " });
84+ auto camera = zivid.connectCamera (Zivid::CameraAddress{ identifiers. hostname });
5985 camera.disconnect ();
6086 }
6187
0 commit comments