This README gives an introduction to the C++ and Python code examples in this folder on the subject of finding Visionary cameras in the network and configuring their IP addresses. Last but not least it describes how to establish a connection and read-out device information.
Note
|
Remember to adjust the command line arguments like IP address ( |
C++
Either build and run the samples from the top level directory as described in Getting Started or build and run the samples from the sample subdirectory using its CmakeLists.txt file.
Find sensor
cd build/
./find_sensor -i192.168.1.100/24
Configure sensor
cd build/
configure_sensor -oXX:XX:XX:XX:XX:XX -c1 -i192.168.1.10/24 -n192.168.136.101 -m255.255.255.0
Hello sensor
cd build/
./hello_sensor -i192.168.1.10 -dVisionary-S
Python
Note
|
Make sure you followed the prerequisite steps in Getting Started |
To run the Python samples, execute the following command from the top-level directory:
Find sensor
python3 -m finding_and_connecting_devices.python.find_sensor -i"192.168.136.1/24"
Configure sensor
python -m finding_and_connecting_devices.python.configure_sensor -i"192.168.136.1/24" -o"XX:XX:XX:XX:XX:XX" -n"192.168.136.13" -m"255.255.255.0" -c"2"
Hello sensor
python -m finding_and_connecting_devices.python.hello_sensor -i"192.168.136.10" -d"Visionary-T Mini"
This example demonstrates how to discover all available Visionary cameras in a given network. As soon as a Visionary camera device is identified its device information will also be displayed. For example, the IP address, serial number, MAC address and so on.
When running the sample executable it will print usage information.
./build/find_sensor [option]* where option is one of -h show this help and exit -i<IP> ip address of the interface on which the scan is performed. It is expected to be in a CIDR manner, i.e., using ip address and the length of network prefix seperated by /. For example, -i192.168.1.100/24 Note the range of prefix is [0, 32].
To actually perform a find_sensor the mandatory parameters -i need to be provided e.g. ./build/find_sensor -i192.168.1.100/24
.
Step 1: Instantiate VisionaryAutoIP
The VisionaryAutoIP class provides IP address relevant features. For example, discovery of Visionary camera devices and IP configuration of a specific device in the network. Instantiate VisionaryAutoIP with a host IP address, i.e., the IP address of the interface on which the Visionary camera device discovery is performed, and the prefix length of the network mask.
C++
using namespace visionary;
VisionaryAutoIP ipScan(hostIp, prefixLength);
Python
autoIp = AutoIp(ip_address)
Step 2: Get the device information
Once Visionary camera devices are discovered, concrete device information can be retrieved.
C++
// scan for devices
std::vector<DeviceInfo> deviceList = ipScan.scan();
// print device info for every found device
for (auto it : deviceList)
{
std::cout << "Device name: " << it.deviceIdent << std::endl
<< "SerialNumber: " << it.serialNumber << std::endl
<< "MAC Address: " << it.macAddress << std::endl
<< "IP Address: " << it.ipAddress << std::endl
<< "Network Mask: " << it.networkMask << std::endl
<< "CoLa port: " << it.colaPort << std::endl
<< "CoLa version: " << static_cast<uint16_t>(it.colaVersion) << std::endl;
}
std::cout << '\n' << "Number of found devices: " << deviceList.size() << std::endl;
Python
devices = autoIp.scan()
for device in devices:
print(f"Device name: {device.deviceIdent}")
print(f"SerialNumber: {device.serialNumber}")
print(f"MAC Address: {device.macAddress}")
print(f"IP Address: {device.ipAddress}")
print(f"Network Mask: {device.netmask}")
print(f"CoLa port: {device.colaPort}")
print(f"CoLa version: {int(device.colaVersion)}")
print("Number of found devices: ", len(devices))
This example demonstrates how to configure a new IP address to a Visionary camera device.
When running the sample executable it will print usage information.
./build/configure_sensor [option]* where options are -h show this help and exit -o<MAC> mac address of the device to assign -i<IP> ip address of the interface on which the scan is performed. It is expected to be in a CIDR manner, i.e., using ip address and the length of network prefix seperated by /. For example, -i192.168.1.100/24 Note the range of prefix is [0, 32]. -c<version> cola version either -c1 (COLA1) or -c2 (COLA2) -n<IP> new ip address of the device -m<mask> network mask of the device -g<IP> gateway of the device -d enable dhcp
To actually configure an ip address the mandatory parameters -o, -c, -i, -n and -m need to be provided e.g. ./build/configure_sensor -oXX:XX:XX:XX:XX:XX -c1 -i192.168.1.10/24 -n192.168.136.101 -m255.255.255.0
.
Step 1: Instantiate VisionaryAutoIP
The VisionaryAutoIP class provides IP address relevant features. For example, discovery of Visionary camera devices and IP configuration of a specific device in the network. Instantiate VisionaryAutoIP with a host IP address, i.e., the IP address of the interface on which the Visionary camera device discovery is performed, and the prefix length of the network mask.
C++
using namespace visionary;
VisionaryAutoIP ipScan(hostIp, prefixLength);
Python
autoIp = AutoIp(ip_address)
Step 2: Configure Visionary camera device
Configure a specific Visionary camera device in the network.
C++
// Assign IP address
bool successful = ipScan.assign(destinationMac, colaVer, ipAddr, ipMask, ipGateway, dhcp, timeout);
Python
succ = autoIp.assign(mac_address, cola_version, new_ip_address, network_mask, gateway, dhcp)
This example illustrates the initial interaction with a Visionary camera device. It demonstrates how to establish a connection with the device and retrieve its device Identification.
The first step is to create a camera control object
and specifing the right VisionaryType
. The VisionaryControl class provides an interface for controlling a Visionary Camera, including managing the connection, logging in and out, and controlling data acquisition.
To establish a connection, invoke the open()
method, specifying the device’s IP address as an argument.
C++
using namespace visionary;
VisionaryControl visionaryControl(visionaryType);
if (!visionaryControl.open(ipAddress))
{
std::printf("Failed to open control connection to device.\n");
return ExitCode::eCommunicationError;
}
Note
|
Run the python script from the repository root with the following command: python3 -m finding_and_connecting_devices.python.hello_sensor -iDEVICEIP -tDEVICETYPE. Change DEVICEIP and DEVICETYPE to match your device. |
Python
deviceControl = Control(ip_address, cola_protocol, control_port)
deviceControl.open()
Once a connection to the device has been successfully established, you can retrieve the device’s identification information by invoking the getDeviceIdent()
method. This method returns a struct of two strings that represents the device’s name and version.
C++
DeviceIdent deviceIdent = visionaryControl.getDeviceIdent();
std::printf("Device Name: '%s', Device Version: '%s'\n", deviceIdent.name.c_str(), deviceIdent.version.c_str());
Python
name, version = deviceControl.getIdent()
print(f"DeviceIdent: {name} {version}")