00001 #include <cstdio>
00002 #include "prosilica/prosilica.h"
00003 #include <arpa/inet.h>
00004
00005 void printSettings(const tPvCameraInfo& info, const tPvIpSettings& conf)
00006 {
00007 printf("\t%s - %7s - Unique ID = %lu\n", info.SerialString, info.DisplayName, info.UniqueId);
00008 printf("\tMode:\t\t");
00009 if (conf.ConfigMode & ePvIpConfigPersistent)
00010 printf("FIXED\n");
00011 else if (conf.ConfigMode & ePvIpConfigDhcp)
00012 printf("DHCP&AutoIP\n");
00013 else if (conf.ConfigMode & ePvIpConfigAutoIp)
00014 printf("AutoIP\n");
00015 else
00016 printf("None\n");
00017
00018 struct in_addr addr;
00019 addr.s_addr = conf.CurrentIpAddress;
00020 printf("\tAddress:\t%s\n", inet_ntoa(addr));
00021 addr.s_addr = conf.CurrentIpSubnet;
00022 printf("\tSubnet:\t\t%s\n", inet_ntoa(addr));
00023 addr.s_addr = conf.CurrentIpGateway;
00024 printf("\tGateway:\t%s\n", inet_ntoa(addr));
00025 }
00026
00027 int main(int argc, char** argv)
00028 {
00029 if (argc < 2) {
00030 printf("Usage: %s 10.68.0.20\n", argv[0]);
00031 return 0;
00032 }
00033
00034 prosilica::init();
00035
00036 boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(prosilica::fini));
00037
00038
00039 char* ip_address = argv[1];
00040 unsigned long IP = inet_addr(ip_address);
00041 tPvCameraInfo info;
00042 tPvIpSettings conf;
00043 tPvErr err = PvCameraInfoByAddr(IP, &info, &conf);
00044 if (!err) {
00045 printf("Camera found at requested IP address:\n");
00046 printSettings(info, conf);
00047 }
00048 else {
00049 printf("No camera found at %s, trying to change settings of a local camera...\n", ip_address);
00050 size_t num_cams = prosilica::numCameras();
00051 if (num_cams == 0) {
00052 printf("ERROR: No camera detected. Is it plugged in?\n");
00053 return 1;
00054 }
00055 if (num_cams == 2) {
00056 printf("ERROR: Multiple cameras (%u) found. Do you have more than one plugged in?\n", num_cams);
00057 return 1;
00058 }
00059
00060 printf("Detected camera.\n");
00061 unsigned long uid = prosilica::getGuid(0);
00062
00063 if (PvCameraInfo(uid, &info)) {
00064 printf("ERROR: could not retrieve camera info.\n");
00065 return 1;
00066 }
00067 if (PvCameraIpSettingsGet(uid, &conf)) {
00068 printf("ERROR: could not retrieve camera IP settings.\n");
00069 return 1;
00070 }
00071 printf("Original settings:\n");
00072 printSettings(info, conf);
00073
00074 printf("Applying new settings...\n");
00075 conf.ConfigMode = ePvIpConfigPersistent;
00076 conf.CurrentIpAddress = conf.PersistentIpAddr = IP;
00077 conf.CurrentIpSubnet = conf.PersistentIpSubnet = inet_addr("255.255.255.0");
00078 conf.CurrentIpGateway = conf.PersistentIpGateway = inet_addr("0.0.0.0");
00079 if (PvCameraIpSettingsChange(uid, &conf)) {
00080 printf("ERROR: Failed to apply the new settings\n");
00081 return 1;
00082 }
00083 printf("New settings:\n");
00084 printSettings(info, conf);
00085 }
00086
00087 return 0;
00088 }